51单片机驱动的不带字库的lcd12864液晶屏显示及其proteus仿真图如下:
单片机驱动12864液晶的头文件LCD12864.H源程序如下(附件里面有调用方法 很简单):
- //===========LCD12864.H===============
- #ifndef _LCD12864_H__
- #define _LCD12864_H__
- /*********************************************************************************************/
- #include <reg52.h> // 包含头文件
- #include <string.h> //用于指针
- typedef unsigned char uchar ;
- typedef unsigned int uint ;
- /*********************************************************************************************
- //接口定义
- //
- /*********************************************************************************************/
- #define LCD12864_DATABUS P1 // 定义LCD12864的数据总线
- sbit LCD12864_RS = P2^6; // 定义LCD12864的RS控制线
- sbit LCD12864_RW = P2^7; // 定义LCD12864的RW控制线
- sbit LCD12864_E = P3^0; // 定义LCD12864的E控制线
- sbit LCD12864_CS1 = P3^1; // 定义LCD12864的CS1控制线
- sbit LCD12864_CS2 = P3^2; // 定义LCD12864的CS2控制线
- //sbit LCD12864_RESET = P2 ^ 5; // 定义LCD12864的RESET控制线
- //sbit LCD12864_LEDK = P2 ^ 0; // 定义LCD12864的LEDK(BLK)控制线
- /*********************************************************************************************
- //数据定义
- //定义LCD12864的命令字
- /*********************************************************************************************/
- #define LCD12864_DISP_ON 0x3F // 打开LCD12864显示
- #define LCD12864_DISP_OFF 0x3E // 关闭LCD12864显示
- #define LCD12864_START_ROW 0xC0 // 显示起始行,可以用LCD12864_START_ROW+x设置起始行。(x<64)
- #define LCD12864_PAGE_ADDR 0xB8 // 页起始地址,可以用LCD12864_PAGE_ADDR+x设置当前页。(x<8)
- #define LCD12864_COL_ADDR 0x40 // 列起始地址,可以用LCD12864_COL_ADDR+x设置当前列。(x<64)
- //在BUSY和REST状态时,除读状态指令外,其他指令均不对LCD12864产生作用。
- //在对LCD12864操作之前要查询BUSY状态,以确定是否可以对LCD12864进行操作。
- #define LCD12864_STATUS_BUSY 0x80 // LCD12864忙状态屏蔽码
- #define LCD12864_STATUS_DISP_OFF 0x20 // LCD12864显示关闭状态屏蔽码
- #define LCD12864_STATUS_REST 0x10 // LCD12864复位状态屏蔽码
- void LCD12864_WriteCMD(uchar LCD_com);
- void LCD12864_WriteData(unsigned char LCD12864_data);
- void Delay(unsigned int count);
- /*********************************************************************************************
- //字符/图像定义库
- /*********************************************************************************************/
- /*-- 文字: 欢 --*/
- /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
- //0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0x55,0xaa,0xaa,0x55,0x55,0xaa,0xaa,
- //0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,
- //0x00,0x00,0x00,0x00,0x11,0x11,0x11,0x1F,0x22,0x22,0x22,0x00,0x00,0x00,0x00,0x00,
- //0x00,0x08,0x08,0x08,0x08,0x08,0x08,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
- /* 纵向取模,字节倒序 */
- unsigned char code zheng[]={
- 0x00,0x80,0xA0,0xA4,0xA8,0xF0,0x54,0x52,0x00,0xF0,0x08,0x68,0x98,0x08,0x00,0x00,
- 0x00,0x00,0x10,0x08,0x06,0x01,0x02,0x04,0x00,0x7F,0x00,0x02,0x04,0x07,0x00,0x00,
- };
- unsigned char code zhou[]={
- 0x00,0x00,0xE0,0x00,0xFC,0x00,0xE0,0x00,0xFC,0x20,0xC0,0x00,0xFE,0x00,0x00,0x00,
- 0x00,0x21,0x10,0x0C,0x03,0x00,0x00,0x00,0x0F,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,
- };
- unsigned char code jin[]={
- 0x00,0x80,0x40,0x20,0x90,0x8C,0xC3,0x44,0x48,0x10,0x20,0x60,0x40,0x40,0x40,0x00,
- 0x01,0x00,0x20,0x24,0x2A,0x22,0x3F,0x11,0x19,0x15,0x10,0x10,0x00,0x00,0x00,0x00,
- };
- unsigned char code te[]={
- 0x80,0x60,0x58,0x20,0xFE,0xA0,0x40,0x50,0x50,0x7F,0xE8,0xA8,0xA0,0xA0,0x20,0x00,
- 0x04,0x04,0x02,0x01,0x3F,0x00,0x01,0x05,0x09,0x21,0x7F,0x00,0x00,0x00,0x00,0x00,
- };
- unsigned char code lai[]={
- 0x00,0x08,0x08,0x48,0xAE,0x24,0xF4,0x14,0x9C,0x57,0x04,0x04,0x04,0x00,0x00,0x00,
- 0x00,0x20,0x22,0x12,0x0A,0x05,0x7F,0x03,0x05,0x09,0x19,0x11,0x10,0x10,0x00,0x00,
- };
- unsigned char code dian[]={
- 0x00,0x00,0xF0,0x10,0x90,0x90,0xFF,0x48,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x03,0x02,0x02,0x1F,0x21,0x21,0x21,0x20,0x20,0x20,0x1C,0x00,0x00,
- };
- unsigned char code zi[]={
- 0x00,0x40,0x40,0x40,0x44,0x44,0x44,0x72,0xCA,0x26,0x22,0x20,0x20,0x20,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x20,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- };
- unsigned char code you[]={
- 0x00,0x08,0x08,0x88,0x48,0xF8,0x4C,0x4B,0x28,0x24,0xE4,0x04,0x04,0x04,0x00,0x00,
- 0x04,0x02,0x01,0x00,0x00,0x7F,0x05,0x05,0x25,0x40,0x3F,0x00,0x00,0x00,0x00,0x00,
- };
- unsigned char code xian[]={
- 0x00,0xF8,0x04,0xB4,0xCC,0x00,0xFC,0xD4,0x54,0x42,0x3E,0x80,0x00,0x00,0x00,0x00,
- 0x00,0x3F,0x00,0x00,0x00,0x00,0x3F,0x10,0x09,0x02,0x05,0x0C,0x08,0x08,0x08,0x00,
- };
- unsigned char code gong[]={
- 0x00,0x00,0x80,0x60,0x18,0x00,0x82,0x02,0x0C,0x10,0x20,0x40,0xC0,0x80,0x80,0x00,
- 0x02,0x01,0x00,0x18,0x14,0x12,0x11,0x08,0x0A,0x0C,0x18,0x00,0x00,0x00,0x00,0x00,
- };
- unsigned char code si[]={
- 0x00,0x00,0x80,0xA0,0xA4,0x94,0x54,0xD2,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x03,0x04,0x04,0x04,0x02,0x03,0x00,0x10,0x20,0x1F,0x00,0x00,0x00,0x00,
- };
- /********************************************************************************************
- //软件延时 Delay()
- *********************************************************************************************/
- void Delay(unsigned int count)
- {
- unsigned char i;
- while(--count != 0)
- {
- for(i = 0; i < 125; i++); // ";" 表示空语句,CPU空转。
- } // i 从0加到125,在12M晶体下CPU大概耗时1毫秒
- }
- /*********************************************************************************************
- //LCD12864测忙函数 LCD12864_TestBusy()
- **********************************************************************************************/
- //void LCD12864_TestBusy(void)
- //{
- // LCD12864_RW = 1;
- // LCD12864_RS = 0;
- // LCD12864_E = 0; //???????????????
- // //Delay(1);
- // LCD12864_E = 1;
- // while(LCD12864_DATABUS & LCD12864_STATUS_BUSY);
- //}
- /*********************************************************************************************
- //写指令到LCD12864 LCD12864_WriteCMD()
- **********************************************************************************************/
- void LCD12864_WriteCMD(uchar LCD_com)
- {
- //LCD12864_TestBusy();
- LCD12864_RW = 0;
- LCD12864_RS = 0;
- LCD12864_DATABUS = LCD_com;
- LCD12864_E = 0;
- LCD12864_E = 1;
- //Delay(1);
- LCD12864_E = 0;
- //LCD12864_TestBusy();
- }
- /*********************************************************************************************
- //写数据到LCD12864 LCD12864_WriteData()
- **********************************************************************************************/
- void LCD12864_WriteData(unsigned char LCD12864_data)
- {
- LCD12864_RW = 0;
- LCD12864_RS = 1;
- LCD12864_DATABUS = LCD12864_data;
- LCD12864_E = 0;
- LCD12864_E = 1;
- //Delay(1);
- LCD12864_E = 0;
- //LCD12864_TestBusy();
- }
- /********************************************************************************************
- //从LCD12864读数据 LCD12864_ReadData()
- *********************************************************************************************/
- //unsigned char LCD12864_ReadData(void)
- //{
- // unsigned char LCD12864_data;
- // LCD12864_E = 0;
- // LCD12864_RW = 1; LCD12864_RS = 1;
- // LCD12864_E = 1;
- // LCD12864_data = LCD12864_DATABUS; //送入8位数据
- // LCD12864_TestBusy(); //读LCM忙
- // return LCD12864_data;
- //}
- /********************************************************************************************
- //向LCD12864指定点写一字节数据 LCD12864_Write1Byte_X_Y()
- //x(0-127) y(0-63)为坐标值 LCD12864_data 为所要写的数据
- /********************************************************************************************/
- //void LCD12864_Write1Byte_X_Y( uchar x,uchar y,uchar LCD12864_data)
- //{
- // x = x&0x7f;
- // y = y&0x3f; //参数过滤
- // LCD12864_CS1 = 1;
- // LCD12864_CS2 = 1; //不选中左半屏及右半屏
- // if(x<64)
- // {
- // LCD12864_CS1 = 0; // 选中左半屏
- // }
- // else
- // {
- // LCD12864_CS2 = 0; // 选中右半屏
- // x = x-64;
- // }
- // LCD12864_WriteCMD(LCD12864_COL_ADDR+x); // 设置当前列地址,即x坐标
- // LCD12864_WriteCMD(LCD12864_PAGE_ADDR+y); // 设置当前页地址,即y坐标
- // LCD12864_WriteData(LCD12864_data); // 向LCD12864写数据
- //}
- /********************************************************************************************
- //从LCD12864指定点读取一字数据 LCD12864_Read1Byte_X_Y()
- /********************************************************************************************/
- //unsigned char LCD12864_Read1Byte_X_Y( uchar x,uchar y)
- //{
- // uchar LCD12864_data;
- // x = x&0x7f;
- // y = y&0x3f; //参数过滤
- // LCD12864_CS1 = 1; LCD12864_CS2 = 1; //不选中左半屏及右半屏
- // if(x<64)
- // { // 判断选择左、右半屏
- // LCD12864_CS1 = 0; // 选中左半屏
- // }
- // else
- // {
- // LCD12864_CS2 = 0; // 选中右半屏
- // x = x-64;
- // }
- // LCD12864_WriteCMD(LCD12864_COL_ADDR+x); // 设置当前列地址,即x坐标
- // LCD12864_WriteCMD(LCD12864_PAGE_ADDR+y); // 设置当前页地址,即y坐标
- // LCD12864_data = LCD12864_ReadData(); // 向LCD12864写数据
- // return LCD12864_data;
- //}
- /********************************************************************************************
- //向LCD12864填充数据 LCD12864_Fill_Screen()
- //设置涮屏速度(为1不涮屏,默认为60) //欲写入的数据
- *********************************************************************************************/
- void LCD12864_Fill_Screen( uchar refresh_rate,uchar LCD_Data)
- {
- unsigned char x,y;
- LCD12864_CS1 = 0; // 选中左半屏
- LCD12864_CS2 = 0; // 选中右半屏
- LCD12864_WriteCMD(LCD12864_START_ROW+0); // 显示起始行设置为0
- for(x=0;x<8;x++)
- {
- Delay(refresh_rate); // 刷屏速度延时
- LCD12864_WriteCMD(LCD12864_PAGE_ADDR+x); // 设置页地址
- LCD12864_WriteCMD(LCD12864_COL_ADDR); // 设置列地址
- for(y=0;y<128;y++) //64
- {LCD12864_WriteData( LCD_Data );}
- }
- LCD12864_CS1 = 1; // 不选中左半屏
- LCD12864_CS2 = 1; // 不选中右半屏
- }
- /********************************************************************************************
- //LCD12864清屏 LCD12864_Clear_Screen()
- *********************************************************************************************/
- void LCD12864_Clear_Screen(void)
- {
- LCD12864_Fill_Screen(20,0x00); //写入0到每个显示区
- }
- /********************************************************************************************
- //LCD12864黑屏 LCD12864_Clear_black()
- *********************************************************************************************/
- //void LCD12864_Clear_black(void)
- //{
- // LCD12864_Fill_Screen(60,0xff); //可写入其它数值以填满LCD屏
- //}
- /********************************************************************************************
- //显示128*64图片 LCD12864_Disp_Bitmap_12864()
- *********************************************************************************************/
- //void LCD12864_Disp_Bitmap_12864( uchar t,uchar code *bitmap_12864)
- //{ //128*64点阵图像所在数组表
- //unsigned char j,k;
- //for(k=0;k<8;k++)
- // { //设置8页的显示
- // Delay(t);
- // LCD12864_CS1 = 0;
- // LCD12864_CS2 = 1; //半屏选中
- // LCD12864_WriteCMD(LCD12864_PAGE_ADDR+k); //选中页
- // LCD12864_WriteCMD(LCD12864_COL_ADDR+0); //选中列
- // for(j=0;j<64;j++) //64
- // {
- // LCD12864_WriteData(bitmap_12864[k*128+j]); //开始写入数据
- // }
- // LCD12864_CS1 = 0;
- // LCD12864_CS2 = 0;
- // LCD12864_WriteCMD(LCD12864_PAGE_ADDR+k);
- // LCD12864_WriteCMD(LCD12864_COL_ADDR+0);
- // for(j=64;j<128;j++)
- // {
- // LCD12864_WriteData(bitmap_12864[k*128+j]);
- // }
- // }
- //}
- /********************************************************************************************
- //在LCD12864的指定点显示16*16点阵汉字 LCD12864_Disp_Chinese_16_16()
- //设置书写速度(为1直接显示,默认为12)//输入8:8*16字符,16:16*16字符
- //LCD12864的页地址(0~7)//LCD12864的列地址(0~128)注意:右半屏起始是64 huan
- *********************************************************************************************/
- void LCD12864_Disp16(uchar b,uchar LCD12864_page,uchar LCD12864_col,uchar code *Chardata)
- { //16*16点阵汉字字模(纵向取模,字节倒序)
- unsigned char j=0,i=0;
- if(LCD12864_col < 64 )
- {
- LCD12864_CS1 = 0;
- LCD12864_CS2 = 1; //判断屏幕使能
- }
- else
- {
- LCD12864_CS1 = 1;
- LCD12864_CS2 = 0;
- LCD12864_col = LCD12864_col - 64;
- }
- for(j=0;j<2;j++)
- {
- LCD12864_WriteCMD(LCD12864_PAGE_ADDR+LCD12864_page+j);
- LCD12864_WriteCMD(LCD12864_COL_ADDR+LCD12864_col);
- for(i=0;i<b;i++)
- {
- LCD12864_WriteData(Chardata[b*j+i]);
- Delay(10);
- }
- }
- }
- /********************************************************************************************
- //LCD12864初始化 LCD12864_Init()
- //
- *********************************************************************************************/
- void LCD12864_Init(void)
- {
- //LCD12864_RESET = 0; //复位
- //Delay(300);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
LCD12864源码及proteus仿真.rar
(88.01 KB, 下载次数: 134)
|