新聞中心

        EEPW首頁 > 光電顯示 > 設計應用 > 12864液晶(AVR_Mega128)的頭文件

        12864液晶(AVR_Mega128)的頭文件

        作者: 時間:2018-08-09 來源:網絡 收藏

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

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

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

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

        //編譯環境為ICCAVR

        //頭文件

        #include

        #include

        #include

        //數據端口定義

        #define Dat_Port_Write PORTA

        #define Dat_Port_Read PINA

        //控制端口及相應的位

        #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

        //延時函數

        void Delay_Ms(unsigned int ms)

        {

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

        }

        //寫數據

        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; //輸出數據

        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(); //根據需要檢測忙

        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);

        }

        //讀狀態:檢測忙

        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); //三次顯示模式設置,不檢測忙信號

        Delay_Ms(1000);

        Write_Command_LCM(0x38);

        Delay_Ms(1000);

        Write_Command_LCM(0x38);

        Delay_Ms(1000);

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

        Write_Command_LCM(0x08); //關閉顯示

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

        Write_Command_LCM(0x06); //顯示光標移動設置

        Write_Command_LCM(0x0C); //顯示開及光標設置

        }

        /



        關鍵詞:

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 津市市| 抚宁县| 瑞昌市| 宜章县| 大余县| 屏东县| 长岛县| 台南县| 汤原县| 阳信县| 漯河市| 都匀市| 庄浪县| 略阳县| 海原县| 南郑县| 康马县| 宜宾市| 新安县| 江都市| 房产| 云梦县| 徐州市| 景东| 宁南县| 北安市| 岗巴县| 杭州市| 美姑县| 镇赉县| 赤水市| 准格尔旗| 建始县| 城步| 巢湖市| 武汉市| 拉孜县| 鹿泉市| 五台县| 汉沽区| 江山市|