这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » 分享一个8051单片机驱动LCD128x64液晶屏的测试程序

共8条 1/1 1 跳转至

分享一个8051单片机驱动LCD128x64液晶屏的测试程序

工程师
2020-02-02 18:26:19     打赏

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

* 文件名  : 一个8051单片机驱动LCD128x64 液晶屏的测试程序.c

* 描述    :  

* 创建人  : 

* 版本号  : V1.0

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

#include <reg52.h>

#include <string.h>


#define uchar unsigned char

#define uint  unsigned int


uchar code IC_DAT[];

uchar code pic1[];

uchar code pic2[];

uchar code pic3[]; 

//1~VSS:GND;2,3~VDD;19~VCC:A,20~GND:K

sbit RST = P2^4;     //  17~RST

sbit RS  = P2^5;     //  4

sbit RW = P2^6;     //  5~R/W

sbit E   = P2^7;     //  6~E

sbit PSB = P2^2;     //  15~PSB

#define DATA_BUS P0  //7~14:DBx


void TransferData(char data1,bit DI);

void display(void);

void display_grapic(void);

void delayms(uint n);

void DisplayLine(uchar line1,uchar line2);

void DisplayGraphic(uchar code *adder);

void delay(uint m);

void lcd_mesg(uchar code *adder1);


uchar code IC_DAT[]={

"     AT89S52    "  

"                "

"   80C51单片机  "

"    入门实验    "

};


uchar code IC_DAT2[]={

"  归来无所利,  "                        //0x80

"  黄犬却有情,  "                        //0x90

"  骨肉亦不喜。  "                        //0x88

"  当门卧摇尾。  "                        //0x98

};



void initinal(void)           //LCD字库初始化程序

{

           delay(40);             //大于40MS的延时程序

           PSB=1;                 //设置为8BIT并口工作模式

           delay(1);              //延时

           RST=0;                 //复位

           delay(1);              //延时

           RST=1;                 //复位置高

           delay(10);

           TransferData(0x30,0);  //Extended Function Set :8BIT设置,RE=0: basic instruction set, G=0 :graphic display OFF

           delay(100);            //大于100uS的延时程序

           TransferData(0x30,0);  //Function Set

           delay(37);             ////大于37uS的延时程序

           TransferData(0x08,0);  //Display on Control

           delay(100);            //大于100uS的延时程序

           TransferData(0x10,0);  //Cursor Display Control光标设置

           delay(100);            //大于100uS的延时程序

           TransferData(0x0C,0);  //Display Control,D=1,显示开

           delay(100);            //大于100uS的延时程序

           TransferData(0x01,0);  //Display Clear

           delay(10);             //大于10mS的延时程序

           TransferData(0x06,0);  //Enry Mode Set,光标从右向左加1位移动

           delay(100);            //大于100uS的延时程序

          }


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

* 名称 : Main()

* 功能 : 主函数

* 输入 : 无

* 输出 : 无

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

void     initina2(void)           //LCD显示图片(扩展)初始化程序

          {

           delay(40);             //大于40MS的延时程序

           PSB=1;                 //设置为8BIT并口工作模式

           delay(1);              //延时

           RST=0;                 //复位

           delay(1);              //延时

           RST=1;                 //复位置高

           delay(10);


           TransferData(0x36,0);  //Extended Function Set RE=1: extended instruction

           delay(100);            //大于100uS的延时程序

           TransferData(0x36,0);  //Extended Function Set:RE=1: extended instruction set

           delay(37);             ////大于37uS的延时程序

           TransferData(0x3E,0);  //EXFUNCTION(DL=8BITS,RE=1,G=1)

           delay(100);            //大于100uS的延时程序

           TransferData(0x01,0);  //CLEAR SCREEN

           delay(100);            //大于100uS的延时程序

          }


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

* 名称 : Main()

* 功能 : 主函数

* 输入 : 无

* 输出 : 无

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

void    main(void)

     {

         while(1)

            {

                  initina2();            //调用LCD显示图片(扩展)初始化程序

  

          DisplayGraphic(pic2);  //显示图片2

          delayms(200);                          


          initinal();                    //调用LCD字库初始化程序

          delay(100);            //大于100uS的延时程序

          lcd_mesg(IC_DAT);      //显示中文汉字1

          delayms(240);

          delayms(240);

           

          initinal();                    //调用LCD字库初始化程序

          delay(100);            //大于100uS的延时程序 

          lcd_mesg(IC_DAT2);     //显示中文汉字2

          delayms(240);

                  delayms(240);

                  initinal();  

        }

      }


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

* 名称 : Main()

* 功能 : 主函数

* 输入 : 无

* 输出 : 无

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

void   lcd_mesg(unsigned char code *adder1)

{

        unsigned char i;

        TransferData(0x80,0);  //Set Graphic Display RAM AddRSTs

        delay(100);

        for(i=0;i<32;i++)

                {

                          TransferData(*adder1,1);

                           adder1++;

                }


        TransferData(0x90,0);  //Set Graphic Display RAM AddRSTs

        delay(100);

        for(i=32;i<64;i++)

                {

                          TransferData(*adder1,1);

                           adder1++;

                }

}


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

* 名称 : Main()

* 功能 : 主函数

* 输入 : 无

* 输出 : 无

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

void    TransferData(char data1,bit DI)  //传送数据或者命令,当DI=0是,传送命令,当DI=1,传送数据.

          {

            RW=0;

            RS=DI;

            delay(1);

            DATA_BUS=data1;

            E=1;

            delay(1);

            E=0;

           }


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

* 名称 : Main()

* 功能 : 主函数

* 输入 : 无

* 输出 : 无

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

void    delayms(unsigned int n)            //延时10×n毫秒程序

                   {

                      unsigned int i,j;

                      for(i=0;i<n;i++)

                         for(j=0;j<2000;j++);

                   }


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

* 名称 : Main()

* 功能 : 主函数

* 输入 : 无

* 输出 : 无

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

void    delay(unsigned int m)            //延时程序

                   {

                      unsigned int i,j;

                      for(i=0;i<m;i++)

                         for(j=0;j<10;j++);

                   }


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

* 名称 : Main()

* 功能 : 主函数

* 输入 : 无

* 输出 : 无

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

void DisplayGraphic(unsigned char code *adder)

{


   int i,j;

//*******显示上半屏内容设置

   for(i=0;i<32;i++)              //

    { 

      TransferData((0x80 + i),0); //SET  垂直地址 VERTICAL ADD

      TransferData(0x80,0);       //SET  水平地址 HORIZONTAL ADD

      for(j=0;j<16;j++)

       {

         TransferData(*adder,1);

         adder++;

       }

    }           

//*******显示下半屏内容设置

   for(i=0;i<32;i++)              //

    {

      TransferData((0x80 + i),0); //SET 垂直地址 VERTICAL ADD

      TransferData(0x88,0);       //SET 水平地址 HORIZONTAL ADD

      for(j=0;j<16;j++)

       {

         TransferData(*adder,1);

         adder++;

       }

    }

}




unsigned char code pic2[]=

{

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x3F,0xC1,0xC0,0x00,0x1F,0x0F,0xC0,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x01,0xD8,0x01,0xC0,0x00,0x78,0x07,0xF8,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x06,0x26,0x07,0x40,0x00,0xE0,0x03,0x9F,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x0C,0x2A,0x0D,0x00,0x01,0xC0,0x01,0x83,0xC0,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x13,0x3C,0x30,0x00,0x03,0x9C,0x01,0x80,0xF8,0x00,0x78,0x00,0x00,

0x00,0x00,0x01,0xF4,0x80,0x64,0x00,0x07,0x3C,0x01,0x80,0x1E,0x00,0xFC,0x00,0x00,

0x00,0x00,0x06,0x2B,0x40,0xD0,0x00,0x06,0x18,0xC3,0x80,0x07,0x81,0x8C,0x00,0x00,

0x00,0x00,0x01,0xEC,0xC3,0x84,0x88,0x0E,0x01,0xE3,0x80,0x01,0xE3,0x0C,0x00,0x00,

0x00,0x00,0x00,0x67,0x06,0x3F,0xFC,0x0C,0x01,0xC7,0x00,0x7E,0x7F,0x1C,0x00,0x00,

0x00,0x00,0x01,0xC0,0x07,0xFC,0x08,0x0C,0x00,0x0E,0x01,0xE3,0x1E,0x18,0x00,0x00,

0x00,0x00,0x03,0x60,0x00,0x00,0x30,0x0E,0x00,0x1C,0x01,0xF1,0x8F,0xB0,0x3F,0x80,

0x00,0x00,0x06,0x60,0x00,0x00,0xE0,0x06,0x00,0x38,0x03,0xF1,0x8D,0xF0,0xF9,0x80,

0x00,0x00,0x03,0xE0,0x00,0x03,0x00,0x07,0x80,0xF0,0x03,0x23,0x80,0xF1,0xC1,0x80,

0x00,0x00,0x00,0x20,0x00,0x06,0x00,0x03,0xFF,0xC0,0x01,0x87,0x01,0xFB,0x81,0x80,

0x00,0x00,0x00,0x70,0x00,0x04,0x10,0x03,0xFE,0x00,0x01,0xFE,0x00,0x1E,0x03,0x00,

0x00,0x00,0x00,0x50,0x00,0x04,0x1C,0x01,0xC0,0x00,0x00,0x00,0x3E,0x0F,0x0E,0x00,

0x00,0x00,0x00,0x98,0x00,0x06,0x38,0x00,0xE0,0x00,0x00,0x00,0xE7,0x0F,0x9C,0x00,

0x00,0x00,0x01,0x98,0x00,0x02,0x7C,0x00,0x70,0x00,0x00,0x01,0xF1,0x81,0xF8,0x00,

0x00,0x00,0x00,0x6C,0x00,0x03,0xC0,0x00,0x38,0x00,0x00,0x01,0xF9,0x83,0xE0,0x00,

0x00,0x00,0x00,0x04,0x00,0x01,0x83,0x00,0x1E,0x00,0x00,0x01,0xB1,0x81,0xE0,0x00,

0x00,0x00,0x00,0x0E,0x00,0x00,0xC7,0x80,0x07,0x80,0x00,0x01,0x83,0x80,0x70,0x00,

0x00,0x00,0x00,0x1B,0x00,0x00,0x7F,0x00,0x01,0xF0,0x00,0x00,0xFE,0x00,0x30,0x00,

0x00,0x00,0x00,0x0F,0x00,0x01,0xFB,0x00,0x00,0xF8,0x00,0x00,0x10,0x00,0x38,0x00,

0x00,0x00,0x00,0x01,0x80,0x03,0xF0,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x18,0x00,

0x00,0x00,0x00,0x00,0xC0,0x00,0x18,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x18,0x00,

0x00,0x00,0x00,0x01,0xC0,0x00,0x0C,0x00,0x03,0x88,0x00,0x00,0x00,0x00,0x1C,0x00,

0x00,0x00,0x00,0x01,0x60,0x00,0x06,0x00,0x03,0x9C,0x00,0x00,0x00,0x00,0x0C,0x00,

0x00,0x00,0x00,0x00,0xE0,0x00,0x03,0x00,0x03,0x1E,0x00,0x00,0x10,0x60,0x0C,0x00,

0x00,0x00,0x00,0x00,0x30,0x00,0x01,0x00,0x07,0x37,0x00,0x00,0x40,0x10,0x1C,0x00,

0x00,0x00,0x00,0x00,0x30,0x00,0x01,0x80,0x07,0x3D,0xE0,0x00,0x80,0x00,0x1C,0x00,

0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x80,0x07,0x1B,0xFF,0x80,0x80,0x04,0x18,0x00,

0x00,0x00,0x00,0x00,0xD8,0x00,0x00,0xF0,0x07,0x1D,0x97,0x80,0x00,0x00,0x18,0x00,

0x00,0x00,0x00,0x00,0xC8,0x00,0x00,0xF0,0x03,0x0F,0x3F,0x01,0x00,0x00,0x38,0x00,

0x00,0x00,0x00,0x00,0x78,0x00,0x00,0xF0,0x07,0x87,0xFC,0x00,0x00,0x04,0x30,0x00,

0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x78,0x0F,0xC0,0x70,0x00,0x80,0x08,0x70,0x00,

0x00,0x00,0x00,0x00,0x18,0x00,0x1C,0xFF,0x0C,0xE0,0x00,0x00,0x80,0x10,0xE0,0x00,

0x00,0x00,0x00,0x01,0xF8,0x00,0x1C,0xFF,0xFC,0xF0,0x00,0x00,0x40,0x21,0xC0,0x00,

0x00,0x00,0x00,0x00,0x90,0x00,0xFC,0xE1,0xF8,0x38,0x00,0x00,0x1F,0x03,0x80,0x00,

0x00,0x00,0x00,0x00,0x70,0x00,0xFF,0x80,0x38,0x1E,0x00,0x00,0x00,0x0F,0x00,0x00,

0x00,0x00,0x00,0x0C,0x60,0x00,0x1F,0xF0,0x30,0x07,0x80,0x00,0x00,0x1E,0x00,0x00,

0x00,0x00,0x00,0x0B,0x80,0x00,0x7F,0xFF,0x70,0x03,0xF0,0x00,0x00,0xFF,0x00,0x00,

0x00,0x00,0x03,0x0F,0x00,0x00,0x74,0x1F,0xF0,0x00,0x7F,0x00,0x07,0xE3,0x00,0x00,

0x00,0x00,0x02,0x9C,0x00,0x00,0x0C,0x01,0xFE,0x00,0x0F,0xFF,0xFF,0x83,0x80,0x00,

0x00,0x00,0xE6,0xE0,0x00,0x00,0x1E,0x00,0x6E,0x00,0x00,0x7F,0xF8,0x01,0x80,0x00,

0x00,0x30,0xBF,0x00,0x00,0x00,0x67,0x00,0x60,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,

0x06,0x27,0xF0,0x00,0x00,0x31,0x87,0xF0,0x60,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,

0x0D,0xFE,0x00,0x00,0x00,0x3E,0x03,0x80,0x60,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,

0x7F,0x00,0x00,0x00,0x00,0x78,0x03,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,

0x38,0x00,0x00,0x00,0x0F,0x98,0x03,0x00,0x70,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,

0x07,0xE0,0x00,0x07,0xF8,0x1C,0x00,0x07,0x30,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,

0x00,0xFF,0xFF,0xFE,0x00,0x1F,0xC0,0x0F,0xB0,0x00,0x00,0x00,0x00,0x01,0x80,0x00,

0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x0F,0x98,0x18,0x00,0x00,0x00,0x03,0x80,0x00,

0x00,0x00,0x00,0x00,0x00,0x32,0x00,0x0F,0x1C,0x3C,0x00,0x00,0x00,0x07,0x0F,0x80,

0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x0F,0x0E,0x3E,0x00,0x00,0x00,0x0E,0x1D,0xC0,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x07,0x3C,0x00,0x00,0x00,0x3F,0x1D,0x80,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFC,0x00,0x00,0x00,0xF3,0xCF,0x8C,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFC,0x00,0x00,0x07,0xE0,0xFF,0x3C,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x3F,0x00,0x00,0xFF,0x00,0x3F,0xF8,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xF8,0x00,0x01,0xE0,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,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,0x00,0x00


};





关键词: 单片机     LCD     128x64     液晶屏     LCM     MC    

工程师
2020-02-02 20:13:55     打赏
2楼

是类似这种外形的LCD模块吧?


工程师
2020-02-02 20:24:05     打赏
3楼

请问楼主,这个LCD的控制器型号是? T6963支持吗?


院士
2020-02-03 09:56:02     打赏
4楼

这个代码要是状态机的实现模型就好了


工程师
2020-02-03 13:37:38     打赏
5楼

多谢楼主的分享


工程师
2020-02-03 14:51:17     打赏
6楼

代码很强大!


工程师
2020-02-03 22:17:33     打赏
7楼

这个程序分显示上、下半屏,应该是KS0107、KS0108的LCD控制器的,不是T6963


工程师
2020-02-03 22:30:54     打赏
8楼

收藏!

说不定后面用得到。谢谢楼主的共享~


共8条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]