中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁 > 光電顯示 > 設(shè)計(jì)應(yīng)用 > 12864液晶(AVR_Mega128)的頭文件

        12864液晶(AVR_Mega128)的頭文件

        作者: 時間:2018-08-09 來源:網(wǎng)絡(luò) 收藏

        大家使用時把這段代碼保存成.h的頭文件,在主程序中包含這個頭文件就行

        本文引用地址:http://www.antipu.com.cn/article/201808/386090.htm

        根據(jù)你們液晶電路更改下面的端口宏定義即可

        //CPU:ATmega128; 時鐘頻率為16MHz

        //編譯環(huán)境為ICCAVR

        //頭文件

        #include

        #include

        #include

        //數(shù)據(jù)端口定義

        #define Dat_Port_Write PORTA

        #define Dat_Port_Read PINA

        //控制端口及相應(yīng)的位

        #define RS_RW_EN_Control PORTG

        #define LCM_RS 0

        #define LCM_RW 1

        #define LCM_EN 2

        #define uchar unsigned char

        #define uint unsigned int

        //延時函數(shù)

        void Delay_Ms(unsigned int ms)

        {

        for(;ms>1;ms--);

        }

        //寫數(shù)據(jù)

        void Write_Data_LCM(unsigned char WDLCM)

        {

        Read_Status_LCM(); //檢測忙

        Delay_Ms(100);

        RS_RW_EN_Control|=BIT(LCM_RS); //RS=1

        Delay_Ms(100);

        RS_RW_EN_Control=~BIT(LCM_RW); //RW=0

        Delay_Ms(100);

        RS_RW_EN_Control|=BIT(LCM_EN); //EN=1

        Delay_Ms(100);

        Dat_Port_Write=WDLCM; //輸出數(shù)據(jù)

        Delay_Ms(100);

        RS_RW_EN_Control=~BIT(LCM_EN); //EN=0

        Delay_Ms(100);

        }

        //寫指令

        void Write_Command_LCM(unsigned char WCLCM)

        {

        Read_Status_LCM(); //根據(jù)需要檢測忙

        Delay_Ms(100);

        RS_RW_EN_Control=~BIT(LCM_RS); //RS=0

        Delay_Ms(100);

        RS_RW_EN_Control=~BIT(LCM_RW); //RW=0

        Delay_Ms(100);

        RS_RW_EN_Control|=BIT(LCM_EN); //EN=1

        Delay_Ms(100);

        Dat_Port_Write=WCLCM; //輸出指令

        Delay_Ms(100);

        RS_RW_EN_Control=~BIT(LCM_EN); //EN=0

        Delay_Ms(100);

        }

        //讀狀態(tài):檢測忙

        void Read_Status_LCM(void)

        {

        uchar temp;

        uchar flag = 1;

        while(flag==1)

        {

        DDRA=0x00; //端口A改為輸入

        Dat_Port_Write = 0xff;

        Delay_Ms(100);

        RS_RW_EN_Control=~BIT(LCM_RS); //RS=0

        Delay_Ms(100);

        RS_RW_EN_Control|=BIT(LCM_RW); //RW=1

        Delay_Ms(100);

        RS_RW_EN_Control|=BIT(LCM_EN); //EN=1

        Delay_Ms(100);

        temp = Dat_Port_Read; //讀端口A

        Delay_Ms(100);

        DDRA=0xff; //端口A改為

        Delay_Ms(100);

        RS_RW_EN_Control=~BIT(LCM_EN); //EN=0

        Delay_Ms(100);

        if(temp>>7==0)

        flag = 0;

        }

        }

        //LCM初始化

        void LCM_Init(void)

        {

        Write_Command_LCM(0x38); //三次顯示模式設(shè)置,不檢測忙信號

        Delay_Ms(1000);

        Write_Command_LCM(0x38);

        Delay_Ms(1000);

        Write_Command_LCM(0x38);

        Delay_Ms(1000);

        Write_Command_LCM(0x38); //顯示模式設(shè)置,開始要求每次檢測忙信號

        Write_Command_LCM(0x08); //關(guān)閉顯示

        Write_Command_LCM(0x01); //顯示清屏

        Write_Command_LCM(0x06); //顯示光標(biāo)移動設(shè)置

        Write_Command_LCM(0x0C); //顯示開及光標(biāo)設(shè)置

        }

        /



        關(guān)鍵詞:

        評論


        相關(guān)推薦

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

        關(guān)閉