<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

        LCD12864 液晶顯示器 模塊化程序(51單片機)

        作者:佚名   來源:本站原創   點擊數:  更新時間:2014年10月24日   【字體:

         

         

         

        /**********************
        lcd12864.h 頭文件
        **********************/
        #ifndef _LCD12864_H_
        #define _LCD12864_H_
        extern void lcd12864_busy(); //忙標志函數
        extern void led12864_clear();//清屏
        extern void lcd12864_init(); //初始化函數
        extern void lcd12864_pxy(unsigned char p,unsigned char x,unsigned char y);//數據的顯示位置,p=0左半屏,p=1右半屏,p=2兩半屏全選,xy為顯示的坐標,第四象限,用正值表示。
        extern void lcd12864_zifu(unsigned char p,unsigned char x,unsigned char,unsigned char m); //第m個字符的顯示位置,與漢字的定義一樣,只是xy的坐標的值應小于等于7.
        extern void lcd12864_hanzi(unsigned char p,unsigned char x,unsigned char y,unsigned char m); //第m個漢字的顯示位置,p=0左半屏,p=1右半屏,p=2兩半屏全選,xy為顯示的坐標,第四象限,用正值表示,x或y的值都應小于等于3。m為顯示的第m個漢字。
        #endif

         

         

        /**********************
         lcd12864.c 文件
        **********************/

        #include<reg51.h>
        #define uint unsigned int
        #define uchar unsigned char
        sbit cs2=P2^0;
        sbit cs1=P2^1;
        sbit e=P2^2;
        sbit rw=P2^3;
        sbit rs=P2^4;
        uchar code zifu[]=
        {
         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//,0
         0x00,0x00,0x58,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  

         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//。1
         0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

         0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//!2
         0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
        };
        uchar code ziku[]=
        {
          //0x80,0x40,0xF0,0x2C,0x43,0x20,0x98,0x0F,0x0A,0xE8,0x08,0x88,0x28,0x1C,0x08,0x00,//"你",
         //0x00,0x00,0x7F,0x00,0x10,0x0C,0x03,0x21,0x40,0x3F,0x00,0x00,0x03,0x1C,0x08,0x00,

         0x80,0x84,0x44,0x44,0x24,0x14,0x04,0xFF,0x04,0x14,0x24,0x24,0x46,0xC4,0x40,0x00,//"李",0 漢字后面的數字表示漢字的代號,方便使用
            0x00,0x08,0x08,0x08,0x09,0x49,0x89,0x7D,0x0D,0x0B,0x09,0x08,0x0C,0x08,0x00,0x00,

         0x10,0x10,0x10,0xFF,0x90,0x50,0xFE,0x92,0x92,0x92,0x92,0x92,0x9A,0xD3,0x82,0x00,//"振",1 
            0x02,0x42,0x81,0x7F,0x40,0x30,0x0F,0x00,0xFF,0x40,0x07,0x18,0x28,0x64,0x22,0x00,

          0x80,0x40,0x20,0xF8,0x07,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x68,0x4C,0x08,0x00,//"偉",2
            0x00,0x00,0x00,0xFF,0x02,0x02,0x02,0x02,0x02,0xFF,0x02,0x12,0x22,0x1F,0x02,0x00,

         0x00,0x00,0x00,0xC0,0x70,0x20,0x00,0xFF,0x00,0x10,0x20,0xC0,0x80,0x00,0x00,0x00,//小3
         0x04,0x02,0x01,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x01,0x07,0x02,0x00,

         0x00,0x04,0x84,0x44,0x3C,0x44,0x85,0x06,0x04,0xC4,0x3C,0x44,0x84,0x04,0x00,0x00,//卒4
         0x04,0x05,0x04,0x04,0x04,0x04,0x05,0xFE,0x05,0x04,0x04,0x04,0x05,0x04,0x04,0x00,

         0x40,0x41,0xCE,0x04,0x00,0x80,0x40,0xBE,0x82,0x82,0x82,0xBE,0xC0,0x40,0x40,0x00,//設5
         0x00,0x00,0x7F,0x20,0x90,0x80,0x40,0x43,0x2C,0x10,0x10,0x2C,0x43,0xC0,0x40,0x00,

         0x20,0x21,0x2E,0xE4,0x00,0x00,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x00,//計6
         0x00,0x00,0x00,0x7F,0x20,0x10,0x08,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,

         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//,7
         0x00,0x00,0x58,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  

         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//。8
         0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

         0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//!9
         0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
         
        };

        /*void delay(uchar i)   //1ms延時函數 
        {
            uchar a,b;
            for(b=i;b>0;b--)
                for(a=110;a>0;a--);
        }*/
        void lcd12864_busy()    //忙標志位函數
        {
         uchar i;
         rw=1;
         rs=0;
         while(1)
         {
          P0=0xff;
          e=1;
          //i=P0;
          e=0;
          i=P0;
          i=i&0x80;
          if(i!=0x80)
          break;
         }
        }
        lcd12864_writedat(uchar dat) //寫數據函數
        {
         //lcd12864_busy();
         rw=0;
         rs=1;
         e=1;
         P0=dat;
         e=0;
        }
        lcd12864_writecom(uchar com)  //寫命令函數
        {
         //lcd12864_busy();
         rw=0;
         rs=0;
         e=1;
         P0=com;
         e=0;
        }
        void lcd12864_init()   //初始化函數
        {
          lcd12864_writecom(0x3f);//開顯示 關顯示為0x3e
          lcd12864_writecom(0xb8);//設置頁地址為0.第一頁。
          lcd12864_writecom(0xc0);//設置顯示起始行地址,為第一行顯示到液晶屏上
          lcd12864_writecom(0x40);//設置列地址
        }
        lcd12864_pxy(uchar p,uchar x,uchar y) //數據的位置,p=0左半屏,p=1右半屏,p=2兩半屏全選,xy為顯示的坐標,第四象限,用正值表示。
        {
          switch(p)
         {
          case 0:cs1=0;cs2=1;break;
          case 1:cs1=1;cs2=0;break;
          case 2:cs1=0;cs2=0;break;
         }
          lcd12864_writecom(0xb8+y);
          lcd12864_writecom(0x40+x);
        }
        lcd12864_zifu(uchar p,uchar x,uchar y,uchar m) //第m個字符的顯示位置,與測字的定義一樣,只是xy的坐標的值應小于等于7.
        {
         uchar i;
         lcd12864_pxy(p,x*8,y);
         for(i=0;i<8;i++)
         {
          lcd12864_writedat(zifu[i+m*8]);
         }
        }
        lcd12864_hanzi(uchar p,uchar x,uchar y,uchar m) //第m個漢字的顯示位置,p=0左半屏,p=1右半屏,p=2兩半屏全選,xy為顯示的坐標,第四象限,用正值表示,x或y的值都應小于等于3。m為顯示的第m個漢字。
        {
         uchar i;
         lcd12864_pxy(p,x*16,2*y);
         for(i=0;i<16;i++)
         lcd12864_writedat(ziku[i+m*32]);
         lcd12864_pxy(p,x*16,2*y+1);
         for(i=0;i<16;i++)
         lcd12864_writedat(ziku[i+m*32+16]);
        }
        void lcd12864_clear()      //清屏函數
        {            
         uint i;
         lcd12864_pxy(2,0,0);      //清左右兩屏的第一、二、三、四頁
         for(i=0;i<256;i++)
         {
          lcd12864_writedat(0x00);
         }          
         lcd12864_pxy(2,0,4);      //清左右兩屏的第五、六、七、八頁
         for(i=0;i<256;i++)
         {
          lcd12864_writedat(0x00);
         }
        }

         

         

        /******************************************
         main.c 主文件
        ******************************************/

        #include<reg51.h>
        #include"lcd12864.h"
        void main()
        {
         lcd12864_init();
         lcd12864_clear();
         lcd12864_hanzi(0,0,0,0);//李
         lcd12864_hanzi(0,1,0,1);//振
         lcd12864_hanzi(0,2,0,2);//偉
         lcd12864_hanzi(0,3,0,8);// 。
         lcd12864_hanzi(0,0,2,3);//小
         lcd12864_hanzi(0,1,2,4);//卒
         lcd12864_hanzi(0,2,2,5);//設
         lcd12864_hanzi(0,3,2,6);//計
         lcd12864_hanzi(1,0,2,9);//!
         lcd12864_zifu(1,6,6,8); //!的左上部 分開以字符的形式顯示
         lcd12864_zifu(1,7,6,9); //!的右上部
         lcd12864_zifu(1,6,7,10);//!的左下部
         lcd12864_zifu(1,7,7,11);//!的右下部
         while(1);
        }

        關閉窗口

        相關文章

        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮