不带字库12864程序实例.docx

上传人:牧羊曲112 文档编号:3207419 上传时间:2023-03-11 格式:DOCX 页数:18 大小:40.04KB
返回 下载 相关 举报
不带字库12864程序实例.docx_第1页
第1页 / 共18页
不带字库12864程序实例.docx_第2页
第2页 / 共18页
不带字库12864程序实例.docx_第3页
第3页 / 共18页
不带字库12864程序实例.docx_第4页
第4页 / 共18页
不带字库12864程序实例.docx_第5页
第5页 / 共18页
亲,该文档总共18页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《不带字库12864程序实例.docx》由会员分享,可在线阅读,更多相关《不带字库12864程序实例.docx(18页珍藏版)》请在三一办公上搜索。

1、不带字库12864程序实例/*/ /程序部分开始/ /* /头文件定义 / /*/ #include / 包含头文件 #include /用于指针 /* /接口定义 / /*/ #define LCM12864_DB7_DB0 P0 / 定义LCM12864的数据总线 sbit LCM12864_RS = P2 3; / 定义LCM12864的RS控制线 sbit LCM12864_RW = P2 4; / 定义LCM12864的RW控制线 sbit LCM12864_E = P2 2; / 定义LCM12864的E控制线 sbit LCM12864_CS1 = P2 7; / 定义LCM12

2、864的CS1控制线 sbit LCM12864_CS2 = P2 6; / 定义LCM12864的CS2控制线 sbit LCM12864_RESET = P2 5; / 定义LCM12864的RESET控制线 sbit LCM12864_LEDK = P2 0; / 定义LCM12864的LEDK控制线 /* /数据定义 /定义LCM12864的命令字 /*/ #define LCM12864_DISP_ON 0x3f / 打开LCM12864显示 #define LCM12864_DISP_OFF 0x3e / 关闭LCM12864显示 #define LCM12864_START_RO

3、W 0xc0 / 显示起始行0,可以用LCM12864_START_ROW+x设置起始行。(x64) #define LCM12864_PAGE_START_ADDR 0xb8 / 页起始地址,可以用LCM12864_PAGE_START_ADDR+x设置当前页。(x8) #define LCM12864_COL_START_ADDR 0x40 / 列起始地址,可以用LCM12864_COL_START_ADDR+x设置当前列。(x64) /定义LCM12864的状态屏蔽码 /在BUSY和REST状态时,除读状态指令外,其他指令均不对LCM12864产生作用。 /在对LCM12864操作之前要

4、查询BUSY状态,以确定是否可以对LCM12864进行操作。 #define LCM12864_STATUS_BUSY 0x80 / LCM12864忙状态屏蔽码 #define LCM12864_STATUS_DISP_OFF 0x20 / LCM12864显示关闭状态屏蔽码 #define LCM12864_STATUS_REST 0x10 / LCM12864复位状态屏蔽码 /* /字符/图像定义库 / /*/ /*- 文字: 欢 -*/ /*- 宋体12; 此字体下对应的点阵为:宽x高=16x16 -*/ /* 纵向取模,字节倒序 */ unsigned char code huan1

5、= 0x0C,0x6C,0xEC,0x8C,0xFC,0x3C,0x40,0x70,0x3F,0xCF,0xCC,0x0C,0x3C,0x3C,0x00,0x00, 0x10,0x38,0x1C,0x07,0x07,0x4C,0x60,0x30,0x18,0x0F,0x07,0x0C,0x18,0x30,0x20,0x00, ; /*- 文字: 迎 -*/ /*- 宋体12; 此字体下对应的点阵为:宽x高=16x16 -*/ /* 纵向取模,字节倒序 */ unsigned char code ying2= 0x60,0x66,0xEE,0xE8,0x00,0xFE,0xFE,0x07,0x0

6、3,0xFE,0xFE,0x06,0xFE,0xFE,0x00,0x00, 0x40,0x60,0x3F,0x1F,0x30,0x67,0x67,0x62,0x60,0x6F,0x6F,0x62,0x67,0x67,0x60,0x00 ; / / ASCII字模的数据表 / / 码表从0x200x7e / / 字库:Asc8X16E.dat 纵向取模下高位 / / unsigned char code nAsciiDot = / ASCII 0x04,0xFC,0xFC,0x04,0x0C,0xF8,0xF0,0x00, / -D- 0x08,0x0F,0x0F,0x08,0x0C,0x07,

7、0x03,0x00, 0xE0,0xE0,0x00,0x00,0x00,0xE0,0xE0,0x00, / -y- 0x47,0x4F,0x48,0x48,0x68,0x3F,0x1F,0x00, 0x00,0x10,0x18,0xFC,0xFC,0x00,0x00,0x00, / -1- 0x00,0x08,0x08,0x0F,0x0F,0x08,0x08,0x00, 0x08,0x0C,0x84,0xC4,0x64,0x3C,0x18,0x00, / -2- 0x0E,0x0F,0x09,0x08,0x08,0x0C,0x0C,0x00, 0xB8,0xFC,0x44,0x44,0x44,

8、0xFC,0xB8,0x00, / -8- 0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00, 0xF0,0xF8,0x4C,0x44,0x44,0xC0,0x80,0x00, / -6- 0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00, 0xC0,0xE0,0xB0,0x98,0xFC,0xFC,0x80,0x00, / -4- 0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00, ; / / Bitmap点阵数据表 / / 图片: C:.鎈doyleee.bmp,纵向取模下高位,数据排列:从左到右从上

9、到下 / / 图片尺寸: 128 * 64 / / unsigned char code doyleee = / 数据表 0xFF,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x81,0xF1,0xF1,0xF1,0x71,0x31, 0x31,0x71,0xF1,0xF1,0xE1,0xC1,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01

10、,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x81,0xF1,0xF1,0xF1,0x71,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0

11、x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xFF, 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0xF0,0xFF,0xFF,0xFF,0x0F,0x00,0x00, 0x00,0x00,0xC0,0xFF,0xFF,0xFF,0x7F,0x00, 0x00,0xF0,0xFC,0xFE

12、,0xFE,0x0F,0x03,0x03, 0x07,0xFF,0xFE,0xFE,0xF8,0x00,0xE0,0xE0, 0xE0,0xE0,0x00,0x03,0x3F,0xFF,0xFF,0xFC, 0xC0,0xF0,0xFE,0x3F,0x0F,0x03,0x00,0xF0, 0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xF0,0xFC, 0xFE,0xFE,0x3F,0x33,0x33,0x33,0x3F,0x3F, 0x3E,0x38,0x00,0x00,0xF0,0xFC,0xFE,0xFE, 0x3F,0x33,0x33,0x33,0x3F,0x3F,0x

13、3E,0x38, 0x00,0x00,0xF0,0xFC,0xFE,0xFE,0x3F,0x33, 0x33,0x33,0x3F,0x3F,0x3E,0x38,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80, 0x8E,0x8F,0x8F,0x8F,0x8C,0x8C,0x8C,0x8C, 0x8E

14、,0x8F,0x87,0x87,0x83,0x81,0x80,0x80, 0x80,0x81,0x87,0x87,0x8F,0x8E,0x8C,0x8C, 0x8F,0x87,0x87,0x83,0x80,0x80,0x80,0xC0, 0xC0,0xC0,0xC0,0xC0,0xC0,0xF3,0x7F,0x3F, 0x0F,0x03,0x00,0x00,0x00,0x00,0x0E,0x0F, 0x0F,0x0F,0x00,0x00,0x00,0x00,0x01,0x07, 0x07,0x0F,0x0E,0x0C,0x0C,0x0F,0x07,0x03, 0x01,0x00,0x00,0x

15、00,0x01,0x07,0x07,0x0F, 0x0E,0x0C,0x0C,0x0F,0x07,0x03,0x01,0x00, 0x00,0x00,0x01,0x07,0x07,0x0F,0x0E,0x0C, 0x0C,0x0F,0x07,0x03,0x01,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,

16、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,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x

17、00,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,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, 0xFF,0x40,0x40,

18、0x40,0x40,0x40,0x40,0x40, 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, 0x40,0x40,0x40,0x40,0x40,0x00,0x00,0xFC, 0xFC,0x04,0x0C,0xF8,0xF0,0x00,0x00,0xF0, 0xF0,0x00,0x00,0xF0,0xF0,0x00,0x00,0x40, 0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x10, 0x10,0x18,0xFC,0xFC,0x00,0x00,0x00,0x18, 0x1C,0x84,0xC4,0x7C,0x38,0x0

19、0,0x00,0xB8, 0xFC,0x64,0xC4,0xFC,0xB8,0x00,0x00,0xE0, 0xF0,0x3C,0x2C,0xE4,0xC0,0x00,0x00,0x80, 0xFC,0x7C,0x00,0xF0,0xF0,0x00,0x00,0xFC, 0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0xF8, 0xFC,0x04,0x04,0x1C,0x18,0x00,0x00,0x40, 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,

20、0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF, 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07, 0x07,0x04,0x06,0x03,0x01,0x00,0x20,0x23, 0x27,0x34,0x1C,0x0F,0x03,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x0

21、7,0x07,0x04,0x00,0x00,0x06, 0x07,0x05,0x04,0x04,0x04,0x00,0x00,0x03, 0x07,0x04,0x04,0x07,0x03,0x00,0x00,0x03, 0x07,0x04,0x04,0x07,0x03,0x00,0x00,0x01, 0x01,0x01,0x01,0x07,0x07,0x01,0x00,0x07, 0x07,0x04,0x04,0x04,0x04,0x00,0x00,0x03, 0x07,0x04,0x04,0x07,0x03,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0

22、x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x00,0x00,0x00

23、, 0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0, 0x00,0x00,0x00,0x00,0xF0,0xF0,0x00,0x00, 0x00,0x20,0x20,0xF0,0xF0,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xF0, 0x10,0x10,0x90,0x50,0xF0,0xE0,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0

24、x00,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,0xFF, 0xFF,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80

25、,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x81,0x83, 0x86,0x8C,0x8C,0x86,0x83,0x81,0x80,0x80, 0x88,0x88,0x88,0x8F,0x8F,0x88,0x88,0x88, 0x80,0x80,0x8C,0x8C,0x80,0x80,0x87,0x8F, 0x8A,0x89,0x88,0x88,0x8F,0x87,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x

26、80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xFF ; /* /软件延时 Delay / */ void Delay(unsigned int count) unsigned char i; while(-count != 0) for

27、(i = 0; i 125; i+); / ; 表示空语句,CPU空转。 / i 从0加到125,在12M晶体下CPU大概耗时1毫秒 /* /LCM12864测忙函数 LCM12864_TestBusy / */ void LCM12864_TestBusy(void) LCM12864_RW = 1; LCM12864_RS = 0; LCM12864_E = 0; LCM12864_E = 1; while(LCM12864_DB7_DB0 & LCM12864_STATUS_BUSY); /* /写指令到LCM12864 LCM12864_WriteCMD / */ void LCM12

28、864_WriteCMD(unsigned char LCM12864_command) /LCM12864_command 欲写入指令 LCM12864_TestBusy; LCM12864_RW = 0; LCM12864_RS = 0; LCM12864_DB7_DB0 = LCM12864_command; LCM12864_E = 0; LCM12864_E = 1; LCM12864_TestBusy; /* /写数据到LCM12864 LCM12864_WriteData / */ void LCM12864_WriteData(unsigned char LCM12864_da

29、ta) /LCM12864_command 欲写入数据 LCM12864_RW = 0; LCM12864_RS = 1; LCM12864_DB7_DB0 = LCM12864_data; LCM12864_E = 0; LCM12864_E = 1; LCM12864_TestBusy; /读LCM忙 /* /从LCM12864读数据 LCM12864_ReadData / */ unsigned char LCM12864_ReadData(void) unsigned char LCM12864_data; LCM12864_E = 0; LCM12864_RW = 1; LCM128

30、64_RS = 1; LCM12864_E = 1; LCM12864_data = LCM12864_DB7_DB0; /送入8位数据 LCM12864_TestBusy; /读LCM忙 return LCM12864_data; /* /向LCM12864指定点写一字节数据 LCM12864_Write1Byte_X_Y / /*/ void LCM12864_Write1Byte_X_Y( unsigned char x, /x坐标值(0-127) unsigned char y, /y坐标值(0-63) unsigned char LCM12864_data) /LCM12864_da

31、ta 所要写的数据 x = x&0x7f; y = y&0x3f; /参数过滤 LCM12864_CS1 = 1; LCM12864_CS2 = 1; /不选中左半屏及右半屏 if(x64) / 判断选择左、右半屏 LCM12864_CS1 = 0; / 选中左半屏 else LCM12864_CS2 = 0; / 选中右半屏 x = x-64; LCM12864_WriteCMD(LCM12864_COL_START_ADDR+x); / 设置当前列地址,即x坐标 LCM12864_WriteCMD(LCM12864_PAGE_START_ADDR+y); / 设置当前页地址,即y坐标 LC

32、M12864_WriteData(LCM12864_data); / 向LCM12864写数据 /* /从LCM12864指定点读取一字数据 LCM12864_Read1Byte_X_Y / /*/ unsigned char LCM12864_Read1Byte_X_Y( unsigned char x, /x坐标值(0-127) unsigned char y) /y坐标值(0-63) unsigned char LCM12864_data; x = x&0x7f; y = y&0x3f; /参数过滤 LCM12864_CS1 = 1; LCM12864_CS2 = 1; /不选中左半屏及

33、右半屏 if(x64) / 判断选择左、右半屏 LCM12864_CS1 = 0; / 选中左半屏 else LCM12864_CS2 = 0; / 选中右半屏 x = x-64; LCM12864_WriteCMD(LCM12864_COL_START_ADDR+x); / 设置当前列地址,即x坐标 LCM12864_WriteCMD(LCM12864_PAGE_START_ADDR+y); / 设置当前页地址,即y坐标 LCM12864_data = LCM12864_ReadData; / 向LCM12864写数据 return LCM12864_data; /* /向LCM12864填

34、充数据 LCM12864_Fill_Screen / */ void LCM12864_Fill_Screen( unsigned char t, /设置涮屏速度 unsigned char LCM12864_FillData) /欲写入的数据 unsigned char x,y; LCM12864_CS1 = 0;LCM12864_CS2 = 0; / 选中左半屏及右半屏 LCM12864_WriteCMD(LCM12864_START_ROW+0); / 设置显示起始行为0 for(x=0;x8;x+) Delay(t); / 涮屏速度延时 LCM12864_WriteCMD(LCM128

35、64_PAGE_START_ADDR+x); / 设置页地址 LCM12864_WriteCMD(LCM12864_COL_START_ADDR);/ / 设置列地址 for(y=0;y64;y+) LCM12864_WriteData(LCM12864_FillData); LCM12864_CS1 = 1; / 不选中右半屏 LCM12864_CS2 = 1; / 不选中右半屏 /* /LCM12864清屏 LCM12864_Clear_Screen / */ void LCM12864_Clear_Screen(void) LCM12864_Fill_Screen(60,0x00); /

36、写入0到每个显示区 /* /LCM12864黑屏 LCM12864_Clear_black / */ void LCM12864_Clear_black(void) LCM12864_Fill_Screen(0xff); /可写入其它数值以填满LCD屏 /* /显示128*64图片 LCM12864_Disp_Bitmap_12864 / */ void LCM12864_Disp_Bitmap_12864( unsigned char t, /设置涮屏速度 unsigned char code *bitmap_12864) /128*64点阵图像所在数组表 unsigned char j,k

37、; for(k=0;k8;k+) /设置8页的显示 Delay(t); LCM12864_CS1 = 0;LCM12864_CS2 = 1; /半屏选中 LCM12864_WriteCMD(LCM12864_PAGE_START_ADDR+k); /选中页 LCM12864_WriteCMD(LCM12864_COL_START_ADDR+0); /选中列 for(j=0;j64;j+) LCM12864_WriteData(bitmap_12864k*128+j); /开始写入数据 LCM12864_CS1 = 1;LCM12864_CS2 = 0; LCM12864_WriteCMD(LCM12864_PAGE_START_ADDR+k); LCM12864_WriteCMD(LCM12864_COL_START_ADDR+0); for(j=64;j128;j+) LCM12864_WriteData(bitmap_12864k*128+j); /* /在LCM12864的指定点显示16*16点阵汉字 LCM12864_Disp_Ch

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号