1、LCM12864ZS系列液晶模块使用手册及例程LCM12864系列液晶模块使用手册特点:1.SPI串行接口2.自带12*12和16*16点阵一、二级汉字库3.自带6*10、8*16、12*24、16*32点阵英文点阵字库4.内置基本绘图指令,绘制直线、圆框、实芯圆、矩形框、实芯矩形、棒状条、点,只需要输入起始、终点坐标等参数即可完成绘图功能5.任意位置填充图片功能6.指令控制背光的开和关7.任意位置字符反白功能8.供电电压:3.3V9.功耗:不开背光3mA,开背光10mA引脚接口序号引脚功能序号引脚功能13.3V电源正6RST模块复位2SS从机选择7BS模块忙检测3SDA串行数据输入8NC未用
2、4TS未用9NC未用5SCK串行时钟10GND电源负控制信号时序图上电后,首先将RST线拉低5ms,然后才能对模块进行操作。控制指令表指令功能函 数说 明0x01绘制一个点void point(unsigned char x,unsigned char y)在x,y坐标绘制一个点,颜色由设置绘图色指令决定0x02绘制一条直线void line(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2)X1,y1:直线的起点坐标,x2,y2直线的终点坐标,颜色由设置绘图色指令决定0x03绘制一个矩形框void rect
3、angle(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2)x1,y1:左上角点坐标x2,y2,右下角点坐标, 颜色由设置绘图色指令决定0x04绘制一个实心矩形void SolidRectangle(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2)x1,y1:左上角点坐标x2,y2,右下角点坐标, 颜色由设置绘图色指令决定0x05绘制一个圆void circular(unsigned char x0,unsigned c
4、har y0,unsigned char r)x0,y0:圆心坐标r:圆半径,颜色由设置绘图色指令决定0x06绘制一个实心圆void SolidCircular(unsigned char x0,unsigned char y0,unsigned char r)x0,y0:圆心坐标r:圆半径,颜色由设置绘图色指令决定0x07显示ASCII字符void PutChar(unsigned char x,unsigned char y,unsigned char ASCII)x,y:字符左上角坐标c:ASCII码,031无效0x08显示汉字void PutHZ(unsigned char x,uns
5、igned char y, unsigned char _flash *pHZ)x,y:字符左上角坐标*pHZ:待显示的字符串指针0x09在指定位置填充图片void fill_bmp(unsigned char x,unsigned char y, unsigned char pixel_x,unsigned char pixel_y,unsigned char _flash *pb)图片取模方式:从上向下,低位在上,从左往右x:图片左上角横向坐标y:图片左上角纵向坐标pixel_x:图片横向点数pixel_y:图片纵向点数*pb:图片地址0x0a背光控制void BackLight(unsi
6、gned char s)S=1:开S=0:关0x0b绘制一条棒状条void bar(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned char w)x1,y1:起点坐标x2,y2:终点坐标w:宽度0x80清屏void clear(unsigned char xx)xx:可为任意数,但必需有0x81ASCII字符设置void FontASCII(unsigned char data)Data取值:b7b4:字符大小选择 0000-8*16字体 0001-6*10字体 0002-12*24字体
7、0003-16*32字体b3b0:字符颜色选择 0000-白色 0001-黑色0x82汉字设置void FontHZ(unsigned char data)Data取值:b7b4:字符大小选择 0000-16*16字体 0001-12*12字体b3b0:字符颜色选择 0000-白色 0001-黑色0x83设置绘图颜色void PaintColor(unsigned char color)color:为0时以白色进行绘制 非0时以黑色进行绘制LCM12864-05液晶屏外形尺寸:40*40mm短接箭头所指电阻,接通电源,进入模块测试功能,正常时会显示不同点阵的字符 LCM12864-05将箭头所
8、指的晶振的一个脚对地短接,再接通电源,进入模块测试功能,正常时会显示不同点阵的字符/液晶模块测试程序/MCU:ATmega128/晶振:11.0592/编译器:IARAVR 5.3#include #define testbit(var, bit) (var)&(1(bit) /测试位#define setbit(var, bit) (var)|=(1(bit) /位置#define clrbit(var, bit) (var)&=(1(bit) /位清#define LCD_BUSY 5#define LCD_BUSY_PORT PORTA#define LCD_BUSY_DDR DDRA#
9、define LCD_BUSY_PIN PINA#define LCD_RST 6#define LCD_RST_PORT PORTA#define LCD_RST_DDR DDRA#define LCD_RST_PIN PINA#define LCD_SS 0#define LCD_SS_PORT PORTB#define LCD_SS_DDR DDRB#define LCD_SS_PIN PINB#define SPI_MODE3() setbit(SPCR,CPOL);setbit(SPCR,CPHA)#define SPI_MODE0() clrbit(SPCR,CPOL);clrbi
10、t(SPCR,CPHA)#define EN_LCD() Delayus(10);clrbit(LCD_SS_PORT,LCD_SS);SPI_MODE3();setbit(SPCR,SPR0);setbit(SPCR,SPR1)#define DS_LCD() Delayus(10);setbit(LCD_SS_PORT,LCD_SS);SPI_MODE0();clrbit(SPCR,SPR0);clrbit(SPCR,SPR1)#define CS_DDR DDRB#define CS_PORT PORTB#define CS_BIT 0#define SCK_DDR DDRB#defin
11、e SCK_PORT PORTB#define SCK_BIT 1#define MOSI_DDR DDRB#define MOSI_PORT PORTB#define MOSI_BIT 2#define MISO_DDR DDRB#define MISO_PORT PORTB#define MISO_BIT 3void clear(unsigned char xx);void LcdOn(unsigned char data);void FontASCII(unsigned char data);void SPI_Low(void) /低速模式 setbit(SPCR,SPE); /SPI
12、使能 setbit(SPCR,MSTR); /SPI 主机 setbit(SPCR,SPR1); /SCK=fosc/128 setbit(SPCR,SPR0); clrbit(SPSR,SPI2X); /setbit(SPCR,CPOL); /模式2,空闲时高电平/* spi high speed, not exceed 25MHz */void SPI_High(void) /高速模式 setbit(SPCR,SPE); setbit(SPCR,MSTR); setbit(SPSR,SPI2X); /SCK=fosc/2/ SPI interface initializervoid spi
13、Init(void) /setbit(CS_PORT,CS_BIT); setbit(SCK_PORT,SCK_BIT); setbit(MOSI_PORT,MOSI_BIT); setbit(MISO_PORT,MISO_BIT); /setbit(CS_DDR,CS_BIT); setbit(SCK_DDR,SCK_BIT); setbit(MOSI_DDR,MOSI_BIT); clrbit(MISO_DDR,MISO_BIT); SPI_Low(); /SPI_High();/-unsigned char spiWriteByte(unsigned char data) unsigne
14、d char i; SPDR = data; /* 启动数据传输 */ while(!testbit(SPSR,SPIF); /* 等待传输结束 */ i = SPSR; /*中断标志清零*/ setbit(SPCR,MSTR); /主机模式 return SPDR;void Delayms(unsigned char ms) unsigned int i,j; for(i=0;ims;i+) for(j=0;j8000;j+) ; void Delayus(unsigned char us) unsigned char i,j; for(i=0;ius;i+) for(j=0;j8;j+)
15、; /*LCD初始化*/void LcdInit(void) clrbit(LCD_BUSY_DDR,LCD_BUSY);/忙信号检测输入 setbit(LCD_BUSY_PORT,LCD_BUSY);/上拉开 setbit(LCD_RST_DDR,LCD_RST);/复位信号输出 setbit(LCD_RST_PORT,LCD_RST); setbit(LCD_SS_DDR,LCD_SS);/片选信号为输出 setbit(LCD_SS_PORT,LCD_SS); clrbit(LCD_RST_PORT,LCD_RST); Delayms(5); setbit(LCD_RST_PORT,LCD
16、_RST); Delayms(50); /clear(1); /LcdOn(1);/*清屏*xx:可为任意数,但必需有*/void clear(unsigned char xx) EN_LCD(); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(0x80); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(xx); while(testbit(LCD_BUSY_PIN,LCD_BUSY); DS_LCD();/*画点*x:横向坐标(x=0127)y:纵向坐标(y=063)*/void
17、point(unsigned char x,unsigned char y) EN_LCD(); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(0x01); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(x); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(y); while(testbit(LCD_BUSY_PIN,LCD_BUSY); DS_LCD();/*画直线*x1,y1:起点坐标x2,y2:终点坐标*/void lin
18、e(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2) EN_LCD(); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(0x02); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(x1); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(y1); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByt
19、e(x2); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(y2); while(testbit(LCD_BUSY_PIN,LCD_BUSY); DS_LCD();/*画棒状条*x1,y1:起点坐标x2,y2:终点坐标w:宽度*/void bar(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned char w) EN_LCD(); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(0x
20、0b); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(x1); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(y1); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(x2); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(y2); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(w); while(testbit(LC
21、D_BUSY_PIN,LCD_BUSY); DS_LCD();/*背光控制*s=1,开s=0,关*/void BackLight(unsigned char s) EN_LCD(); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(0x0a); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(s); while(testbit(LCD_BUSY_PIN,LCD_BUSY); DS_LCD();/*画矩形框*x1,y1:左上角点坐标x2,y2,右下角点坐标*/void rectangle(
22、unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2) EN_LCD(); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(0x03); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(x1); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(y1); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(
23、x2); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(y2); while(testbit(LCD_BUSY_PIN,LCD_BUSY); DS_LCD();/*画实心矩形*x1,y1:左上角点坐标x2,y2,右下角点坐标*/void SolidRectangle(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2) EN_LCD(); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(0x04); w
24、hile(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(x1); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(y1); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(x2); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(y2); while(testbit(LCD_BUSY_PIN,LCD_BUSY); Delayus(100); DS_LCD();/*画圆框*x0,y0:圆心坐标
25、r:圆半径*/void circular(unsigned char x0,unsigned char y0,unsigned char r) EN_LCD(); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(0x05); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(x0); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(y0); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteBy
26、te(r); while(testbit(LCD_BUSY_PIN,LCD_BUSY); DS_LCD();/*画实心圆*x0,y0:圆心坐标r:圆半径*/void SolidCircular(unsigned char x0,unsigned char y0,unsigned char r) EN_LCD(); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(0x06); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(x0); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(y0); while(testbit(LCD_BUSY_PIN,LCD_BUSY); spiWriteByte(r); while(testbit(LCD_BUSY_PIN,LCD_BUSY); Delayus(100); DS_LCD();/*显示ASCII字符*x,y:字符左上角坐标c:ASC