在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,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首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 128*64 LCD顯示驅(qū)動程序

            128*64 LCD顯示驅(qū)動程序

            作者: 時間:2016-11-18 來源:網(wǎng)絡(luò) 收藏

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

            //頭文件部分
            #include


            //======================================================
            //定義常用符號,LCD控制字符號常量,TIME0定時賦值常量
            #define uchar unsigned char
            #define uint unsigned int

            #define DISPON 0x3f
            #define DISPOFF 0x3e
            #define DISPFIRSTLINE 0xc0
            #define LCDBUZY 0x80
            #define LIMIT 0x80 //128列限制

            #define TL0NUMB (65536-50000)%256 //定時50MS,20次溢出為一秒定時中斷
            #define TH0NUMB (65536-50000)/256
            #define TCOUNTF 10


            //=========================================================
            //定義引腳
            sbit lck = P3^5; //鎖存信號引腳


            //=========================================================
            //定義全局變量
            uchar combyte; //LCD命令變量
            uchar data status; //狀態(tài)變量,左右半屏標(biāo)志量
            uchar tcount = 0; //限制定時時間標(biāo)志
            //uchar pagebyte = 0; //上下移頁控制量
            uchar colbyte = 120; //左右移列控制量


            //=========================================================
            //定義圖形參數(shù)
            uchar code A[]={0xe0, 0x0f, 0xf0, 0x0f, 0x98, 0x00, 0x8c, 0x00, // A,此處的參數(shù)是按照列輸入來寫的,英文內(nèi)碼是按照行輸入來寫的
            0x98, 0x00, 0xf0, 0x0f, 0xe0, 0x0f, 0x00, 0x00};


            //=========================================================
            //函數(shù)原型
            void IniLcd(void); //初始化LCD
            void ClrLcd(uchar); //清屏LCD
            void WrComL(uchar); //寫左半屏幕命令字
            void WrComR(uchar); //寫右半屏幕命令字
            void WrData(uchar,uchar,uchar); //寫數(shù)據(jù)
            void Locate(uchar,uchar); //LCD屏定位
            void delayus(uint); //微妙級延遲
            void delay(void); //延遲個幾秒
            //void PicturePage(void); //圖形下移函數(shù)
            void PictureCol(void); //圖像左移函數(shù)

            void IniTime0(void); //初始化定時器0,利用MCU的內(nèi)部定時完成圖像的移動過程

            //=========================================================
            //主程序部分
            void main(void)
            {
            IniLcd();
            IniTime0();
            while(1); //對LCD的操作
            /*{
            Picture();
            delay();
            ClrLcd(0x00);
            }*/
            }


            /******************************************************/
            /* 以下部分是LCD12864的驅(qū)動模塊 */
            /******************************************************/

            //=========================================================
            //初始化定時器0函數(shù)
            void IniTime0(void)
            {
            TMOD = 0x01;
            //TCON = 0x00;
            TL0 = TL0NUMB;
            TH0 = TH0NUMB;
            TR0 = 1;
            ET0 =1;
            EA =1;
            }


            //=========================================================
            //定時器中斷函數(shù)
            void Time0(void) interrupt 1
            {
            TR0 = 0;
            TL0 = TL0NUMB;
            TH0 = TH0NUMB;
            tcount++;
            if(tcount == TCOUNTF)
            {
            tcount = 0;

            /*PicturePage();
            pagebyte++;
            if(pagebyte > 6)
            pagebyte = 0;*/

            PictureCol();
            colbyte--;
            }
            TR0 = 1;
            }


            //=========================================================
            //初始化LCD函數(shù)
            void IniLcd(void)
            {
            combyte = DISPOFF;
            WrComL(combyte);
            WrComR(combyte);

            combyte = DISPON;
            WrComL(combyte);
            WrComR(combyte);

            combyte = DISPFIRSTLINE;
            WrComL(combyte);
            WrComR(combyte);

            ClrLcd(0x00);

            /*combyte = DISPFIRSTLINE;
            WrComL(combyte);
            WrComR(combyte);*/

            Locate(0x00,0x00);
            }


            //=========================================================
            //清屏LCD函數(shù)
            void ClrLcd(uchar cbyte)
            {
            uchar i,j;
            for(i=0;i<8;i++)
            {
            delayus(6);
            for(j=0;j{
            delayus(6);
            WrData(cbyte,i,j);
            }
            }
            }


            //=========================================================
            //微妙級延遲函數(shù)
            void delayus(uint t)
            {
            while(t--);
            }


            //=========================================================
            //延遲個幾秒函數(shù)
            void delay(void)
            {
            delayus(50000);
            delayus(50000);
            delayus(50000);
            delayus(50000);
            delayus(50000);
            delayus(50000);
            }


            //=========================================================
            //寫左半屏幕命令字函數(shù)
            void WrComL(uchar cbyte)
            {
            lck = 0;
            P1 = 0x29; //E = 1;R/W = 1;D/I = 0; CS1 = 1; CS2 = 0;
            lck = 1;
            while(P0&LCDBUZY);
            lck = 0;
            P1 = 0x00; //E = 0;
            lck = 0;

            lck = 0;
            P1 = 0x21; //E = 1;R/W = 0;D/I = 0; CS1 = 1; CS2 = 0;
            lck = 1;
            P0 = cbyte;
            lck = 0;
            P1 = 0x00; //E = 0;
            lck = 1;
            }


            //=========================================================
            //寫右半屏幕命令字函數(shù)
            void WrComR(uchar cbyte)
            {
            lck = 0;
            P1 = 0x2a; //E = 1;R/W = 1;D/I = 0; CS1 = 0; CS2 = 1;
            lck = 1;
            while(P0&LCDBUZY);
            lck = 0;
            P1 = 0x00; //E = 0;
            lck = 0;

            lck = 0;
            P1 = 0x22; //E = 1;R/W = 0;D/I = 0; CS1 = 0; CS2 = 1;
            lck = 1;
            P0 = cbyte;
            lck = 0;
            P1 = 0x00; //E = 0;
            lck = 1;
            }


            //=========================================================
            //LCD屏幕點定位函數(shù)
            void Locate(uchar page,uchar col)
            {
            uchar com_page,com_col,right;
            switch(col&0xc0)
            {
            case 0x00: //左半屏幕
            {
            right = 0;
            break;
            }
            case 0x40: //右半屏幕
            {
            right = 1;
            break;
            }
            default: break;
            }
            com_page = page&0x07|0xb8; //將頁數(shù)據(jù)轉(zhuǎn)換為頁命令字
            com_col = col&0x3f|0x40; //將列數(shù)據(jù)轉(zhuǎn)換為列命令字

            switch(right)
            {
            case 0x00: //左半屏幕
            {
            WrComL(com_page);
            WrComL(com_col);
            status = 0;
            break;
            }
            case 0x01: //右半屏幕
            {
            WrComR(com_page);
            WrComR(com_col);
            status = 1;
            break;
            }
            default: break;
            }
            }


            //=========================================================
            //寫數(shù)據(jù)函數(shù)
            void WrData(uchar databyte,uchar page,uchar col)
            {
            Locate(page,col);

            P0 = databyte;

            lck = 0;
            if(status)
            P1 = 0x26; //E = 1; R/W = 0; D/I = 1; CS1 = 0; CS2 = 1;
            else
            P1 = 0x25; //E = 1; R/W = 0; D/I = 1; CS1 = 1; CS2 = 0;
            lck = 1;

            //P0 = databyte;

            lck = 0;
            P1 = 0x00;
            lck = 1;
            }


            //=========================================================
            //圖形函數(shù),圖像按頁下移
            /*void PicturePage(void)
            {
            uchar col,page;
            uchar i = 0;
            ClrLcd(0x00);
            for(col=64;col<72;col++)
            {
            for(page=pagebyte;page{
            WrData(A[i++],page++,col);
            }
            }
            }*/


            //=========================================================
            //圖形左移函數(shù)
            void PictureCol(void)
            {
            uchar col,page;
            uchar i = 0;
            ClrLcd(0x00);
            for(col=colbyte;(col=0);) //列控制
            {
            for(page=0;page<2;page++) //頁控制
            {
            WrData(A[i++],page,col); //寫數(shù)據(jù),“i++”同步跟新數(shù)據(jù)
            }
            col++;
            }
            if(colbyte==0)
            colbyte = 120;

            }




            關(guān)鍵詞: 128*64LCD顯示驅(qū)動程

            評論


            相關(guān)推薦

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

            關(guān)閉