在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > AVR六個(gè)IO口驅(qū)動(dòng)液晶LCD1602

            AVR六個(gè)IO口驅(qū)動(dòng)液晶LCD1602

            作者: 時(shí)間:2016-11-10 來(lái)源:網(wǎng)絡(luò) 收藏
            液晶LCD1602比中文大液晶12864較容易驅(qū)動(dòng),這個(gè)驅(qū)動(dòng)程序只用六個(gè)單片機(jī)IO口驅(qū)動(dòng),可以減少四個(gè)IO口,套用也方便...

            //LCD1602.h

            本文引用地址:http://www.biyoush.com/article/201611/317336.htm

            /*---------------------------------------------------------------
            要使用本驅(qū)動(dòng),改變下面配置信息即可

            注意:RW要接地
            -----------------------------------------------------------------*/
            #define LCD_EN_PORT PORTD//以下2個(gè)要設(shè)為同一個(gè)口
            #define LCD_EN_DDR DDRD
            #define LCD_RS_PORT PORTD//以下2個(gè)要設(shè)為同一個(gè)口
            #define LCD_RS_DDR DDRD
            #define LCD_DATA_PORT PORTD//以下3個(gè)要設(shè)為同一個(gè)口
            #define LCD_DATA_DDR DDRD//一定要用高4位
            #define LCD_DATA_PIN PIND
            #define LCD_RS (1<<0)//0x04 portd2 out
            #define LCD_EN (1<<2)//0x08 portd3 out
            #define LCD_DATA ((1<<4)|(1<<5)|(1<<6)|(1<<7))//0xf0 portd4/5/6/7 out
            /*-------------------------------------------------------------------------------
            函數(shù)說(shuō)明
            ------------------------------------------------------------------------------*/
            void LCD_init(void);
            void LCD_en_write(void);
            void LCD_write_command(unsigned char command) ;
            void LCD_write_data(unsigned char data);
            void LCD_set_xy (unsigned char x, unsigned char y);
            void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);
            void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data);
            void delay_nus(unsigned int n);
            void delay_nms(unsigned int n);

            //LCD1602.c

            #include
            #include
            #include"LCD1602.h"


            void delay_1us(void)//1us延時(shí)函數(shù)
            {
            asm("nop");
            }

            void delay_nus(unsigned int n)//N us延時(shí)函數(shù)
            {
            unsigned int i=0;
            for (i=0;i delay_1us();
            }

            void delay_1ms(void)//1ms延時(shí)函數(shù)
            {
            unsigned int i;
            for (i=0;i<1140;i++);
            }

            void delay_nms(unsigned int n)//N ms延時(shí)函數(shù)
            {
            unsigned int i=0;
            for (i=0;i delay_1ms();
            }


            /*----------------------------------------------------------------------------*/
            void LCD_init(void)//液晶初始化
            {
            LCD_DATA_DDR|=LCD_DATA;//數(shù)據(jù)口方向?yàn)檩敵?br /> LCD_EN_DDR|=LCD_EN;//設(shè)置EN方向?yàn)檩敵?br /> LCD_RS_DDR|=LCD_RS;//設(shè)置RS方向?yàn)檩敵?br /> LCD_write_command(0x28);
            LCD_en_write();
            delay_nus(40);
            LCD_write_command(0x28);//4位顯示
            LCD_write_command(0x0c);//顯示開(kāi)
            LCD_write_command(0x01);//清屏
            delay_nms(2);
            }

            /*----------------------------------------------------------------------------*/
            void LCD_en_write(void)//液晶使能
            {
            LCD_EN_PORT|=LCD_EN;
            delay_nus(1);
            LCD_EN_PORT&=~LCD_EN;
            }

            /*----------------------------------------------------------------------------*/
            void LCD_write_command(unsigned char command)//寫指令
            {
            delay_nus(16);
            LCD_RS_PORT&=~LCD_RS;//RS=0
            LCD_DATA_PORT&=0X0f;//清高四位
            LCD_DATA_PORT|=command&0xf0;//寫高四位
            LCD_en_write();
            command=command<<4;//低四位移到高四位
            LCD_DATA_PORT&=0x0f;//清高四位
            LCD_DATA_PORT|=command&0xf0;//寫低四位
            LCD_en_write();

            }
            /*----------------------------------------------------------------------------*/
            void LCD_write_data(unsigned char data)//寫數(shù)據(jù)
            {
            delay_nus(16);
            LCD_RS_PORT|=LCD_RS;//RS=1
            LCD_DATA_PORT&=0X0f;//清高四位
            LCD_DATA_PORT|=data&0xf0;//寫高四位
            LCD_en_write();
            data=data<<4;//低四位移到高四位
            LCD_DATA_PORT&=0X0f;//清高四位
            LCD_DATA_PORT|=data&0xf0;//寫低四位
            LCD_en_write();
            }
            /*----------------------------------------------------------------------------*/
            void LCD_set_xy( unsigned char x, unsigned char y )//寫地址函數(shù)
            {
            unsigned char address;
            if (y == 0) address = 0x80 + x;
            else address = 0xc0 + x;
            LCD_write_command( address);
            }
            /*----------------------------------------------------------------------------*/

            //列x=0~15,行y=0,1
            void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)

            {
            LCD_set_xy( X, Y );//寫地址
            while (*s)// 寫顯示字符
            {
            LCD_write_data( *s );
            s ++;
            }

            }

            /*----------------------------------------------------------------------------*/

            //列x=0~15,行y=0,1
            void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data)

            {
            LCD_set_xy( X, Y );//寫地址
            LCD_write_data( data);

            }

            //main.c

            #include
            #include
            #include"LCD1602.h"

            void main(void)
            {
            LCD_init();
            // X Y *s
            LCD_write_string(2, 0, "hello!!");
            while(1)
            {
            // X Y *s
            LCD_write_string(2, 1,"1234567890");
            // X Y data
            LCD_write_char(12, 0, 8);
            LCD_write_char(13, 0, 8);
            }

            }



            評(píng)論


            技術(shù)專區(qū)

            關(guān)閉