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

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

        LCD12232液晶的模塊化程序(51單片機)

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

         

         

        /*******************************************************************

                 lcd12232.h頭文件

        *******************************************************************/

        #ifndef _LCD12232_H_
        #define _LCD12232_H_
        extern void lcd12232_busy(); //忙標志函數
        extern void lcd12232_init(); //初始化函數
        extern void lcd12232_clear();//清屏函數
        extern void lcd12232_hanzi(unsigned char m,unsigned char n,unsigned char p,unsigned char y);//第一個參數代表的是共顯示幾個字(空格也算一個漢字),第二個參數是從第幾個字開始顯示,第三個參數是選屏,第四個是頁地址
                           //選屏函數,2為兩屏,1為左屏,0為右屏
                           //頁地址設置的參數值應該為0、1、2三個數中的一個,因為液晶一共分為四頁
        //extern void lcd12232_zifu(unsigned char m,unsigned char n,unsigned char y,unsigned char d);//第一個參數代表的是第幾個字,第二個參數是選屏,第三個參數是頁地址,第四個參數是列地址
        #endif 

        /*******************************************************************

                 lcd12232.c文件

        *******************************************************************/

        #include<reg51.h>
        #define uchar unsigned char
        #define uint  unsigned char
        #define port P0
        sbit e1=P2^1;
        sbit e2=P2^2;
        sbit a0=P2^0;
        sbit rw=P2^3;
        uchar code ziku[]=
        {

         0x00,0x00,0x00,0xC0,0x70,0x20,0x00,0xFF,0x00,0x10,0x20,0xC0,0x80,0x00,0x00,0x00,//小
         0x04,0x02,0x01,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x01,0x07,0x02,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,0x00,0x00,0x00,0x00,0x00,

         0x00,0x04,0x84,0x44,0x3C,0x44,0x85,0x06,0x04,0xC4,0x3C,0x44,0x84,0x04,0x00,0x00,//卒
         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,//設
         0x00,0x00,0x7F,0x20,0x90,0x80,0x40,0x43,0x2C,0x10,0x10,0x2C,0x43,0xC0,0x40,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,0x00,0x00,0x00,0x00,0x00,

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

         0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//!
         0x00,0x00,0x00,0x5F,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,//,
         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,//。
         0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

         0x80,0x84,0x44,0x44,0x24,0x14,0x04,0xFF,0x04,0x14,0x24,0x24,0x46,0xC4,0x40,0x00,//"李"
         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,//"振"  
         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,//"偉"
         0x00,0x00,0x00,0xFF,0x02,0x02,0x02,0x02,0x02,0xFF,0x02,0x12,0x22,0x1F,0x02,0x00
        };
        void delay(uchar z)    //延時函數
        {
             int x;
             for(x=z;x>0;x--);
        }
        void lcd12232_cs(uchar cs) //選屏函數,2為兩屏,1為左屏,0為右屏
        {
           switch(cs)
           {
            case 0:e1=1,e2=0;break;
            case 1:e1=0;e2=1;break;
            case 2:e1=0;e2=0;break;
            case 3:e1=1;e2=1;break;  
           }
        }
        void lcd12232_write_com(uchar com,uchar n)//寫命令函數
        {
         lcd12232_cs(3);
         a0=0;
         rw=0;
         port=com;
         //delay(1);
         lcd12232_cs(n);
         delay(1);
        }
        void lcd12232_write_dat(uchar dat,uchar n)//寫數據函數
        {
        a0=1;
        rw=0;
        lcd12232_cs(3);
        port=dat;
        lcd12232_cs(n);
        }
        uchar lcd12232_read()   //讀狀態函數
        {
         uchar dat;
         //e1=0;e2=0;
         lcd12232_cs(2);
         a0=0;
         rw=1;
         port=0xff;
         delay(1);
         //e1=1;e2=1;
         lcd12232_cs(3);
         dat=port;
         delay(1);
         //e1=0;e2=0;
         lcd12232_cs(2);
         return dat;
        }
        void lcd12232_busy()
        {
         uchar i;
         i=lcd12232_read();
         while(i&0x80==0x80);
        }
        void lcd12232_clear()    //清屏函數
        {
         uchar i;
         lcd12232_write_com(0xb8,2);
         lcd12232_write_com(0x00,2);
         for(i=0;i<255;i++)
         lcd12232_write_dat(0x00,2);
        }
        void lcd12232_init() //第一個參數為指令,第二個參數為選屏,2為兩屏,1為左屏,0為右屏
        {
         lcd12232_write_com(0xe2,2);//復位
         lcd12232_write_com(0xaf,2);//總顯示開
         lcd12232_write_com(0xc0,2);//從第一行開始顯示數據
         lcd12232_write_com(0xb8,2);//設置顯示頁地址為第一頁
         lcd12232_write_com(0x00,2);//設置顯示列地址為第一列
         lcd12232_write_com(0xa1,2);//設置正向顯示,a0為逆向顯示
         lcd12232_write_com(0xa9,2);// 1/32占空比
         lcd12232_write_com(0xa4,2);//動態驅動
         lcd12232_write_com(0xee,2);
         lcd12232_clear();     //清屏
        }
        void lcd12232_hanzi(uchar m,uchar n,uchar p,uchar y)   //漢字顯示函數,第一個參數代表的是顯示m個字,第二個參數是從第n個字開始顯示,第三個參數是選屏,第四個是頁地址
        {
         uchar i,a;
         lcd12232_write_com(0x00,2);
         lcd12232_write_com(0xb8+y,2);
         for(a=0;a<m;a++)
         {
          for(i=0;i<16;i++)
          {
           lcd12232_write_dat(ziku[i+a*32+(n-1)*32],p);
          }
         }

         lcd12232_write_com(0x00,2);
         lcd12232_write_com(0xb9+y,2);
         for(a=0;a<m;a++)
         {
          for(i=0;i<16;i++)
          {
           lcd12232_write_dat(ziku[i+a*32+16+(n-1)*32],p);
          }
         }
        }
        /*void lcd12232_zifu(uchar m,uchar n,uchar y,uchar d)  //第一個參數代表的是第幾個字,第二個參數是選屏,第三個參數是頁地址,第四個參數是列地址
        {
         uchar i;
         lcd12232_write_com(0xb8+y,2);
         lcd12232_write_com(0x00+d,2);
         for(i=0;i<16;i++)
         {
         lcd12232_write_dat(ziku[m*32+i],n);
         }
         lcd12232_write_com(0xb9+y,2);
         lcd12232_write_com(0x00+d,2);
         for(i=0;i<16;i++)
         {
         lcd12232_write_dat(ziku[m*32+i+16],n);
         }
        } */

        /*******************************************************************

                   main.c主文件

        *******************************************************************/

        #include<reg51.h>
        #include"lcd12232.h"
        void main()
        {     
        lcd12232_init(); //初始化
        lcd12232_clear();//清屏
        lcd12232_busy();//忙檢測
        lcd12232_hanzi(3,1,1,1);//第一個參數代表的是共顯示幾個字(空格也算一個漢字),第二個參數是從第幾個字開始顯示,第三個參數是選屏,第四個參數是頁地址
        lcd12232_busy();
        lcd12232_hanzi(4,4,0,1);

        //lcd12232_zifu(0,1,0,0);//第一個參數代表的是第幾個字,第二個參數是選屏,第三個參數是頁地址,第四個參數是列地址
        while(1);
        }

        關閉窗口

        相關文章

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