资源描述
LCD12864绘图方法如下:1、 绘图方法: 1、使用扩展指令集并关闭绘图显示 2、输入y轴坐标3、输入x轴坐标4、写入数据D15-D85、写入数据D7-D06、开绘图显示7、返回普通指令对应程序如下:LCD_write_comm(0x34);/使用扩充指令集LCD_delay();LCD_write_comm(0x80+y);/y坐标起始地址LCD_delay();LCD_write_comm(0x80+x);/x坐标起始地址LCD_delay();LCD_write_date(0x55);/写入数据D15-D8LCD_delay();LCD_write_date(0x55);/写入数据D7-D0LCD_delay();LCD_write_comm(0x36);/显示RAMLCD_delay();LCD_write_comm(0x30);/退出扩展指令集LCD_delay();程序执行效果则是第一行的第1-16个像素点会描出0x5555的二进制像素点,则后面的整个屏幕则是花屏,如果只想看到这0x5555,这几个像素点,则必须要给LCD的RAM重新赋值,也可以说是清屏,程序如下:void LCD12864_RAM_Cls()u8 x,y;/xy坐标LCD_write_comm(0x34);/使用扩充指令集LCD_delay();for(y=0;y32;y+)LCD_write_comm(0x80+y);/y坐标起始地址LCD_delay();LCD_write_comm(0x80);/x坐标起始地址LCD_delay();for(x=0;x16;x+)LCD_write_date(0x00);LCD_delay();LCD_write_date(0x00);LCD_delay();LCD_write_comm(0x36);/显示RAMLCD_delay();LCD_write_comm(0x30);/退出扩展指令集LCD_delay();二、坐标与显示X轴坐标设定初始值后会自动加1,取值范围0-15Y轴需要人为加1,取值范围为0-31整个屏幕分为上下屏,上屏对应坐标为x(0-7)y(0-31),下屏对应坐标为x(8-15)y(0-31)三、LCD12864图片显示代码1、 Main.c#includecommon.h#includedelay.h#include12864.hunsigned char code Picture= / 图片数据表/此处添加图片取模16进制码共1024Byte,取模方式:从左到右从上到下0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x06,0x30,0x01,0xE0,0x00,0x00,0x2A,0x00,0x00,0xD8,0x00,0x00,0x00,0x00,0x01,0x80,0x0F,0x7B,0x63,0xE0,0x00,0x00,0x22,0x00,0x01,0x24,0x00,0x00,0x00,0x00,0x01,0x80,0x0F,0xFB,0x63,0x07,0x34,0x00,0x14,0x00,0x01,0x04,0x00,0x00,0x00,0x00,0x01,0x80,0x0D,0xDB,0x63,0x01,0xBC,0x00,0x08,0x00,0x00,0x88,0x00,0x00,0x00,0x00,0x01,0x80,0x0C,0x1B,0x63,0x07,0xB0,0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x01,0x80,0x0C,0x1B,0x63,0xED,0xB0,0xDB,0x00,0x01,0x00,0x20,0x00,0x00,0x00,0x00,0x01,0x80,0x0C,0x19,0xE1,0xE7,0xB0,0xDB,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x0C,0x19,0xE1,0xE7,0xB0,0xDB,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x05,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x0A,0x80,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x0A,0x00,0x00,0xFF,0xF8,0xE0,0x05,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x06,0xC0,0x15,0x00,0x1F,0xFF,0xFF,0xC0,0x02,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x09,0x20,0x11,0x00,0xFB,0xFF,0xE1,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x08,0x20,0x0A,0x03,0x9F,0x00,0x9E,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x04,0x40,0x04,0x0E,0x70,0x00,0x81,0xC7,0x80,0x01,0x40,0x00,0x00,0x00,0x01,0x80,0x02,0x80,0x00,0x1D,0x80,0x00,0xE0,0x61,0xE0,0x02,0xA0,0x00,0x00,0x00,0x01,0xC0,0x01,0x00,0x00,0x77,0x9F,0xFC,0xF0,0x18,0xF8,0x02,0x20,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x01,0xDF,0x00,0x00,0xF3,0x0C,0x3C,0x01,0x40,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x03,0x9E,0x00,0x00,0xF8,0x06,0x1E,0x00,0x80,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x07,0x0E,0x30,0x01,0xFC,0x7F,0x07,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x07,0x0E,0x30,0x01,0xFC,0x7F,0x07,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x7E,0xFF,0xFF,0xFF,0xFF,0xFF,0x83,0xC0,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x0F,0xFD,0xFF,0xFF,0xFF,0xFF,0xFC,0x01,0xF0,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x3F,0x81,0xFF,0x00,0x00,0x00,0x00,0x1F,0xF0,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0xFE,0xF0,0x00,0x00,0x01,0x00,0x00,0xC0,0x1C,0x00,0x00,0x00,0x00,0x01,0x80,0x03,0xC0,0x07,0x80,0x00,0x03,0xE0,0x07,0x00,0x1C,0x00,0x00,0x00,0x00,0x01,0x80,0x03,0x80,0x03,0x60,0x00,0x03,0xE0,0x0C,0x00,0x0E,0x00,0x00,0x00,0x00,0x01,0x80,0x07,0x00,0x00,0xC0,0x00,0x00,0x20,0x18,0x00,0x07,0x00,0x00,0x00,0x00,0x01,0x80,0x09,0x01,0x80,0x60,0x00,0x00,0x20,0x73,0x9F,0x03,0x80,0x00,0x00,0x00,0x01,0x80,0x1E,0x0F,0xF2,0x20,0x00,0x00,0x20,0x67,0xFF,0xC1,0xC0,0x00,0x00,0x00,0x01,0x80,0x1E,0x1F,0xF9,0x30,0x00,0x00,0x20,0xEF,0xFF,0xE0,0xE0,0x00,0x00,0x00,0x01,0x80,0x38,0x3F,0xFC,0x90,0x00,0x00,0x20,0xCB,0xFF,0xF9,0xF0,0x00,0x00,0x00,0x01,0x80,0x7F,0x7F,0xFE,0x10,0x00,0x00,0x20,0xDB,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x01,0x80,0x6E,0xF9,0xBF,0x10,0x00,0x00,0x20,0xF7,0xED,0xFF,0xF0,0x00,0x00,0x00,0x01,0x80,0x7C,0xFC,0x3F,0x10,0x00,0x00,0x20,0x67,0xE1,0xFD,0xE0,0x00,0x00,0x00,0x01,0x80,0x7C,0xFC,0x3F,0x10,0x00,0x00,0x20,0x67,0xE1,0xFD,0xE0,0x00,0x00,0x00,0x01,0x80,0x38,0xFC,0x3F,0x18,0x00,0x00,0x20,0x87,0xE0,0xFD,0xC0,0x00,0x00,0x00,0x01,0x80,0x38,0xF1,0x8F,0x18,0x00,0x1F,0xE7,0x87,0x9C,0x7D,0xC0,0x00,0x00,0x00,0x01,0x80,0x1C,0xFE,0x1F,0x81,0xFF,0xFF,0xC0,0x0F,0xE0,0xFF,0x80,0x00,0x00,0x00,0x01,0x80,0x0C,0xFC,0x3F,0x80,0x00,0x00,0x00,0x0F,0xE1,0xF8,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0xF9,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xEC,0xFE,0x00,0x00,0x00,0x00,0x01,0x80,0x03,0xF9,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x01,0x80,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x00,0x60,0x00,0x00,0x01,0xC0,0x02,0x80,0x00,0x00,0x00,0x1C,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF;void main()LCD12864_init();/LCD初始化/LCD12864_RAM_Cls();LCD_Picture_show(Picture);while(1);2、 common.h#ifndef _COMMON_H#define _COMMON_H#include#include intrins.h#define u8 unsigned char/无符号字符型#define u16 unsigned int/无符号整型 #endif3、 delay.h#ifndef _DELAY_H#define _DELAY_H#include common.h#define MAIN_Fosc 24000000L /定义主时钟void delay_ms(u16 ms);void LCD_delay();/LCD延时函数#endif4、delay.c#include delay.h/-毫秒延时函数-void delay_ms(u16 ms) u16 i; do i = MAIN_Fosc / 13000; while(-i) ; /14T per loop while(-ms);/-LCD延时函数-void LCD_delay(void) _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();5、12864.h#ifndef _12864_H#define _12864_h#include common.hsbit CS =P11;/片选sbit SID=P12;/数据口sbit CLK=P13;/同步时钟void LCD_write_spi(u8 date);/LCD SPI数据写入void LCD_write_comm(u8 comm);/LCD写指令void LCD_write_date(u8 date);/LCD写数据void LCD12864_init();/LCD初始化void LCD12864_RAM_Cls();/RAM清屏void LCD_print(u8 *date);/LCD字符串显示void LCD_Picture_show(u8 *date);#endif6、12864.c#includecommon.h#includedelay.h#include12864.h/-LCD SPI数据写入-void LCD_write_spi(u8 date)u8 i;for(i=0;i8;i+)CS=1;if(date&0x80)SID=1;elseSID=0;date = 1;CLK=1;LCD_delay();CLK=0;/-LCD写指令-void LCD_write_comm(u8 comm)u8 date = 0xf8;/串行写入指令到LCD(数据手册)u8 comm_H = comm&0xf0;u8 comm_L = comm4;CS =0;CLK=0;SID=0;LCD_delay();LCD_write_spi(date);LCD_write_spi(comm_H);LCD_write_spi(comm_L);CS=0;/-LCD写数据-void LCD_write_date(u8 date)u8 date2 = 0xfa;/串行写入指令到LCD(数据手册)u8 date_H = date&0xf0;u8 date_L = date4;CS =0;CLK=0;SID=0;LCD_delay();LCD_write_spi(date2);LCD_write_spi(date_H);LCD_write_spi(date_L);CS=0;/-LCD初始化-void LCD12864_init()LCD_write_comm(0x01);/清屏幕delay_ms(1);LCD_write_comm(0x0c);/开显示,游标显示关闭LCD_delay();LCD_write_comm(0x81);/设定坐标LCD_delay();/-写RAM清屏-void LCD12864_RAM_Cls()u8 x,y;/xy坐标LCD_write_comm(0x34);/使用扩充指令集LCD_delay();for(y=0;y32;y+)LCD_write_comm(0x80+y);/y坐标起始地址LCD_delay();LCD_write_comm(0x80);/x坐标起始地址LCD_delay();for(x=0;x16;x+)LCD_write_date(0x00);LCD_delay();LCD_write_date(0x00);LCD_delay();LCD_write_comm(0x36);/显示RAMLCD_delay();LCD_write_comm(0x30);/退出扩展指令集LCD_delay();/-LCD字符串显示-void LCD_print(u8 *date)u8 j=0;while(datej!=0)LCD_write_date(datej);j+;LCD_delay();/-图片显示-void LCD_Picture_show(u8 *date)u8 x,y;/xy坐标LCD_write_comm(0x34);/使用扩充指令集LCD_delay();for(y=0;y32;y+)LCD_write_comm(0x80+y);/y坐标起始地址LCD_delay();LCD_write_comm(0x80);/x坐标起始地址LCD_delay();for(x=0;x8;x+)/写上半屏幕LCD_write_date(date16*y+x*2);LCD_delay();LCD_write_date(date16*y+x*2+1);LCD_delay();for(x=0;x8;x+)/写下半屏幕LCD_write_date(date16*(y+32)+x*2);LCD_delay();LCD_write_date(date16*(y+32)+x*2+1);LCD_delay();LCD_write_comm(0x36);/显示RAMLCD_delay();LCD_write_comm(0x30);/退出扩展指令集LCD_delay();4、 程序执行效果
展开阅读全文