lcd16824驱动程序文件

合集下载

基于AVR的液晶12864驱动程序

基于AVR的液晶12864驱动程序

#include <mega16.h>#define uchar unsigned char#define uint unsigned int#define nop() NOP()#define xtal 8#define Set_CS() DDRB |= (1<<0);PORTB |= (1<<0)#define Set_SID() DDRB |= (1<<1);PORTB |= (1<<1)#define Set_SCLK() DDRB |= (1<<2);PORTB |= (1<<2)#define Clr_CS() DDRB |= (1<<0);PORTB &=~(1<<0)#define Clr_SID() DDRB |= (1<<1);PORTB &=~(1<<1)#define Clr_SCLK() DDRB |= (1<<2);PORTB &=~(1<<2)void Delay(uint ms); //延时子程序void W_1byte(uchar RW, uchar RS, uchar W_data);void Write_8bits(uint W_bits);void LCD_Init(void);void LCD_INT(void);void LCD_disp (uchar *mynew1, uchar *mynew2,uchar *mynew3,uchar *mynew4);const uchar string1[]={"~~~~梦之队~~~~"};const uchar string2[]={"蹇司玉"};const uchar string3[]={" 王蕊"};const uchar string4[]={" 崔媛媛"};void LCD_INT(void){Clr_CS();Clr_SID();Clr_SCLK();LCD_Init();}void LCD_disp (uchar *mynew1, uchar *mynew2,uchar *mynew3,uchar *mynew4) {uchar i = 0;;W_1byte(0,0,0x80); //显示的地址0x80;for(i=0;mynew1[i]!='\0';i++){W_1byte(0,1,mynew1[i]);}W_1byte(0,0,0x90); //显示的地址0x90for(i=0;mynew2[i]!='\0';i++){W_1byte(0,1,mynew2[i]);}W_1byte(0,0,0x88); //显示的地址0x88for(i=0;mynew3[i]!='\0';i++){W_1byte(0,1,mynew3[i]);}W_1byte(0,0,0x98); //显示的地址0x98for(i=0;mynew4[i]!='\0';i++){W_1byte(0,1,mynew4[i]);};}void LCD_single_disp(uchar single_row, uchar single_line, uchar *single_data) {uchar j,a,i;switch(single_row){case 1:{a=0x80;break;}case 2:{a=0x90;break;}case 3:{a=0x88;break;}case 4:{a=0x98;break;}}for(j=single_line;j>=2;j--){a++;W_1byte(0,0,a); //显示的地址0x88for(i=0; single_data[i]!='\0';i++){W_1byte(0,1,single_data[i]);}}void main(void){LCD_INT();LCD_single_disp(2,1,string2);}/******************************************************************/ void LCD_Init(void){uchar cmd;cmd=0x30; //功能设置8位数据,基本指令W_1byte(0,0,cmd);Delay(2);cmd=0x0C; //显示状态ON,游标OFF,反白OFFW_1byte(0,0,cmd); //写指令Delay(2);cmd=0x01; //清除显示W_1byte(0,0,cmd); //写指令Delay(2);cmd=0x02; //地址归位W_1byte(0,0,cmd); //写指令Delay(2);cmd=0x80; //设置DDRAM地址W_1byte(0,0,cmd); //写指令Delay(2); //延时}/******************************************************************* 函数名:W_1byte入口参数:RW、RS、W_data出口参数:无建立日期:2007年3月3日修改日期:函数作用:写一个字节的数据到12864液晶,包括指令和数据说明:RW=1,从液晶读数据到MCU;RW=0,写一个数据到液晶;(一般RW都设为0,即只向液晶写数据,不读数据)RS=1,写入的是数据;RS=0,写入的是指令;一般模式:RW=0,RS=1;写数据RW=0,RS=0;写指令********************************************************************/ void W_1byte(uchar RW, uchar RS, uchar W_data){uint H_data,L_data,S_ID = 0xf8; //11111RWRS0if(RW == 0){S_ID &=~ 0x04;}else //if(RW==1){S_ID |= 0X04;}if(RS == 0){S_ID &=~ 0x02;}else //if(RS==1){S_ID |= 0X02;}H_data = W_data;H_data &= 0xf0; //屏蔽低4位的数据L_data = W_data; //xxxx0000格式L_data &= 0x0f; //屏蔽高4位的数据L_data <<= 4; //xxxx0000格式Set_CS();Write_8bits(S_ID); //发送S_IDWrite_8bits(H_data); //发送H_dataWrite_8bits(L_data); //发送L_data}/******************************************************************** 函数名:Write_8bits入口参数:W_bits出口参数:无建立日期:2007年3月3日修改日期:函数作用:负责串行输出8个bit位说明:********************************************************************/ void Write_8bits(uint W_bits){uint i,Temp_data;for(i=0; i<8; i++){Temp_data = W_bits;Temp_data <<= i;if((Temp_data&0x80)==0) //bit7 is zero{Clr_SID();;Set_SCLK();;;Clr_SCLK();;Clr_SID();}else //bit7 is one{Set_SID();;Set_SCLK();;;Clr_SCLK();;Clr_SID();}}}/******************************************************************** 函数名:Delay出口参数:无建立日期:2007年3月3日修改日期:函数作用:毫秒级的延时程序,当晶振为12Mhz时,xtal=12;说明:********************************************************************/void Delay(uint ms){uint i;while(ms--){for(i=1;i<(uint)(xtal*143-2);i++);}}//===================================================================*/。

lcd16824驱动程序

lcd16824驱动程序

#include <lm3sxxx.h>#define fuc_PERIPH SYSCTL_PERIPH_GPIOE#define fuc_PORT GPIO_PORTE_BASE#define rs_PIN GPIO_PIN_0#define rw_PIN GPIO_PIN_1#define en_PIN GPIO_PIN_2#define lcd_PERIPH SYSCTL_PERIPH_GPIOD#define lcd_PORT GPIO_PORTD_BASE#define lcd_PINS 0xff#define SysCtlPeriEnable SysCtlPeripheralEnable#define SysCtlPeriDisable SysCtlPeripheralDisable#define GPIOPinTypeIn GPIOPinTypeGPIOInput#define GPIOPinTypeOut GPIOPinTypeGPIOOutput#define GPIOPinTypeOD GPIOPinTypeGPIOOutputOD#define FIRST_ADDR 0 //定义字符/汉字显示起始位置unsigned char CGRAM[]={0x08,0x20,0x1c,0x10,0x1c,0x1c,0xff,0x9e,0x7f,0x1e,0x1c,0x1f,0x3e,0x1f,0x3e,0x1f, 0x77,0x1f,0x41,0x3f,0x00,0x7e,0x00,0xfe,0x83,0xfc,0x7f,0xf8,0x3f,0xf0,0x0f,0xc0, };unsigned char BMP1[];unsigned char BMP2[];unsigned char BMP3[];unsigned char BMP4[];unsigned char BMP5[];unsigned char BMP6[];unsigned char BMP7[];unsigned char BMP8[];unsigned char Num[]={'0','1','2','3','4','5','6','7','8','9','.'};void delay (int m){int n;for(n=0;n<=m;n++);}void check(void) //判断是否忙碌{delay(500);}void write_com(unsigned char com) //写显示命令{GPIOPinWrite(lcd_PORT , lcd_PINS, com); //P0=com;GPIOPinWrite(fuc_PORT , rs_PIN, 0X00); // rs=0;GPIOPinWrite(fuc_PORT , rw_PIN, 0X00); //rw=0GPIOPinWrite(fuc_PORT , en_PIN, 0Xff); // lcden=0;check();GPIOPinWrite(fuc_PORT , en_PIN, 0X00); //lcden=1;GPIOPinWrite(lcd_PORT , lcd_PINS, 0xff); //P0=com;}void write_data(unsigned char date) //写显示数据{GPIOPinWrite(lcd_PORT , lcd_PINS, date); //P0=com;GPIOPinWrite(fuc_PORT , rs_PIN, 0Xff); // rs=0;GPIOPinWrite(fuc_PORT , rw_PIN, 0X00); //rw=0GPIOPinWrite(fuc_PORT , en_PIN, 0xff); // lcden=0;check();GPIOPinWrite(fuc_PORT , en_PIN, 0X00); //lcden=1;GPIOPinWrite(lcd_PORT , lcd_PINS, 0xff); //P0=com;}void LCD_INIT(void) //初始化LCD{SysCtlPeriEnable(lcd_PERIPH); // 使能LcD所在的GPIO 端口GPIOPinTypeOut(lcd_PORT,lcd_PINS);SysCtlPeriEnable(fuc_PERIPH); // 使能LcD功能端口所在的GPIO 端口GPIOPinTypeOut(fuc_PORT,rs_PIN|en_PIN|rw_PIN );GPIOPinWrite(fuc_PORT , en_PIN, 0Xff); //lcden=1;write_com(0x01); //清除屏幕显示,将DDRAM的地址计数器清零delay(5);write_com(0x30); //清除屏幕显示,将DDRAM的地址计数器清零delay(5);write_com(0x30); //8BIT控制界面,基本指令集delay(5);write_com(0X0C);delay(5);write_com(0x01); // /清除屏幕显示,将DDRAM的地址计数器清零delay(5);write_com(0x06); //DDRAM的地址计数器(AC)加1delay(5);}//********************************************************************// 名称: DisStr16()// 功能: 12864显示16*16字符串函数// 输入: hang显示的行数,lie显示的列数,*p显示的内容// 输出: 无//*********************************************************************** void zhifuchuan16(unsigned char hang,unsigned char lie,char *p){unsigned char a=0,i=0;if(lie>8) lie=1;switch(hang){case 1: a=0x80;break;case 2: a=0x90;break;case 3: a=0x88;break;case 4: a=0x98;break;}a=a+lie-1;delay(5);write_com(a);delay(5);while(1){if((i/2+lie)>8) break;if(*p=='\0') break;write_data(*p);p++;i++;}GPIOPinWrite(lcd_PORT , lcd_PINS, 0xff);//IO1PIN=IO1PIN&0xff00ffff|0x00010000;}//********************************************************************//* 名称: DisStr8()//* 功能: 12864显示8*16字符串函数//* 输入: hang显示的行数,lie显示的列数,*p显示的内容//* 输出: 无//***********************************************************************/void zhifuchuan8(unsigned char hang,unsigned char lie,char *p){unsigned char a,i=0;if(lie<1) lie=1;if(lie>16) lie=16;lie=lie-1;if(hang==1) a=0x80;if(hang==2) a=0x90;if(hang==3) a=0x88;if(hang==4) a=0x98;a=a+lie/2;write_com(a);if(lie%2==1) write_data(0x20);while(1){if((i+lie)>15) break;if(*p=='\0') break;write_data(*p);p++;i++;}//IO1PIN=IO1PIN&0xff00ffff|0x00010000;}/********************************************************************* 名称: DisChar()* 功能: 显示单个数字字符函数* 输入: hang显示的行数,lie显示的列数,sign显示的内容* 输出: 无***********************************************************************/void DisChar(unsigned char hang,unsigned char lie,unsigned int sign){unsigned char a;if(lie<1) lie=1;if(lie>16) lie=16;lie=lie-1;if(hang==1) a=0x80;if(hang==2) a=0x90;if(hang==3) a=0x88;if(hang==4) a=0x98;a=a+lie/2;write_com(a);if(lie%2==1) write_data(0x20);write_data(sign+0x30);//IO1PIN=IO1PIN&0xff00ffff|0x00010000;}/* 名称: DisNum()* 功能: 显示单个数字字符函数* 输入: hang显示的行数,lie显示的列数,sign显示的内容* 输出: 无***********************************************************************/void DisNum(unsigned char hang,unsigned char lie,unsigned int num1,unsigned int num2) {unsigned char a;if(lie<1) lie=1;if(lie>16) lie=16;lie=lie-1;if(hang==1) a=0x80;if(hang==2) a=0x90;if(hang==3) a=0x88;if(hang==4) a=0x98;a=a+lie/2;write_com(a);if(lie%2==1) write_data(0x20);write_data(num1+0x30);write_data(num2+0x30);//IO1PIN=IO1PIN&0xff00ffff|0x00010000;}/********************************************************************* 名称: DisImg(uint xs,uint ys,uint xe,uint ye,uchar *img)* 功能: 显示图片xs为图片显示的起始横坐标,xs=1-16xe为图片显示的结束横坐标,xe=2-17宽单位为8个像素点,图片大小必须为的宽必须为8的倍数,且小于128,如宽为16时,xe-xs=2 即宽度为2*8=16个像素点ys为图片显示的起始纵坐标,ys=1-64ye为图片显示的结束纵坐标,ye=2-65高单位为1个像素,图片高小于64,如高为19,ye-ys=19 即高度为19个像素点* 输入: 无* 输出: 无***********************************************************************/void DisImg(unsigned int xs,unsigned int ys,unsigned int xe,unsigned int ye,unsigned char *img) {unsigned int j=0;unsigned char x,y,xxs,xxe,i=0,k=0;xs-=1;ys-=1;xe-=1;ye-=1;xxs=xs/2;xxe=xe/2;for(y=ys;y<=ye;y++){for(x=xxs;x<xxe;x++){if(y>=32) i=8,k=32;write_com(0x36); //8位数据总线,扩展指令集,绘图显示开write_com(y+0x80-k); //行地址write_com(x+0x80+i); //列地址write_com(0x30);if(xs%2==1) write_data(0x00);write_data(img[j++]);write_data(img[j++]);}}}/********************************************************************* 名称: CLR()* 功能: 清屏* 输入: 无* 输出: 无***********************************************************************/ void CLR(){write_com(0x01);delay(1);}/********************************************************************/********************************************************************* 名称: CLRGDRAM()* 功能: 清整个GDRAM空间* 输入: 无* 输出: 无***********************************************************************/void CLRGDRAM(){unsigned char x,y,i;CLR();zhifuchuan16(1,1," ");for(i=0;i<9;i+=8) //0时上半屏,8时下半屏for(y=0;y<32;y++) //列地址(0~32)(0~32)for(x=0;x<8;x++) //行地址(0~7) (8~15){write_com(0x36); //8位数据总线,扩展指令集,绘图显示开write_com(y+0x80); //行地址write_com(x+0x80+i); //列地址write_com(0x30);write_data(0x00);write_data(0x00);}CLR();}//***********************************闪烁******************************************************//// void shanshuo ()//{// write_com(0x02);// write_com(0x0e);void LCD_set_xy( unsigned char hang, unsigned char lie ){unsigned char a=0,i=0;if(lie>8) lie=1;switch(hang){case 1: a=0x80;break;case 2: a=0x90;break;case 3: a=0x88;break;case 4: a=0x98;break;}a=a+lie-1;delay(5);write_com(a);}void LCD_falsh(unsigned char hang,unsigned char lie,unsigned char falsh){LCD_set_xy( hang, lie );if(falsh)write_com(0x0e);}//**************************************************************************** //*火影图片*///*-- 宽度x高度=128x64 --*/unsigned char BMP2[]={0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF F,0XFC,0X00,0X00,0X03,0XFF,0XFF,0XF1,0X33,0X3F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFE,0X3 F,0XFC,0X00,0X00,0X40,0X3E,0XFC,0X00,0X10,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFE,0X 7F,0XFC,0X00,0X00,0X40,0X38,0X00,0X00,0X01,0XC3,0XFF,0XFF,0XFF,0XF8,0X00,0XFF,0X7 F,0XFC,0X00,0X00,0XC0,0X50,0X27,0XFE,0X00,0X07,0XFF,0XFF,0XC0,0X00,0X00,0X7F,0X 3F,0XFC,0X00,0X00,0XC0,0X11,0XFF,0XFE,0X00,0X0F,0XFF,0X00,0X00,0X00,0X00,0X2F,0X3 F,0XFC,0X00,0X00,0XC0,0X00,0XF7,0XFE,0X00,0X1F,0XF8,0X03,0XFF,0XFF,0XF8,0X23,0X BF,0XFC,0X00,0X01,0XC0,0X00,0XF7,0XFE,0X80,0X3F,0XF0,0XFF,0XFF,0XFF,0XF4,0X11,0X BF,0XFC,0X00,0X01,0XC0,0X01,0XFF,0XFE,0X01,0X3F,0X61,0X7F,0XFF,0XCF,0XFC,0X00,0X FF,0XFC,0X00,0X01,0XC0,0X00,0XF9,0XFE,0X00,0XEE,0X23,0X3F,0XF8,0X1F,0XFC,0X00,0X 3F,0XFC,0X00,0X01,0XD0,0X00,0XFF,0X80,0XE4,0X0C,0X03,0X3F,0XF7,0XFF,0XFC,0X00,0X 3F,0XFC,0X00,0X01,0XC0,0X00,0X00,0X00,0XF5,0X0A,0X03,0X3F,0XEC,0X3F,0XF8,0X00,0X 3F,0XFC,0X00,0X01,0X80,0X02,0X01,0X03,0X79,0X16,0X02,0X3F,0XE9,0X3F,0XF8,0X00,0X3 F,0XFC,0X00,0X00,0X00,0X03,0X07,0X66,0XFB,0X14,0X02,0X7F,0XCB,0X5F,0XFC,0X00,0X 3F,0XFC,0X00,0X00,0X00,0X03,0X87,0XFF,0XFF,0X20,0X02,0X7F,0XCC,0X5F,0XFC,0X00,0X 3F,0XFC,0X00,0X00,0X00,0X03,0XDF,0XFF,0XF0,0X00,0X03,0X7F,0XA7,0X9F,0XFC,0X00,0X 3F,0XFC,0X00,0X00,0X00,0X01,0XFF,0XFF,0XF0,0X00,0X03,0X7F,0XA0,0X3F,0XF0,0X00,0X3 F,0XFC,0X00,0X00,0X00,0X01,0XFF,0XFF,0XD0,0X40,0X01,0X7F,0XFD,0XFF,0XF4,0X01,0X BF,0XFC,0X00,0X00,0X00,0X01,0XFF,0XFF,0XF0,0X00,0X01,0X7F,0XFF,0XFD,0XF8,0X01,0X3 F,0XFC,0X00,0X00,0X00,0X00,0XFF,0XFF,0XC0,0X00,0X00,0X7F,0XFF,0XF0,0X00,0X02,0X3 F,0XFC,0X00,0X00,0X00,0X00,0XF9,0X7F,0XE0,0X03,0X00,0X00,0X00,0X00,0X00,0X0C,0XB F,0XFC,0X00,0X00,0X00,0X00,0X7D,0XFF,0X80,0X01,0X80,0X00,0X00,0X00,0X0F,0XE8,0X3 F,0XFC,0X00,0X00,0X00,0X00,0X7F,0XFF,0X00,0X00,0XA8,0X00,0X00,0X02,0X03,0XE1,0XB F,0XFC,0X00,0X00,0X00,0X00,0X3E,0X30,0X00,0X03,0X4F,0X81,0XFF,0XFC,0X01,0XE1,0X BF,0XFC,0X00,0X00,0X00,0X00,0X0F,0XE0,0X00,0X03,0X0F,0X00,0XFF,0XC4,0X45,0XE1,0X BF,0XFC,0X00,0X00,0X00,0X00,0X1F,0X00,0X00,0X03,0X1F,0X40,0X47,0XEC,0X0F,0XE9,0XB F,0XFC,0X00,0X00,0X00,0X00,0X30,0X00,0X00,0X03,0X0F,0X40,0X6F,0XFE,0X0F,0XF9,0XB F,0XFC,0X00,0X00,0X00,0X00,0X20,0X00,0X00,0X03,0X0F,0XC3,0XFF,0XFF,0X0F,0XF3,0X3 F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X3F,0XE0,0XFF,0XFF,0XDF,0XE3,0X3 F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1F,0XFB,0XFF,0XFF,0XFF,0XE6,0X3 F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X8F,0XFF,0XFF,0XFF,0XFF,0XCC,0X3 F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XC7,0XFF,0XFF,0XFF,0XFF,0XCC,0X 3F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X77,0XFF,0XFF,0XFF,0XFF,0XDC,0X3 F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X37,0XFF,0XFF,0XFF,0XFF,0X18,0X3 F,0XFC,0X00,0X00,0X00,0X02,0X00,0X00,0X00,0X00,0X33,0XFF,0XFF,0XFF,0XFF,0XB8,0X3 F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X13,0XFF,0XFF,0XFF,0XFF,0XFE,0X3 F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X07,0XFF,0XFF,0XFF,0XFF,0XFF,0X3 F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1D,0XFF,0XFF,0XFF,0XFF,0X3F,0XB F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1F,0XFF,0XFD,0X3F,0XFF,0X7F,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X3C,0XFF,0XFC,0X3F,0XFF,0X7F,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XFC,0XFF,0XFE,0X7F,0XFE,0X7F,0X FF,共享知识分享快乐0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XF8,0X7F,0XFF,0XFF,0XFC,0X4F,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0XF8,0X3F,0XFF,0XFF,0XF8,0X4F,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF8,0X1F,0XFF,0XFF,0XF9,0X07,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF0,0X0F,0XFF,0XFF,0XE7,0X07,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF8,0X07,0XFF,0XFF,0XC3,0X07,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF8,0X63,0XFF,0XFF,0X81,0X0F,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFC,0X50,0XFF,0XFE,0X00,0X0F,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFC,0X40,0X3F,0XFC,0X00,0X1F,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFC,0X41,0X0F,0XF0,0X00,0X3F,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFE,0X01,0XC0,0X00,0X38,0X7F,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0X27,0XF0,0X00,0X7C,0XFF,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XA7,0XFC,0X00,0XFF,0XFF,0X FF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XE7,0XFF,0XFE,0XFF,0XFF,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XF7,0XFF,0XFD,0XFF,0XFF,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XFF,0XFF,0XFC,0XFF,0XFF,0XF F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XFF,0XFE,0X3F,0X7F,0XFF,0XF F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF F,};卑微如蝼蚁、坚强似大象。

LCD12864驱动程序(带字库的)

LCD12864驱动程序(带字库的)
/*void delayuS(uchar buf)
{
while(buf--);
}*/
/***********忙检测********************/
void Busy()
{
DataPort=0xFF;
RS=0;
RW=1;
while (1)
{
E =1;
if (P0^7==0) break;
}
E=0;
}
void main(void)
{
TMOD=0x01; ///选择定时器模式
TR0=1; //开中断,并允许T0中断
ET0=1;
EA=1; //总开关
Init_LCቤተ መጻሕፍቲ ባይዱ();
Clear_LCD();
while(1);
}
void t0(void) interrupt 1 using 0
{
//delay(100);
/*void Line_Num(uchar k)
{
//uint l;
if(k>=128&&k<=135)l=1;
if(k>135&&k<=143) l=3;
if(k>143&&k<=151) l=2;
if(k>151&&k<=159) l=4;
}*/
/*******************逐行显示***************************************/
void Write_Data(uchar Data)
{
Busy();
RS=1;
RW=0;

24402410LCD显示屏驱动程序

24402410LCD显示屏驱动程序

24402410LCD显示屏驱动程序u-boot早就支持framebuffer了,不光显示图片,还可以把控制台重定向到lcd上,只是24x0部分缺代码罢了,需要填充一个结构体,可以从openmoko那里copy过来。

不过如果只是为了显示一张图片的话……初始化lcd控制器的代码随便放哪里运行都可以的吧!2440&2410 LCD显示屏驱动程序#include "config.h"// GPB1/TOUT1 for Backlight control(PWM)#define GPB1_TO_OUT() (rGPBUP &= 0xfffd, rGPBCON &= 0xfffffff3, rGPBCON |= 0x00000004)#define GPB1_TO_1() (rGPBDAT |= 0x0002)#define GPB1_TO_0() (rGPBDAT &= 0xfffd)//extern void Uart_Printf(char *f, ...) ;extern unsigned char __CHS[];extern unsigned char __VGA[];//volatile staticunsigned short LCD_BUFFER[SCR_YSIZE_TFT][SCR_XSIZE_TFT];static void Lcd_PowerEnable(int invpwren,int pwren);static void Lcd_Init(void){rGPCUP = 0x00000000;rGPCCON = 0xaaaa02a9;// rGPDUP=0xffffffff; // Disable Pull-up registerrGPDUP = 0x00000000;rGPDCON=0xaaaaaaaa; //Initialize VD[15:8]rLCDCON1=(CLKVAL_TFT << 8)|(MVAL_USED << 7)|(3 <<5 )|(12 << 1)|0;// TFT LCD panel,16bpp TFT,ENVID=offrLCDCON2=(VBPD << 24)|(LINEVAL_TFT << 14)|(VFPD << 6)|(VSPW); rLCDCON3=(HBPD << 19)|(HOZVAL_TFT << 8)|(HFPD);rLCDCON4=(MVAL << 8)|(HSPW);#if(LCD_TYPE == PT035)rLCDCON5 = (1 << 11) | (1 << 10) | (0 << 9) | (0 << 8) | (1 << 7) | (1 << 6)| (1 << 3) |(BSWP << 1) | (HWSWP);#elif(LCD_TYPE == WD_F3224)rLCDCON5 = (1 << 11) | (1 << 10) | (0 << 9) | (0 << 8) | (0 << 7) | (0 << 6)| (1 << 3) |(0 << 1) | (HWSWP);#elif(LCD_TYPE == TX11D)rLCDCON5 = (1 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (0 << 7) | (0<< 6)| (1 << 3) | (1 << 2) | (BSWP << 1) | (HWSWP);#endifrLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)|M5D((U32)L CD_BUFFER>>1);rLCDSADDR2=M5D( ((U32)LCD_BUFFER+(SCR_XSIZE_TFT * LCD_YSIZE_TFT * 2)) >> 1 );rLCDSADDR3=(((SCR_XSIZE_TFT - LCD_XSIZE_TFT) / 1) << 11)|(LCD_XSIZE_TFT / 1);rLCDINTMSK|=(3); // MASK LCD Sub InterruptrTCONSEL &= (~7) ; // Disable LPC3480rTPAL=0; // Disable Temp Palette}static void Lcd_EnvidOnOff(int onoff){if(onoff == 1)rLCDCON1 |= 1; // ENVID=ONelserLCDCON1 = rLCDCON1 & 0x3fffe; // ENVID Off}static void Lcd_PowerEnable(int invpwren,int pwren){//GPG4 is setted as LCD_PWRENrGPGUP = rGPGUP & ( ~(1 << 4)) |(1 << 4); // Pull-up disable rGPGCON = rGPGCON & ( ~(3 << 8)) |(3 << 8); //GPG4=LCD_PWREN rGPGDAT = rGPGDAT | (1 << 4) ;// invpwren=pwren;//Enable LCD POWER ENABLE FunctionrLCDCON5 = rLCDCON5 & ( ~(1 << 3)) |(pwren << 3); // PWRENrLCDCON5 = rLCDCON5 & ( ~(1 << 5)) |(invpwren << 5); // INVPWREN}static void Lcd_MoveViewPort(int vx, int vy){U32 addr;SET_IF();#if (LCD_XSIZE_TFT < 32)while((rLCDCON1 >> 18) <= 1); // if x<32#elsewhile((rLCDCON1 >> 18) == 0); // if x>32#endifaddr = (U32)LCD_BUFFER + (vx * 2) + vy * (SCR_XSIZE_TFT * 2);rLCDSADDR1 = ( (addr >> 22) << 21 ) | M5D(addr >> 1);rLCDSADDR2 = M5D(((addr + (SCR_XSIZE_TFT * LCD_YSIZE_TFT * 2)) >> 1)); CLR_IF();}static void MoveViewPort(void){int vx=0,vy=0,vd=1;Uart_Printf("\n*Move the LCD view windos:\n");Uart_Printf(" press 8 is up\n");Uart_Printf(" press 2 is down\n");Uart_Printf(" press 4 is left\n");Uart_Printf(" press 6 is right\n");Uart_Printf(" press Enter to exit!\n");while(1){switch( Uart_GetKey() ){case '8':if(vy>=vd)vy-=vd;Uart_Printf("vx==,vy==\n",vx,vy);Lcd_MoveViewPort(vx,vy);break;case '4':if(vx>=vd)vx-=vd;Uart_Printf("vx==,vy==\n",vx,vy);Lcd_MoveViewPort(vx,vy);break;case '6':if(vx<=(SCR_XSIZE_TFT - LCD_XSIZE_TFT -vd))vx += vd;Uart_Printf("vx==,vy==\n",vx,vy);Lcd_MoveViewPort(vx,vy);break;case '2':if(vy<=(SCR_YSIZE_TFT - LCD_YSIZE_TFT -vd))vy += vd;Uart_Printf("vx==,vy==\n",vx,vy);Lcd_MoveViewPort(vx,vy);break;case '\r':return;default:break;}//Uart_Printf("vx==,vy==\n",vx,vy);//Lcd_MoveViewPort(vx,vy);}}void PutPixel(U32 x,U32 y, U16 c ){if ( (x < SCR_XSIZE_TFT) && (y < SCR_YSIZE_TFT) ) LCD_BUFFER[(y)][(x)] = c;}void GUI_Point(U32 x,U32 y, U16 c ){if ( (x < SCR_XSIZE_TFT) && (y < SCR_YSIZE_TFT) ) LCD_BUFFER[(y)][(x)] = c;}void Lcd_ClearScr( U16 c){unsigned int x,y ;for( y = 0 ; y < SCR_YSIZE_TFT ; y++ ){for( x = 0 ; x < SCR_XSIZE_TFT ; x++ ){LCD_BUFFER[y][x] = c ;}}}void Glib_Line(int x1,int y1,int x2,int y2,int color) { int dx,dy,e;dx = x2 -x1;dy = y2 -y1;if(dx >= 0){if(dy >= 0) // dy>=0{if(dx>=dy) // 1/8 octant{e=dy-dx/2;while(x1<=x2){PutPixel(x1,y1,color); if(e>0){y1+=1;e-=dx;} x1+=1; e+=dy;}}else // 2/8 octant{e=dx-dy/2;while(y1<=y2){PutPixel(x1,y1,color); if(e>0){x1+=1;e-=dy;} y1+=1; e+=dx;}}}else // dy<0{dy=-dy; // dy=abs(dy)if(dx>=dy) // 8/8 octant {e=dy-dx/2;while(x1<=x2){PutPixel(x1,y1,color); if(e>0){y1-=1;e-=dx;} x1+=1; e+=dy;}}else // 7/8 octant{e=dx-dy/2;while(y1>=y2){PutPixel(x1,y1,color); if(e>0){x1+=1;e-=dy;} y1-=1; e+=dx;}}}else //dx<0{dx=-dx; //dx=abs(dx)if(dy >= 0) // dy>=0 {if(dx>=dy) // 4/8 octant {e=dy-dx/2;while(x1>=x2){PutPixel(x1,y1,color); if(e>0){y1+=1;e-=dx;} x1-=1; e+=dy;}}else // 3/8 octant{e=dx-dy/2;while(y1<=y2){PutPixel(x1,y1,color); if(e>0){x1-=1;e-=dy;} y1+=1; e+=dx;}}}else // dy<0{dy=-dy; // dy=abs(dy)if(dx>=dy) // 5/8 octant {e=dy-dx/2;while(x1>=x2){PutPixel(x1,y1,color); if(e>0){y1-=1;e-=dx;} x1-=1; e+=dy;}}else // 6/8 octante=dx-dy/2;while(y1>=y2){PutPixel(x1,y1,color);if(e>0){x1-=1;e-=dy;}y1-=1;e+=dx;}}}}}void Glib_Rectangle(int x1,int y1,int x2,int y2,int color){Glib_Line(x1,y1,x2,y1,color);Glib_Line(x2,y1,x2,y2,color);Glib_Line(x1,y2,x2,y2,color);Glib_Line(x1,y1,x1,y2,color);}void Glib_FilledRectangle(int x1,int y1,int x2,int y2,int color) { int i;for(i=y1;i<=y2;i++)Glib_Line(x1,i,x2,i,color);}void Paint_Bmp(int x0,int y0,int h,int l,unsigned char bmp[]) { int x,y;U32 c;int p = 0;for( y = y0 ; y < l ; y++ ){for( x = x0 ; x < h ; x++ ){c = bmp[p+1] | (bmp[p]<<8) ;if ( ( (x0+x) < SCR_XSIZE_TFT) && ( (y0+y) < SCR_YSIZE_TFT) ) LCD_BUFFER[y0+y][x0+x] = c ;p = p + 2 ;}}#if 1void Lcd_PutASCII(unsigned int x,unsigned int y,unsigned char ch,unsigned int c,unsigned int bk_c,unsigned int st) {unsigned short int i,j;unsigned char *pZK,mask,buf;pZK = &__VGA[ch*16];for( i = 0 ; i < 16 ; i++ ){mask = 0x80;buf = pZK[i];for( j = 0 ; j < 8 ; j++ ){if( buf & mask ){PutPixel(x+j,y+i,c);}else{if( !st ){PutPixel(x+j,y+i,bk_c);}}mask = mask >> 1;}}}void Lcd_PutHZ(unsigned int x,unsigned int y,unsigned short int QW,unsigned int c,unsigned int bk_c,unsigned int st) {unsigned short int i,j;unsigned char *pZK,mask,buf;pZK = &__CHS[ ( ( (QW >> 8) - 1 )*94 + (QW & 0x00FF)- 1 )*32 ]; for( i = 0 ; i < 16 ; i++ ){//左mask = 0x80;buf = pZK[i*2];for( j = 0 ; j < 8 ; j++ ){if( buf & mask ){PutPixel(x+j,y+i,c);}else{if( !st ){PutPixel(x+j,y+i,bk_c);}}mask = mask >> 1;}//右mask = 0x80;buf = pZK[i*2 + 1];for( j = 0 ; j < 8 ; j++ ){if( buf & mask ){PutPixel(x+j + 8,y+i,c);}else{if( !st ){PutPixel(x+j + 8,y+i,bk_c);}}mask = mask >> 1;}}}//----------------------void Lcd_printf(unsigned int x,unsigned int y,unsigned int c,unsigned int bk_c,unsigned int st,char *fmt,...){char __LCD_Printf_Buf[256];va_list ap;unsigned char *pStr = (unsigned char *)__LCD_Printf_Buf;unsigned int i = 0;va_start(ap,fmt);vsprintf(__LCD_Printf_Buf,fmt,ap);va_end(ap);while(*pStr != 0 ){switch(*pStr){case '\n' :{break;}default:{if( *pStr > 0xA0 & *(pStr+1) > 0xA0 ) //中文输出{Lcd_PutHZ( x , y , (*pStr - 0xA0)*0x0100 + *(pStr+1) - 0xA0 , c , bk_c , st);pStr++;i++;x += 16;}else //英文输出{Lcd_PutASCII( x , y , *pStr , c , bk_c , st );x += 8;}break;}}pStr++;i++;if( i > 256 ) break;}}#endifvoid Lcd_Display(void){Lcd_Init();Lcd_PowerEnable(0, 1);Lcd_EnvidOnOff(1);Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x00) ); #if((LCD_TYPE == PT035)||(LCD_TYPE == WD_F3224)) Paint_Bmp(0, 0, 320, 240, phone);#elif(LCD_TYPE == TX11D)Paint_Bmp(0, 0, 480, 272, LCD43_ucos);#endif}。

lcd16824驱动程序

lcd16824驱动程序

#include <lm3sxxx.h>#define fuc_PERIPH SYSCTL_PERIPH_GPIOE#define fuc_PORT GPIO_PORTE_BASE#define rs_PIN GPIO_PIN_0#define rw_PIN GPIO_PIN_1#define en_PIN GPIO_PIN_2#define lcd_PERIPH SYSCTL_PERIPH_GPIOD#define lcd_PORT GPIO_PORTD_BASE#define lcd_PINS 0xff#define SysCtlPeriEnable SysCtlPeripheralEnable#define SysCtlPeriDisable SysCtlPeripheralDisable#define GPIOPinTypeIn GPIOPinTypeGPIOInput#define GPIOPinTypeOut GPIOPinTypeGPIOOutput#define GPIOPinTypeOD GPIOPinTypeGPIOOutputOD#define FIRST_ADDR 0 //定义字符/汉字显示起始位置unsigned char CGRAM[]={0x08,0x20,0x1c,0x10,0x1c,0x1c,0xff,0x9e,0x7f,0x1e,0x1c,0x1f,0x3e,0x1f,0x3e, 0x1f,0x77,0x1f,0x41,0x3f,0x00,0x7e,0x00,0xfe,0x83,0xfc,0x7f,0xf8,0x3f,0xf0,0x0f, 0xc0,};unsigned char BMP1[];unsigned char BMP2[];unsigned char BMP3[];unsigned char BMP4[];unsigned char BMP5[];unsigned char BMP6[];unsigned char BMP7[];unsigned char BMP8[];unsigned char Num[]={'0','1','2','3','4','5','6','7','8','9','.'};void delay (int m){i nt n;f or(n=0;n<=m;n++);}void check(void) //判断是否忙碌{delay(500);}void write_com(unsigned char com) //写显示命令{GPIOPinWrite(lcd_PORT , lcd_PINS, com); //P0=com;GPIOPinWrite(fuc_PORT , rs_PIN, 0X00); // rs=0;GPIOPinWrite(fuc_PORT , rw_PIN, 0X00); //rw=0GPIOPinWrite(fuc_PORT , en_PIN, 0Xff); // lcden=0;check();GPIOPinWrite(fuc_PORT , en_PIN, 0X00); //lcden=1;GPIOPinWrite(lcd_PORT , lcd_PINS, 0xff); //P0=com;}void write_data(unsigned char date) //写显示数据{GPIOPinWrite(lcd_PORT , lcd_PINS, date); //P0=com;GPIOPinWrite(fuc_PORT , rs_PIN, 0Xff); // rs=0;GPIOPinWrite(fuc_PORT , rw_PIN, 0X00); //rw=0GPIOPinWrite(fuc_PORT , en_PIN, 0xff); // lcden=0;check();GPIOPinWrite(fuc_PORT , en_PIN, 0X00); //lcden=1;GPIOPinWrite(lcd_PORT , lcd_PINS, 0xff); //P0=com;}void LCD_INIT(void) //初始化LCD{S ysCtlPeriEnable(lcd_PERIPH); // 使能LcD所在的GPIO 端口GPIOPinTypeOut(lcd_PORT,lcd_PINS);S ysCtlPeriEnable(fuc_PERIPH); // 使能LcD功能端口所在的GPIO 端口 GPIOPinTypeOut(fuc_PORT,rs_PIN|en_PIN|rw_PIN );G PIOPinWrite(fuc_PORT , en_PIN, 0Xff); //lcden=1;w rite_com(0x01); //清除屏幕显示,将DDRAM的地址计数器清零d elay(5);write_com(0x30); //清除屏幕显示,将DDRAM的地址计数器清零d elay(5);w rite_com(0x30); //8BIT控制界面,基本指令集d elay(5);w rite_com(0X0C);d elay(5);w rite_com(0x01); // /清除屏幕显示,将DDRAM的地址计数器清零d elay(5);w rite_com(0x06); //DDRAM的地址计数器(AC)加1d elay(5);}//********************************************************************// 名称 : DisStr16()// 功能 : 12864显示16*16字符串函数// 输入 : hang显示的行数,lie显示的列数,*p显示的内容// 输出 : 无//*********************************************************************** void zhifuchuan16(unsigned char hang,unsigned char lie,char *p){unsigned char a=0,i=0;if(lie>8) lie=1;switch(hang){case 1: a=0x80;break;c ase 2: a=0x90;break;c ase 3: a=0x88;break;c ase 4: a=0x98;break;}a=a+lie-1;delay(5);write_com(a);delay(5);while(1){if((i/2+lie)>8) break;if(*p=='\0') break;write_data(*p);p++;i++;}GPIOPinWrite(lcd_PORT , lcd_PINS, 0xff);//IO1PIN=IO1PIN&0xff00ffff|0x00010000;}//********************************************************************//* 名称 : DisStr8()//* 功能 : 12864显示8*16字符串函数//* 输入 : hang显示的行数,lie显示的列数,*p显示的内容//* 输出 : 无//***********************************************************************/void zhifuchuan8(unsigned char hang,unsigned char lie,char *p){unsigned char a,i=0;if(lie<1) lie=1;if(lie>16) lie=16;lie=lie-1;if(hang==1) a=0x80;if(hang==2) a=0x90;if(hang==3) a=0x88;if(hang==4) a=0x98;a=a+lie/2;write_com(a);if(lie%2==1) write_data(0x20);while(1){if((i+lie)>15) break;if(*p=='\0') break;write_data(*p);p++;i++;}//IO1PIN=IO1PIN&0xff00ffff|0x00010000;}/********************************************************************* 名称 : DisChar()* 功能 : 显示单个数字字符函数* 输入 : hang显示的行数,lie显示的列数,sign显示的内容* 输出 : 无***********************************************************************/void DisChar(unsigned char hang,unsigned char lie,unsigned int sign){unsigned char a;if(lie<1) lie=1;if(lie>16) lie=16;lie=lie-1;if(hang==1) a=0x80;if(hang==2) a=0x90;if(hang==3) a=0x88;if(hang==4) a=0x98;a=a+lie/2;write_com(a);if(lie%2==1) write_data(0x20);write_data(sign+0x30);//IO1PIN=IO1PIN&0xff00ffff|0x00010000;}/* 名称 : DisNum()* 功能 : 显示单个数字字符函数* 输入 : hang显示的行数,lie显示的列数,sign显示的内容* 输出 : 无***********************************************************************/void DisNum(unsigned char hang,unsigned char lie,unsigned int num1,unsigned int num2){unsigned char a;if(lie<1) lie=1;if(lie>16) lie=16;lie=lie-1;if(hang==1) a=0x80;if(hang==2) a=0x90;if(hang==3) a=0x88;if(hang==4) a=0x98;a=a+lie/2;write_com(a);if(lie%2==1) write_data(0x20);write_data(num1+0x30);write_data(num2+0x30);//IO1PIN=IO1PIN&0xff00ffff|0x00010000;}/********************************************************************* 名称 : DisImg(uint xs,uint ys,uint xe,uint ye,uchar *img)* 功能 : 显示图片 xs为图片显示的起始横坐标,xs=1-16xe为图片显示的结束横坐标,xe=2-17宽单位为8个像素点,图片大小必须为的宽必须为8的倍数,且小于128,如宽为16时,xe-xs=2 即宽度为2*8=16个像素点ys为图片显示的起始纵坐标,ys=1-64ye为图片显示的结束纵坐标,ye=2-65高单位为1个像素,图片高小于64,如高为19,ye-ys=19 即高度为 19个像素点* 输入 : 无* 输出 : 无***********************************************************************/void DisImg(unsigned int xs,unsigned int ys,unsigned int xe,unsigned int ye,unsigned char *img){unsigned int j=0;unsigned char x,y,xxs,xxe,i=0,k=0;xs-=1;ys-=1;xe-=1;ye-=1;xxs=xs/2;xxe=xe/2;for(y=ys;y<=ye;y++){for(x=xxs;x<xxe;x++){if(y>=32) i=8,k=32;write_com(0x36); //8位数据总线,扩展指令集,绘图显示开 write_com(y+0x80-k); //行地址write_com(x+0x80+i); //列地址write_com(0x30);if(xs%2==1) write_data(0x00);write_data(img[j++]);write_data(img[j++]);}}}/********************************************************************* 名称 : CLR()* 功能 : 清屏* 输入 : 无* 输出 : 无***********************************************************************/ void CLR(){write_com(0x01);delay(1);}/********************************************************************/********************************************************************* 名称 : CLRGDRAM()* 功能 : 清整个GDRAM空间* 输入 : 无* 输出 : 无***********************************************************************/void CLRGDRAM(){unsigned char x,y,i;CLR();zhifuchuan16(1,1," ");for(i=0;i<9;i+=8) //0时上半屏,8时下半屏for(y=0;y<32;y++) //列地址(0~32) (0~32)for(x=0;x<8;x++) //行地址(0~7) (8~15){write_com(0x36); //8位数据总线,扩展指令集,绘图显示开 write_com(y+0x80); //行地址write_com(x+0x80+i); //列地址write_com(0x30);write_data(0x00);write_data(0x00);}CLR();}//***********************************闪烁******************************************************//// void shanshuo ()//{// write_com(0x02);// write_com(0x0e);void LCD_set_xy( unsigned char hang, unsigned char lie ){unsigned char a=0,i=0;if(lie>8) lie=1;switch(hang){case 1: a=0x80;break;c ase 2: a=0x90;break;c ase 3: a=0x88;break;c ase 4: a=0x98;break;}a=a+lie-1;delay(5);write_com(a);}void LCD_falsh(unsigned char hang,unsigned char lie,unsigned char falsh) {L CD_set_xy( hang, lie );i f(falsh)w rite_com(0x0e);}//************************************************************************* ***//*火影图片*///*-- 宽度x高度=128x64 --*/unsigned char BMP2[]={0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF, 0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF, 0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF, 0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF, 0XFF,0XFC,0X00,0X00,0X03,0XFF,0XFF,0XF1,0X33,0X3F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFE, 0X3F,0XFC,0X00,0X00,0X40,0X3E,0XFC,0X00,0X10,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFE, 0X7F,0XFC,0X00,0X00,0X40,0X38,0X00,0X00,0X01,0XC3,0XFF,0XFF,0XFF,0XF8,0X00,0XFF, 0X7F,0XFC,0X00,0X00,0XC0,0X50,0X27,0XFE,0X00,0X07,0XFF,0XFF,0XC0,0X00,0X00,0X7F, 0X3F,0XFC,0X00,0X00,0XC0,0X11,0XFF,0XFE,0X00,0X0F,0XFF,0X00,0X00,0X00,0X00,0X2F, 0X3F,0XFC,0X00,0X00,0XC0,0X00,0XF7,0XFE,0X00,0X1F,0XF8,0X03,0XFF,0XFF,0XF8,0X23, 0XBF,0XFC,0X00,0X01,0XC0,0X00,0XF7,0XFE,0X80,0X3F,0XF0,0XFF,0XFF,0XFF,0XF4,0X11, 0XBF,0XFC,0X00,0X01,0XC0,0X01,0XFF,0XFE,0X01,0X3F,0X61,0X7F,0XFF,0XCF,0XFC,0X00, 0XFF,0XFC,0X00,0X01,0XC0,0X00,0XF9,0XFE,0X00,0XEE,0X23,0X3F,0XF8,0X1F,0XFC,0X00, 0X3F,0XFC,0X00,0X01,0XD0,0X00,0XFF,0X80,0XE4,0X0C,0X03,0X3F,0XF7,0XFF,0XFC,0X00, 0X3F,0XFC,0X00,0X01,0XC0,0X00,0X00,0X00,0XF5,0X0A,0X03,0X3F,0XEC,0X3F,0XF8,0X00, 0X3F,0XFC,0X00,0X01,0X80,0X02,0X01,0X03,0X79,0X16,0X02,0X3F,0XE9,0X3F,0XF8,0X00, 0X3F,0XFC,0X00,0X00,0X00,0X03,0X07,0X66,0XFB,0X14,0X02,0X7F,0XCB,0X5F,0XFC,0X00, 0X3F,0XFC,0X00,0X00,0X00,0X03,0X87,0XFF,0XFF,0X20,0X02,0X7F,0XCC,0X5F,0XFC,0X00, 0X3F,0XFC,0X00,0X00,0X00,0X03,0XDF,0XFF,0XF0,0X00,0X03,0X7F,0XA7,0X9F,0XFC,0X00, 0X3F,0XFC,0X00,0X00,0X00,0X01,0XFF,0XFF,0XF0,0X00,0X03,0X7F,0XA0,0X3F,0XF0,0X00,0X3F,0XFC,0X00,0X00,0X00,0X01,0XFF,0XFF,0XD0,0X40,0X01,0X7F,0XFD,0XFF,0XF4,0X01, 0XBF,0XFC,0X00,0X00,0X00,0X01,0XFF,0XFF,0XF0,0X00,0X01,0X7F,0XFF,0XFD,0XF8,0X01, 0X3F,0XFC,0X00,0X00,0X00,0X00,0XFF,0XFF,0XC0,0X00,0X00,0X7F,0XFF,0XF0,0X00,0X02, 0X3F,0XFC,0X00,0X00,0X00,0X00,0XF9,0X7F,0XE0,0X03,0X00,0X00,0X00,0X00,0X00,0X0C, 0XBF,0XFC,0X00,0X00,0X00,0X00,0X7D,0XFF,0X80,0X01,0X80,0X00,0X00,0X00,0X0F,0XE8, 0X3F,0XFC,0X00,0X00,0X00,0X00,0X7F,0XFF,0X00,0X00,0XA8,0X00,0X00,0X02,0X03,0XE1, 0XBF,0XFC,0X00,0X00,0X00,0X00,0X3E,0X30,0X00,0X03,0X4F,0X81,0XFF,0XFC,0X01,0XE1, 0XBF,0XFC,0X00,0X00,0X00,0X00,0X0F,0XE0,0X00,0X03,0X0F,0X00,0XFF,0XC4,0X45,0XE1, 0XBF,0XFC,0X00,0X00,0X00,0X00,0X1F,0X00,0X00,0X03,0X1F,0X40,0X47,0XEC,0X0F,0XE9, 0XBF,0XFC,0X00,0X00,0X00,0X00,0X30,0X00,0X00,0X03,0X0F,0X40,0X6F,0XFE,0X0F,0XF9, 0XBF,0XFC,0X00,0X00,0X00,0X00,0X20,0X00,0X00,0X03,0X0F,0XC3,0XFF,0XFF,0X0F,0XF3, 0X3F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X3F,0XE0,0XFF,0XFF,0XDF,0XE3, 0X3F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1F,0XFB,0XFF,0XFF,0XFF,0XE6, 0X3F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X8F,0XFF,0XFF,0XFF,0XFF,0XCC, 0X3F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XC7,0XFF,0XFF,0XFF,0XFF,0XCC, 0X3F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X77,0XFF,0XFF,0XFF,0XFF,0XDC, 0X3F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X37,0XFF,0XFF,0XFF,0XFF,0X18, 0X3F,0XFC,0X00,0X00,0X00,0X02,0X00,0X00,0X00,0X00,0X33,0XFF,0XFF,0XFF,0XFF,0XB8, 0X3F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X13,0XFF,0XFF,0XFF,0XFF,0XFE, 0X3F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X07,0XFF,0XFF,0XFF,0XFF,0XFF, 0X3F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1D,0XFF,0XFF,0XFF,0XFF,0X3F, 0XBF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1F,0XFF,0XFD,0X3F,0XFF,0X7F,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X3C,0XFF,0XFC,0X3F,0XFF,0X7F, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XFC,0XFF,0XFE,0X7F,0XFE,0X7F, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XF8,0X7F,0XFF,0XFF,0XFC,0X4F, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0XF8,0X3F,0XFF,0XFF,0XF8,0X4F, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF8,0X1F,0XFF,0XFF,0XF9,0X07, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF0,0X0F,0XFF,0XFF,0XE7,0X07, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF8,0X07,0XFF,0XFF,0XC3,0X07, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF8,0X63,0XFF,0XFF,0X81,0X0F, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFC,0X50,0XFF,0XFE,0X00,0X0F, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFC,0X40,0X3F,0XFC,0X00,0X1F, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFC,0X41,0X0F,0XF0,0X00,0X3F, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFE,0X01,0XC0,0X00,0X38,0X7F, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0X27,0XF0,0X00,0X7C,0XFF, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XA7,0XFC,0X00,0XFF,0XFF, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XE7,0XFF,0XFE,0XFF,0XFF, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XF7,0XFF,0XFD,0XFF,0XFF, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XFF,0XFF,0XFC,0XFF,0XFF, 0XFF,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XFF,0XFE,0X3F,0X7F,0XFF, 0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF, 0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF, 0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF, 0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,};。

LCD12864 并口液晶驱动

LCD12864 并口液晶驱动

#include "LCD12864.h"/*原程序参考于网络,原作者不明,liangjin2807修改适用于MSP430单片机,驱动MGLS12864液晶屏,HD61202芯片*/typedef unsigned char uchar;typedef unsigned int uint;uchardigital[21][16]={{0x00,0xE0,0xF0,0x18,0x08,0x18,0xF0,0xE0,0x00,0x0F,0x1F,0x30,0x20,0x30,0x1F, 0x0F},/*"0",0*/{0x00,0x10,0x10,0xF8,0xF8,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x3F,0x20,0x20,0x00},/*"1",1*/ {0x00,0x70,0x78,0x08,0x08,0x88,0xF8,0x70,0x00,0x30,0x38,0x2C,0x26,0x23,0x31,0x30},/*"2",2* /{0x00,0x30,0x38,0x88,0x88,0xC8,0x78,0x30,0x00,0x18,0x38,0x20,0x20,0x31,0x1F,0x0E},/*"3",3* /{0x00,0x00,0xC0,0xE0,0x30,0xF8,0xF8,0x00,0x00,0x07,0x07,0x24,0x24,0x3F,0x3F,0x24},/*"4",4*/ {0x00,0xF8,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x19,0x39,0x21,0x20,0x31,0x1F,0x0E},/*"5",5*/ {0x00,0xE0,0xF0,0x98,0x88,0x98,0x18,0x00,0x00,0x0F,0x1F,0x31,0x20,0x31,0x1F,0x0E},/*"6",6*/ {0x00,0x38,0x38,0x08,0xC8,0xF8,0x38,0x08,0x00,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00},/*"7",7*/ {0x00,0x70,0xF8,0x88,0x08,0x88,0xF8,0x70,0x00,0x1C,0x3E,0x23,0x21,0x23,0x3E,0x1C},/*"8",8* /{0x00,0xE0,0xF0,0x18,0x08,0x18,0xF0,0xE0,0x00,0x00,0x31,0x33,0x22,0x33,0x1F,0x0F},/*"9",9*/ {0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20},/*"A",0* /{0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00},/*"B",1*/ {0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00},/*"C",2* /{0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00},/*"D",3*/ {0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00},/*"E",4*/ {0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00},/*"F",5*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00},/*".",6*/ {0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},/*":",7*/ {0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00},/*"/",8* /{0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00},/*"*",9*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01},/*"-",10 */};/*"*",12*//**************宏定义***************/#define DataDir P2DIR#define DataPort P2OUT#define Busy 0x80#define CtrlDir P6DIR#define CLR_RS P6OUT&=~BIT3; //RS = P6.3#define SET_RS P6OUT|=BIT3;#define CLR_RW P6OUT&=~BIT4; //RW = P6.4#define SET_RW P6OUT|=BIT4;#define CLR_EN P6OUT&=~BIT5; //EN = P6.5#define SET_EN P6OUT|=BIT5;#define CLR_CS1 P6OUT&=~BIT0; //RW = 6.0#define SET_CS1 P6OUT|=BIT0;#define CLR_CS2 P6OUT&=~BIT1; //EN = 6.1#define SET_CS2 P6OUT|=BIT1;/***********************************************函数名称:DispStr功能:让液晶从某个位置起连续显示一个字符串参数:x--位置的列坐标y--位置的行坐标ptr--指向字符串存放位置的指针返回值:无***********************************************/void DispStr(uchar x,uchar y,uchar *ptr){uchar *temp;uchar i;temp = ptr;//计算字符串有效字符的个数LocateXY( x, y );for (i=0;i<64;i++) //连续显示4个16*16字符{LcdWriteData( temp[i] );}}/***********************************************函数名称:DispDigital功能:让液晶从某个位置显示一个数字,上列数组寻址方式,不建议使用参数:x--位置的列坐标y--位置的行坐标返回值:无***********************************************/void DispDigetal(uchar x,uchar y,uchar n){uchar i;uchar x_1;if(x<64){LcdChoiceL();LocateXY( x, y );for (i=0;i<8;i++)LcdWriteData( digital[n][i] );LocateXY( x, y+1 );for (i=8;i<16;i++)LcdWriteData( digital[n][i] );}else{x_1=x-64;LcdChoiceR();LocateXY( x_1, y );for (i=0;i<8;i++)LcdWriteData( digital[n][i] );LocateXY( x_1, y+1 );for (i=8;i<16;i++)LcdWriteData( digital[n][i] );}}/*********************************************** 函数名称:DispHex功能:让液晶从某个位置显示四个十六进数字参数:x--位置的列坐标y--位置的行坐标ptr--指向字符串存放位置的指针返回值:无***********************************************/ void DispHex(uchar x,uchar y,uint temp){uchar n;n=temp/0x1000;DispDigetal(x,y,n);n=(temp/0x100)%0x10;DispDigetal(x+8,y,n);n=(temp/0x10)%0x10;DispDigetal(x+16,y,n);n=temp%0x10;DispDigetal(x+24,y,n);}/*******************************************函数名称:LocateXY功能:向液晶输入显示字符位置的坐标信息参数:x--位置的列坐标y--位置的行坐标返回值:无********************************************/ void LocateXY(uchar x,uchar y){uchar tempx;uchar tempy;tempx=x|0x40;tempy=y|0xb8;LcdWriteCommand(tempx,1);LcdWriteCommand(tempy,1);}/*******************************************函数名称:DispNChar功能:在某个位置显示一个字符12864参数:x--位置的列坐标y--位置的行坐标n--显示的字个数data--显示的字符数据返回值:无********************************************/void DispNChar(uchar x,uchar y,uchar n,uchar (*ptr)[64]) { uchar i;uchar x_1;for(i=0;i<(16*n);i++)//输入总共的字符数{if(x<64){LcdChoiceL();//指定左屏LocateXY( x, y );//定位地址LcdWriteData( *(*ptr+i) );LocateXY( x, y+1 );LcdWriteData( *(*(ptr+1)+i) );}else {if(x<128)//如果64<X<128,则选择右屏{x_1=x-64;LcdChoiceR();LocateXY( x_1, y );LcdWriteData( *(*ptr+i) );LocateXY( x_1, y+1 );LcdWriteData( *(*(ptr+1)+i) );}else {x=0;y+=2;if(y<8){LcdChoiceL();LocateXY( x, y );LcdWriteData( *(*ptr+i) );LocateXY( x, y+1 );LcdWriteData( *(*(ptr+1)+i) );}else{y=0;LcdChoiceL();LocateXY( x, y );LcdWriteData( *(*ptr+i) );LocateXY( x, y+1 );LcdWriteData( *(*(ptr+1)+i) );}}}x++;}}/******************************************* 函数名称:LcdChoiceL功能:对12864液晶模块左侧参数:无返回值:无********************************************/ void LcdChoiceL(void){SET_CS2;//片选命令,选择左侧CLR_CS1;}/*******************************************函数名称:LcdChoiceR功能:对12864液晶模块右侧参数:无返回值:无********************************************/void LcdChoiceR(void){SET_CS1;//片选命令,选择右侧CLR_CS2;}/*******************************************函数名称:LcdStop功能:对12864液晶模块禁止参数:无返回值:无********************************************/void LcdStop(void){SET_CS1;//片选命令,禁止SET_CS2;}/*******************************************函数名称:LcdReset功能:对12864液晶模块进行复位操作参数:无返回值:无********************************************/void LcdReset(void){CtrlDir |= 0x3B; //控制线端口设为输出状态DataDir = 0xFF; //数据端口设为输出状态LcdChoiceL();//选择右侧LcdWriteCommand(0x3f, 1); //设置显示屏数据开LcdWriteCommand(0xc0, 1);//设置显示屏0行为第一行//LcdWriteCommand(0x40, 1);//设置显示屏0列为第一列/*_NOP();_NOP();_NOP();*/Delay5ms();LcdChoiceR();//选择左侧LcdWriteCommand(0x3f, 1); //设置显示屏数据开LcdWriteCommand(0xc0, 1);//设置显示屏0行为第一行//LcdWriteCommand(0x40, 1);//设置显示屏0列为第一列//显示模式设置}/*******************************************函数名称:LcdLine功能:改变lCD显示的第一行,从而实现滚屏效果参数:Line 取值0-63之间,增大向上滚,减小向下滚返回值:无********************************************/void LcdLine(uchar Line){if(Line<64){Line=Line+0xc0;LcdChoiceL();//选择右侧LcdWriteCommand(Line, 1);//设置显示屏0行为第一行//LcdWriteCommand(0x40, 1);//设置显示屏0列为第一列/*_NOP();_NOP();_NOP();*/Delay5ms();LcdChoiceR();//选择左侧LcdWriteCommand(Line, 1);//设置显示屏0行为第一行//LcdWriteCommand(0x40, 1);//设置显示屏0列为第一列}//显示模式设置}/*******************************************函数名称:LcdClear功能:对12864液晶模块屏幕清屏参数:无返回值:无********************************************/void LcdClear(void){ uchar k;uchar n;for(k=0;k<8;k++){for(n=0;n<64;n++){ LcdChoiceL();//选择左侧LocateXY( n,k );LcdWriteData(0x00);LcdChoiceR();//选择右侧LocateXY( n,k );LcdWriteData(0x00);}}}/*******************************************函数名称:LcdWriteCommand功能:向液晶模块写入命令12864参数:cmd--命令,chk--是否判忙的标志,1:判忙,0:不判返回值:无********************************************/void LcdWriteCommand(uchar cmd,uchar chk){if (chk) WaitForEnable(); // 检测忙信号?CLR_RS;CLR_RW;_NOP();DataPort = cmd; //将命令字写入数据端口_NOP();SET_EN; //产生使能脉冲信号_NOP();_NOP();CLR_EN;}/*******************************************函数名称:LcdWriteData功能:向液晶显示的当前地址写入显示数据参数:data--显示字符数据返回值:无********************************************/void LcdWriteData( uchar data ){WaitForEnable(); //等待液晶不忙SET_RS;CLR_RW;_NOP();_NOP();_NOP();_NOP();DataPort = data; //将显示数据写入数据端口_NOP();_NOP();_NOP();_NOP();SET_EN; //产生使能脉冲信号_NOP();_NOP();CLR_EN;DataPort =0xff;}/*******************************************函数名称:WaitForEnable功能:等待12864液晶完成内部操作参数:无返回值:无********************************************/ void WaitForEnable(void){P2DIR &= 0x00; //将P2口切换为输入状态SET_RW;CLR_RS;_NOP();SET_EN;_NOP();_NOP();while((P2IN & Busy)!=0); //检测忙标志CLR_EN;P2DIR |= 0xFF; //将P2口切换为输出状态}/*******************************************函数名称:Delay5ms功能:延时约5ms参数:无返回值:无********************************************/void Delay5ms(void){uint i=40000;while (i != 0){i--;}}/************************************************************函数名:LCD_Write_16X16Font*功能:写一个16X16的汉字*参数:x , y , c[2] x:0-83 y:0-5*返回值:无*备注:***********************************************************/void LCD_Write_16X16Font(unsigned char x,unsigned char y,unsigned char c[2]) {unsigned char i,k;if(x<64){LcdChoiceL();LocateXY(x,y);}else{LcdChoiceL();x=x-64;LocateXY(x,y);}for(k=0; k<70; k++) //K的值表示汉字库最多存放的字的数量(可改大){if((font16X16[k].Index[0]==c[0])&&(font16X16[k].Index[1]==c[1])){for(i=0; i<32; i++){LcdWriteData(font16X16[k].Msk[i]);if(i==16){y++;LocateXY(x,y);}}}}}/************************************************************函数名:DisplarString*功能:写一行的中文字符*参数:*返回值:无*备注:***********************************************************/void DisplarString(unsigned char x,unsigned char y,unsigned char n,unsigned char *MemuTemp) {uchar a,b,i,x_1,y_1;for(a=0;a<n*2;a+=2) //计数列,每列7个字符{for(b=0;b<70;b++) //50个字符内搜索需要显示的字符{if((font16X16[b].Index[0]==MemuTemp[a])&&(font16X16[b].Index[1]==MemuTemp[a+1])) //找到需要显示的字符,显示{if((a*8+x)<64){LcdChoiceL();x_1=a*8+x;y_1=y;}else{ if((a*8+x)<128){LcdChoiceR();x_1=a*8+x-64;y_1=y;}else{LcdChoiceL();x_1=a*8+x-128;y_1=y+2;}}LocateXY(x_1,y_1);for(i=0; i<32; i++){if(i==16) //如果已经传送16个字节,换行传送字符下半部分{LocateXY(x_1,y_1+1);}LcdWriteData(font16X16[b].Msk[i]);}break;}}}}/*******************************************函数名称:LocateXY功能:向液晶输入显示字符位置的坐标信息,按照像素点定位行参数:x--位置的列坐标y--位置的行坐标返回值:无********************************************/void LocateXY_1(uchar x,uchar y){uchar tempx;uchar tempy;tempx=x|0x40;tempy=y|0xC0;LcdWriteCommand(tempx,1);LcdWriteCommand(tempy,1);}/************************************************************函数名:DisplarString2*功能:写指定个数的汉字,按照像素点定位行*参数:x列数,y行数,n显示汉字个数,MemuTemp汉字字符串*返回值:无*备注:***********************************************************/void DisplarString2(unsigned char x,unsigned char y,unsigned char n,unsigned char *MemuTemp) {uchar a,b,i,x_1,y_1;for(a=0;a<n*2;a+=2) //计数列,每列7个字符{for(b=0;b<70;b++) //50个字符内搜索需要显示的字符{if((font16X16[b].Index[0]==MemuTemp[a])&&(font16X16[b].Index[1]==MemuTemp[a+1])) //找到需要显示的字符,显示{if((a*8+x)<64){LcdChoiceL();x_1=a*8+x;y_1=y;}else{ if((a*8+x)<128){LcdChoiceR();x_1=a*8+x-64;y_1=y;}else{LcdChoiceL();x_1=a*8+x-128;y_1=y+2;}}LocateXY_1(x_1,y_1);for(i=0; i<32; i++){if(i==16) //如果已经传送16个字节,换行传送字符下半部分{LocateXY_1(x_1,y_1+1);}LcdWriteData(font16X16[b].Msk[i]);}break;}}}}/************************************************************函数名:DisplarFont8x16_2*功能:写一行的指定个数的字母*参数:x列数,y行数,n显示汉字个数,MemuTemp汉字字符串*返回值:无*备注:***********************************************************/void DisplarFont8x16_2(unsigned char x,unsigned char y,unsigned char d,unsigned char *MemuTemp){uchar a,b,i,x_1,y_1;uchar n;n=d*8;for(a=0;a<n;a++) //计数列,每列7个字符{if((a*8+x)<64) //判断是否在左侧屏幕{LcdChoiceL(); //选择左侧x_1=a*8+x; //定位坐标y_1=y;}else{ if((a*8+x)<128) //在右侧屏幕{LcdChoiceR();x_1=a*8+x-64;y_1=y;}else //超出右侧屏幕{if(a*8+x-128<64){LcdChoiceL(); //选择左侧屏幕x_1=a*8+x-128;y_1=y+2; //行下移一行}else{if(a*8+x-192<64){LcdChoiceR(); //选择右侧侧屏幕x_1=a*8+x-192;y_1=y+2; //行下移一行}}}}LocateXY(x_1,y_1);for(b=0;b<94;b++) //50个字符内搜索需要显示的字符{if(font8x16[b][0]==MemuTemp[a]) //找到需要显示的字符,显示{for(i=1; i<17; i++){if(i==9) //如果已经传送16个字节,换行传送字符下半部分{LocateXY(x_1,y_1+1);}LcdWriteData(font8x16[b][i]);}break;}}}}/************************************************************函数名:DisplarFont8x16*功能:写一行的字母*参数:*返回值:无*备注:***********************************************************/void DisplarFont8x16(unsigned char x,unsigned char y,unsigned char *MemuTemp) {uchar a,b,i,x_1,y_1;uchar n=0;while(MemuTemp[n]!='\0')n++;for(a=0;a<n;a++) //计数列,每列7个字符{if((a*8+x)<64) //判断是否在左侧屏幕{LcdChoiceL(); //选择左侧x_1=a*8+x; //定位坐标y_1=y;}else{ if((a*8+x)<128) //在右侧屏幕{LcdChoiceR();x_1=a*8+x-64;y_1=y;}else //超出右侧屏幕{if(a*8+x-128<64){LcdChoiceL(); //选择左侧屏幕x_1=a*8+x-128;y_1=y+2; //行下移一行}else{if(a*8+x-192<64){LcdChoiceR(); //选择右侧侧屏幕x_1=a*8+x-192;y_1=y+2; //行下移一行}}}}LocateXY(x_1,y_1);for(b=0;b<94;b++) //50个字符内搜索需要显示的字符{if(font8x16[b][0]==MemuTemp[a]) //找到需要显示的字符,显示{for(i=1; i<17; i++){if(i==9) //如果已经传送16个字节,换行传送字符下半部分{LocateXY(x_1,y_1+1);}LcdWriteData(font8x16[b][i]);}break;}}}}/************************************************************函数名:DisplarFont8x16Left*功能:写左侧一行的字母,y参数为1-4之间数字,字符组MemuTemp包含8个字符*参数:*返回值:无*备注:***********************************************************/void DisplarFont8x16Left(unsigned char y,unsigned char *MemuTemp){uchar a,b,i,x;y=2*y-2;uchar n=0;LcdChoiceL(); // 清除所选择行数据开始LocateXY( 0,y);for(n=0;n<64;n++)LcdWriteData(0x00);LocateXY( 0,y+1);for(n=0;n<64;n++)LcdWriteData(0x00); // 清除所选择行数据结束for(a=0;a<8;a++) //计数每行字节,每行7个字符{for(b=0;b<94;b++) //50个字符内搜索需要显示的字符{if(font8x16[b][0]==MemuTemp[a]) //找到需要显示的字符,显示{x=a*8; //计算LocateXY(x,y); //开始定位y 行0位上半部分for(i=1; i<17; i++){if(i==9) //如果已经传送16个字节,换行传送字符下半部分LocateXY(x,y+1); ////开始定位y 行0位下半部分LcdWriteData(font8x16[b][i]);}break;}}}}/*******************************************函数名称:LcdChoiceLine功能:对12864液晶指定行进行清除参数:无返回值:无********************************************/void LcdClearLine(uchar y){uchar n;LcdChoiceL();//选择左侧LocateXY( 0,y);for(n=0;n<64;n++)LcdWriteData(0x00);LocateXY( 0,y+1);for(n=0;n<64;n++)LcdWriteData(0x00);LcdChoiceR();//选择右侧LocateXY( 0,y);for(n=0;n<64;n++)LcdWriteData(0x00);LocateXY( 0,y+1);for(n=0;n<64;n++)LcdWriteData(0x00);}typedef struct{unsigned char Index[2];unsigned char Msk[32];}TYPE_FONT16X16;const TYPE_FONT16X16 font16X16[]={"宁",0x20,0x18,0x88,0x88,0x88,0x88,0x89,0x8E,0x88,0x88,0x88,0x88,0x88,0x28,0x18,0x00, 0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,"波",0x10,0x60,0x02,0x0C,0xC0,0x00,0xF8,0x88,0x88,0x88,0xFF,0x88,0x88,0xA8,0x18,0x00, 0x04,0x04,0x7C,0x03,0x80,0x60,0x1F,0x80,0x43,0x2C,0x10,0x28,0x46,0x81,0x80,0x00,"钢",0x20,0x10,0x2C,0xE7,0x24,0x24,0x00,0xFE,0x12,0x62,0x82,0x72,0x02,0xFE,0x00,0x00, 0x01,0x01,0x01,0x7F,0x21,0x11,0x00,0xFF,0x08,0x06,0x01,0x4E,0x80,0x7F,0x00,0x00,"铁",0x20,0x10,0x2C,0xE7,0x24,0x24,0x40,0x3C,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,0x00, 0x01,0x01,0x01,0x7F,0x21,0x11,0x80,0x41,0x31,0x0D,0x03,0x0D,0x31,0x41,0x81,0x00,"有",0x04,0x04,0x04,0x84,0xE4,0x3C,0x27,0x24,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00, 0x04,0x02,0x01,0x00,0xFF,0x09,0x09,0x09,0x09,0x49,0x89,0x7F,0x00,0x00,0x00,0x00,"限",0x00,0xFE,0x22,0x5A,0x86,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00, 0x00,0xFF,0x04,0x08,0x07,0x00,0xFF,0x40,0x20,0x03,0x0C,0x14,0x22,0x41,0x40,0x00,"公",0x00,0x80,0x40,0x20,0x18,0x06,0x80,0x00,0x07,0x18,0x20,0x40,0x80,0x00,0x00,0x00, 0x01,0x00,0x20,0x70,0x28,0x26,0x21,0x20,0x20,0x24,0x38,0x60,0x00,0x01,0x01,0x00,"司",0x00,0x10,0x12,0x92,0x92,0x92,0x92,0x92,0x92,0x12,0x12,0x02,0xFE,0x00,0x00,0x00, 0x00,0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x3F,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,"能",0x08,0xCC,0x4A,0x49,0x48,0x4A,0xCC,0x18,0x00,0x7F,0x88,0x88,0x84,0x82,0xE0,0x00, 0x00,0xFF,0x12,0x12,0x52,0x92,0x7F,0x00,0x00,0x7E,0x88,0x88,0x84,0x82,0xE0,0x00,"环",0x04,0x84,0x84,0xFC,0x84,0x84,0x00,0x04,0x04,0x84,0xE4,0x1C,0x84,0x04,0x04,0x00, 0x20,0x60,0x20,0x1F,0x10,0x10,0x04,0x02,0x01,0x00,0xFF,0x00,0x00,0x01,0x06,0x00,"部",0x40,0x44,0x54,0x65,0x46,0x44,0x64,0x54,0x44,0x40,0xFE,0x02,0x22,0xDA,0x06,0x00, 0x00,0x00,0x7E,0x22,0x22,0x22,0x22,0x7E,0x00,0x00,0xFF,0x08,0x10,0x08,0x07,0x00,"煤",0x80,0x70,0x00,0xFF,0x20,0x10,0x04,0x04,0xFF,0x24,0x24,0x24,0xFF,0x04,0x04,0x00,0x80,0x60,0x18,0x07,0x08,0x30,0x44,0x24,0x15,0x0D,0xFF,0x0D,0x15,0x24,0x44,0x00,"气",0x20,0x10,0x4C,0x47,0x54,0x54,0x54,0x54,0x54,0x54,0x54,0xD4,0x04,0x04,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x30,0x40,0xF0,0x00,"排",0x10,0x10,0x10,0xFF,0x90,0x08,0x88,0x88,0xFF,0x00,0x00,0xFF,0x88,0x88,0x08,0x00,0x02,0x42,0x81,0x7F,0x00,0x08,0x08,0x08,0xFF,0x00,0x00,0xFF,0x08,0x08,0x08,0x00,"水",0x00,0x20,0x20,0x20,0xA0,0x60,0x00,0xFF,0x60,0x80,0x40,0x20,0x18,0x00,0x00,0x00, 0x20,0x10,0x08,0x06,0x01,0x40,0x80,0x7F,0x00,0x01,0x02,0x04,0x08,0x10,0x10,0x00,"器",0x80,0x80,0x9E,0x92,0x92,0x92,0x9E,0xE0,0x80,0x9E,0xB2,0xD2,0x92,0x9E,0x80,0x00, 0x08,0x08,0xF4,0x94,0x92,0x92,0xF1,0x00,0x01,0xF2,0x92,0x94,0x94,0xF8,0x08,0x00,"报",0x10,0x10,0x10,0xFF,0x10,0x90,0x00,0xFE,0x82,0x82,0x82,0x92,0xA2,0x9E,0x00,0x00, 0x04,0x44,0x82,0x7F,0x01,0x00,0x00,0xFF,0x80,0x43,0x2C,0x10,0x2C,0x43,0x80,0x00,"警",0x12,0xEA,0xAF,0xAA,0xEA,0x0F,0xFA,0x02,0x88,0x8C,0x57,0x24,0x54,0x8C,0x84,0x00, 0x02,0x02,0xEA,0xAA,0xAA,0xAB,0xAA,0xAB,0xAA,0xAA,0xAA,0xAA,0xEA,0x02,0x02,0x00,"CO",0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00C, 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,"信",0x00,0x80,0x60,0xF8,0x07,0x00,0x04,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x04,0x00, 0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0xF9,0x49,0x49,0x49,0x49,0x49,0xF9,0x00,0x00,"号",0x80,0x80,0x80,0xBE,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xBE,0x80,0x80,0x80,0x00, 0x00,0x00,0x00,0x06,0x05,0x04,0x04,0x04,0x44,0x84,0x44,0x3C,0x00,0x00,0x00,0x00,"正",0x00,0x02,0x02,0xC2,0x02,0x02,0x02,0xFE,0x82,0x82,0x82,0x82,0x82,0x02,0x00,0x00, 0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,"常",0x20,0x18,0x08,0xEA,0xAC,0xA8,0xA8,0xAF,0xA8,0xA8,0xAC,0xEA,0x08,0x28,0x18,0x00, 0x00,0x00,0x3E,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x12,0x22,0x1E,0x00,0x00,0x00,"在",0x08,0x08,0x88,0xC8,0x38,0x0C,0x0B,0x08,0x08,0xE8,0x08,0x08,0x08,0x08,0x08,0x00,0x02,0x01,0x00,0xFF,0x40,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00,"发",0x00,0x00,0x18,0x16,0x10,0xD0,0xB8,0x97,0x90,0x90,0x90,0x92,0x94,0x10,0x00,0x00, 0x00,0x20,0x10,0x8C,0x83,0x80,0x41,0x46,0x28,0x10,0x28,0x44,0x43,0x80,0x80,0x00,"送",0x40,0x40,0x42,0xCC,0x00,0x88,0x89,0x8E,0x88,0xF8,0x88,0x8C,0x8B,0x88,0x80,0x00, 0x00,0x40,0x20,0x1F,0x20,0x40,0x50,0x48,0x46,0x41,0x42,0x44,0x58,0x40,0x40,0x00,"短",0x90,0x88,0x87,0xFC,0x84,0x84,0x80,0x02,0xF2,0x12,0x12,0x12,0x12,0xF2,0x02,0x00, 0x80,0x60,0x18,0x07,0x08,0x30,0x00,0x40,0x45,0x59,0x41,0x41,0x51,0x4D,0x40,0x00,"成",0x00,0x00,0xF8,0x48,0x48,0x48,0xC8,0x08,0xFF,0x08,0x09,0x0A,0xC8,0x88,0x08,0x00, 0x40,0x30,0x0F,0x00,0x08,0x50,0x4F,0x20,0x10,0x0B,0x0C,0x12,0x21,0x40,0xF0,0x00,"功",0x00,0x04,0x04,0x04,0xFC,0x04,0x14,0x14,0x10,0x90,0x7F,0x10,0x10,0xF0,0x00,0x00, 0x04,0x0C,0x04,0x04,0x03,0x42,0x22,0x11,0x0C,0x23,0x20,0x60,0x20,0x1F,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,0x24,0x24,0x24,0x24,0x24,0x24,0xFE,0x22,0x22,0x22,0x22,0x22,0x20,0x00,0x00, 0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,"机",0x08,0x08,0xC8,0xFF,0x48,0x88,0x08,0x00,0xFE,0x02,0x02,0x02,0xFE,0x00,0x00,0x00, 0x04,0x03,0x00,0xFF,0x00,0x41,0x30,0x0C,0x03,0x00,0x00,0x00,0x3F,0x40,0x78,0x00,"卡",0x00,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x40,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x02,0x04,0x0C,0x38,0x10,0x00,0x00,"错",0x40,0x30,0x2C,0xE7,0x24,0x24,0x40,0x48,0x7F,0x48,0x48,0x7F,0x48,0x48,0x40,0x00, 0x01,0x01,0x01,0xFF,0x41,0x21,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,"误",0x40,0x41,0xCE,0x04,0x00,0x40,0x5F,0x51,0x51,0xD1,0x51,0x51,0x5F,0x40,0x00,0x00, 0x00,0x00,0x3F,0x10,0x88,0x42,0x22,0x12,0x0A,0x07,0x0A,0x12,0x22,0xE2,0x42,0x00,/*********************************************/"强",0x02,0xE2,0x22,0x22,0x3E,0x00,0x80,0x9E,0x92,0x92,0xF2,0x92,0x92,0x9E,0x80,0x00, 0x00,0x43,0x82,0x42,0x3E,0x40,0x47,0x44,0x44,0x44,0x7F,0x44,0x44,0x54,0xE7,0x00,"度",0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00, 0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,"中",0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00, 0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00,"国",0x00,0xFE,0x02,0x12,0x92,0x92,0x92,0xF2,0x92,0x92,0x92,0x12,0x02,0xFE,0x00,0x00, 0x00,0xFF,0x40,0x48,0x48,0x48,0x48,0x4F,0x48,0x4A,0x4C,0x48,0x40,0xFF,0x00,0x00,"移",0x24,0x24,0xA4,0xFE,0x23,0x22,0x00,0x10,0x08,0x94,0x67,0x24,0x94,0x0C,0x00,0x00, 0x08,0x06,0x01,0xFF,0x01,0x06,0x00,0x89,0x89,0x44,0x4A,0x33,0x12,0x0A,0x06,0x00,"动",0x40,0x44,0xC4,0x44,0x44,0x44,0x40,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00, 0x10,0x3C,0x13,0x10,0x14,0xB8,0x40,0x30,0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00,"联",0x02,0xFE,0x92,0x92,0xFE,0x02,0x00,0x10,0x11,0x16,0xF0,0x14,0x13,0x10,0x00,0x00, 0x10,0x1F,0x08,0x08,0xFF,0x04,0x81,0x41,0x31,0x0D,0x03,0x0D,0x31,0x41,0x81,0x00,"通",0x40,0x42,0xCC,0x00,0x00,0xE2,0x22,0x2A,0x2A,0xF2,0x2A,0x26,0x22,0xE0,0x00,0x00, 0x80,0x40,0x3F,0x40,0x80,0xFF,0x89,0x89,0x89,0xBF,0x89,0xA9,0xC9,0xBF,0x80,0x00,"服",0x00,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0xFE,0x82,0x82,0x92,0xA2,0x9E,0x00,0x00, 0x80,0x60,0x1F,0x02,0x42,0x82,0x7F,0x00,0xFF,0x40,0x2F,0x10,0x2C,0x43,0x80,0x00,"务",0x00,0x00,0x90,0x88,0x4C,0x57,0xA4,0x24,0x54,0x54,0x8C,0x84,0x00,0x00,0x00,0x00, 0x01,0x01,0x80,0x42,0x22,0x1A,0x07,0x02,0x42,0x82,0x42,0x3E,0x01,0x01,0x01,0x00,"串",0x00,0x00,0x3C,0x24,0x24,0x24,0x24,0xFF,0x24,0x24,0x24,0x24,0x3C,0x00,0x00,0x00, 0x00,0x1F,0x09,0x09,0x09,0x09,0x09,0xFF,0x09,0x09,0x09,0x09,0x09,0x1F,0x00,0x00,"口",0x00,0x00,0xFC,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0x00,0x00,0x00, 0x00,0x00,0x7F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7F,0x00,0x00,0x00,"通",0x40,0x42,0xCC,0x00,0x00,0xE2,0x22,0x2A,0x2A,0xF2,0x2A,0x26,0x22,0xE0,0x00,0x00, 0x80,0x40,0x3F,0x40,0x80,0xFF,0x89,0x89,0x89,0xBF,0x89,0xA9,0xC9,0xBF,0x80,0x00,"讯",0x40,0x40,0x42,0xCC,0x00,0x82,0x82,0xFE,0x82,0x82,0x02,0xFE,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x7F,0x20,0x10,0x00,0xFF,0x00,0x00,0x00,0x0F,0x30,0x40,0xF8,0x00,"异",0x00,0x00,0x7E,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x9E,0x80,0xE0,0x00,0x00, 0x08,0x88,0x48,0x28,0x1E,0x08,0x08,0x08,0x08,0x08,0xFE,0x08,0x08,0x08,0x08,0x00,"修",0x40,0x20,0xF8,0x07,0xF0,0xA0,0x90,0x4C,0x57,0x24,0xA4,0x54,0x4C,0x80,0x80,0x00, 0x00,0x00,0xFF,0x00,0x1F,0x80,0x92,0x52,0x49,0x29,0x24,0x12,0x08,0x00,0x00,0x00,//修0,"改",0x04,0x84,0x84,0x84,0x84,0xFC,0x40,0x30,0xCC,0x0B,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x7F,0x20,0x10,0x10,0x08,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,//改1,"码",0x04,0x84,0xE4,0x5C,0x44,0xC4,0x00,0x02,0xF2,0x82,0x82,0x82,0xFE,0x80,0x80,0x00,0x02,0x01,0x7F,0x10,0x10,0x3F,0x00,0x08,0x08,0x08,0x08,0x48,0x88,0x40,0x3F,0x00,//码2,"电",0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00,//电3,"话",0x40,0x40,0x42,0xCC,0x00,0x00,0x20,0x24,0x24,0x24,0xFE,0x22,0x23,0x22,0x20,0x00,0x00,0x00,0x00,0x7F,0x20,0x10,0x00,0xFE,0x42,0x42,0x43,0x42,0x42,0xFE,0x00,0x00,//话4,"接",0x10,0x10,0x10,0xFF,0x10,0x50,0x44,0x54,0x65,0xC6,0x44,0x64,0x54,0x44,0x40,0x00,0x04,0x44,0x82,0x7F,0x01,0x82,0x82,0x4A,0x56,0x23,0x22,0x52,0x4E,0x82,0x02,0x00,//接5,"收",0x00,0xFC,0x00,0x00,0xFF,0x00,0x40,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00,0x00,0x0F,0x04,0x02,0xFF,0x00,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,//收6,"息",0x00,0x00,0x00,0xFC,0x54,0x54,0x56,0x55,0x54,0x54,0x54,0xFC,0x00,0x00,0x00,0x00,0x40,0x30,0x00,0x03,0x39,0x41,0x41,0x45,0x59,0x41,0x41,0x73,0x00,0x08,0x30,0x00,//息7,"数",0x90,0x52,0x34,0x10,0xFF,0x10,0x34,0x52,0x80,0x70,0x8F,0x08,0x08,0xF8,0x08,0x00,0x82,0x9A,0x56,0x63,0x22,0x52,0x8E,0x00,0x80,0x40,0x33,0x0C,0x33,0x40,0x80,0x00,//数8,"量",0x20,0x20,0x20,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xBE,0x20,0x20,0x20,0x00, 0x00,0x80,0x80,0xAF,0xAA,0xAA,0xAA,0xFF,0xAA,0xAA,0xAA,0xAF,0x80,0x80,0x00,0x00,//量9,"存",0x04,0x04,0x84,0xE4,0x1C,0x07,0x24,0x24,0x24,0x24,0xA4,0x64,0x24,0x04,0x04,0x00,0x02,0x01,0x00,0xFF,0x00,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x00,//存10,"储",0x80,0x60,0xF8,0x87,0x84,0x98,0x00,0x20,0x24,0xA4,0x7F,0x24,0x34,0x28,0x24,0x00,0x00,0x00,0xFF,0x00,0x00,0x7F,0x24,0x12,0x01,0xFF,0x49,0x49,0x49,0xFF,0x00,0x00,//储11,"无",0x00,0x40,0x42,0x42,0x42,0xC2,0x7E,0x42,0xC2,0x42,0x42,0x42,0x40,0x40,0x00,0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00,0x00,};/************************************************************说明:该font.h 文件中包含的是5110显示所用的ASCII、部分汉字、及图片字模。

12864液晶驱动程序库V2.0

12864液晶驱动程序库V2.0
// 功能描述: 液晶查忙程序,如果液晶忙,则一直在函数中循环
//---------------------------------------------------------------
void Check_Busy(void)
{
busy = 1; //先置位繁忙标志位
// 功能描述: 液晶发送数据函数
//---------------------------------------------------------------
void LCD12864SendData( uchar byData ) //发送数据
{
Check_Busy( );
{
uint i ;
for( ; nDelay > 0 ; nDelay-- )
{
for( i = 125 ; i > 0 ; i-- ) ;
}
}
uchar const sign[][1] =
{
//摄氏度符号
0xa1,0xe6,
byReturnValue = LCD12864_DATAPORT ;
LCD12864_EN = 0 ;
return byReturnValue ;
}
//---------------------------------------------------------------
TRISD = 0XFF; //更改通信为输入
LCD12864_RS = 0; //设置该字节数据为命令代码
LCD12864_RW = 1; //设置此次操作为读
while(busy)
LCD12864_RW = 0 ;

12864并口驱动程序

12864并口驱动程序
*函数名称: txt_disp
*功能描述: 显示一行汉字或字符
******************************************************************************************/
void txt_disp(unsigned char code *cn,unsigned char adr)
*函数名称: con_disp
*功能描述: 当data=0xff时,在x0,y0处显示长为16xl宽为yl的方块
******************************************************************************************/
//***************************************************************************
//连线表: CPU=89C52 *
//RS=P3.0 RW=P3.1 E=P3.2 *
//FOSC=12MHz D0-D7=P1.0-P1.7 *
wr_lcd(com,0x80+j-32);
wr_lcd(com,0x88+i);
wr_lcd(com,0x30);
wr_lcd(dat,img[j*16+i*2]);
wr_lcd(dat,img[j*16+i*2+1]);
}
void gra_disp(unsigned char code *img);
void lat_disp(unsigned char data1,unsigned char data2);

LCD驱动程序开发指南

LCD驱动程序开发指南

LCD驱动程序开发指南LCD驱动开发指引1、LCD驱动概述LCD驱动程序调试,是整个⼿机研发过程中⾮常重要的⼀个环节,在每个新的机型开发的初期,最先都要调试LCD驱动程序,我们俗称“点屏”。

“点屏”的调试包括两个部分,⼀是点亮LCD的背光,⼆是调试LCD显⽰。

背光驱动调试的⽅法与技巧,会在背光⽂档中叙述,暂不在这篇⽂档⾥讨论,本⽂将重点讨论LCD的电路原理、驱动程序分析、LCD驱动调试经验总结和具体驱动调试案例的分析。

2、LCD原理及电路分析相关概念:LCD:全称是Liquid Crystal Display 液晶显⽰屏LCM:全称是Liquid Crystal Module指的是液晶显术模块,包括液晶屏及液晶的外围FPC电路和结构件。

LCD的FPC电路:指LCM模块中的液晶外围电路,这部分电路由LCD模组⼚家按照我们对LCD的接⼝要求进⾏设计的。

在LCD驱动调试中,看FPC电路图也是很重要的⼀个环节。

LCD外围电路:我们通常也简称为LCD电路,指的是baseband端的LCD接⼝电路部分,这部分电路由我们⾃⾏设计。

LCD模组⼚家:指信利,天马,京东⽅这些⼚家。

他们将LCD制作成可以供我们⽣产使⽤的LCM模组。

2.1LCD芯⽚介绍⽬前⼿机使⽤的⼤部分显⽰器件都是LCD(Liguid Crystal Display)器件,⽬前康佳使⽤的LCM模块由信利、京东⽅、天马、凌达这⼏家⼚商供货。

但是LCM⽣产⼚家对我们调试驱动并没有任何关系,我们需要了解的是LCM所使⽤的IC型号。

因为,我们实际上是对LCD的IC进⾏编程,间接控制LCD⾯板,常⽤的IC有HD66773、S6B33B2/ S6B33B6、HD66777等。

LCD驱动的编程,除了要关注IC的型号,还要关注LCD FPC的电路设计,LCD外围电路设计,基带芯⽚的LCD接⼝单元,背光IC的控制等⼏个⽅⾯,当然也包括软件的上层程序。

下⾯我们就先了解⼀下LCD IC的内部结构,这是编程要关注的最主要⽅⾯。

12864LCD驱动程序

12864LCD驱动程序

//----------------------------------------------------------------- // 名称: LGM12864LCD显示驱动程序(不带字库) //----------------------------------------------------------------- #include <pic.h>#include "LGM12864.h"//是否反相显示(白底黑字/黑底白字)INT8U Reverse_Display = 0;//----------------------------------------------------------------- // 等待液晶就绪//----------------------------------------------------------------- void Wait_LCD_Ready(){}//----------------------------------------------------------------- // 向LCD发送命令//----------------------------------------------------------------- void LCD_Write_Command(INT8U cmd){}//----------------------------------------------------------------- // 向LCD发送数据//----------------------------------------------------------------- void LCD_Write_Data(INT8U dat){}//----------------------------------------------------------------- // LCD初始化函数//----------------------------------------------------------------- void LCD_Initialize()RST = 0; __delay_ms(1); //复位LCDRST = 1; //恢复LCD正常工作LCD_Write_Command(0x30); __delay_ms(15); //基本指令操作LCD_Write_Command(0x01); __delay_ms(15); //清除显示LCD_Write_Command(0x06); __delay_ms(15); //光标移动方向LCD_Write_Command(0x0c); __delay_ms(15); //开显示,关光标,不闪烁}//-----------------------------------------------------------------//// 通用显示函数//// 从第P页第L列开始显示W个字节数据,数据在r所指向的缓冲// 每字节8位是垂直显示的,高位在下,低位在上// 每个8*128的矩形区域为一页// 整个LCD又由64x64的左半屏和64x64的右半屏构成//-----------------------------------------------------------------void Common_Show(INT8U P,INT8U L,INT8U W,INT8U *r){INT8U i;//显示在左半屏或左右半屏if( L < 64 ){}//全部显示在右半屏else{}}//-----------------------------------------------------------------// 显示一个8×16点阵字符//-----------------------------------------------------------------void Display_A_Char_8X16(INT8U P,INT8U L,INT8U *M)}//-----------------------------------------------------------------// 显示一个16×16点阵汉字//-----------------------------------------------------------------void Display_A_WORD(INT8U P,INT8U L,INT8U *M){}//-----------------------------------------------------------------// 显示一串16×16点阵汉字//-----------------------------------------------------------------void Display_A_WORD_String(INT8U P,INT8U L,INT8U C,INT8U *M) {}。

三通道LED驱动芯片MAX16824/MAX16825及其应用

三通道LED驱动芯片MAX16824/MAX16825及其应用

0 引 言
Maxim公 司推 出的MAX16824/MAX16825是 用 于现 代汽 车半 导体 照 明 系统 的三 通道 、高亮 度 的 LED (HB LE D1驱 动 器 ,具 有6.5~28 V输入 电压 范 围 。该 系 列 器件 具 有 三 路36V额 定 、开 漏 、恒 定 电流 吸 入 输 出能 力 ,可 向三 串独 立 的HB LED 提供 高达 150mA的驱 动 电流 。此 外 。为 优化 设计 的灵活 性 ,该 系Y ̄ ]IC还 可 以独 立设 定 各个 通 道 的 LE D电 流 。其 中MAX16824可 提 供 三 路 PWM调 光 输 入 ,以用 于独 立控 制 各 串L E D的亮 度 ,并 可切 换 各 串LED的 导 通 与 关 断 。 而MAX168255U提供 有 3位透 明锁 存 器 、3位 移 位 寄 存 器 以及2 Mbps、 4线 串 行 接 口 。 通 过 使 用 4个 输 入 引 脚 fDIN, CLK,LE,OE)和 一 个 数 据 输 出 引 脚 (DOUT), 还 可使 微控 制器 用 串 口配 置其 输 出通 道 ;该 芯 片 的DOUT ̄I脚 允许 多个 驱 动 芯 片 通 过 级 联 的方 式 实 现 协 同工 作 。该 系列 LED驱 动 器 可广 泛 用 于 工 业 、建筑 以及装 饰 照 明 ,室 内/室 外LED视 频 显示 器 、汽 车 内部照 明 以及 LCD背 光等 应用 。
收 稿 日期 :2008—01—10
通 过 MAX16825的 四 线 串 口 (DIN,CLK,
14 电 子 元 嚣 件 主 硐 2008.5 枷 聊.ecd ̄cn
第210 00卷8年5第月5 期
姆厂霞 厕
表 1 MAX16824/MAX16825的 引 脚 功 能

12864 LCD驱动程序

12864 LCD驱动程序

/*LCD.C128×64 LCD驱动程序*/#include <INTRINS.H>#include <ABSACC.H>#include "LCD.H"//定义屏幕光标(取值0~63,光标本身不可见)unsigned char LcdCursor;/*函数:LcdLightOn()功能:点亮背光灯*/void LcdLightOn(){LCD_BL = 1;}/*函数:LcdLightOff()功能:熄灭背光灯*/void LcdLightOff(){LCD_BL = 0;}/*函数:LcdGetBF()功能:读出状态位BF返回:BF=1,表示忙,不可进行任何操作BF=0,表示不忙,可以进行正常操作*/bit LcdGetBF(){unsigned char dat;dat = XBYTE[0xD002]; //XBYTE的定义见<ABSACC.H>return (bit)(dat & 0x80);}/*函数:LcdWriteCmd()功能:向LCD发送命令参数:cmd:命令字,详见器件的数据手册*/void LcdWriteCmd(unsigned char cmd){while ( LcdGetBF() );XBYTE[0xD000] = cmd;}/*函数:LcdWriteDat()功能:向LCD写入数据参数:dat,要写入的数据说明:目标地址由地址计数器AC隐含指定,写完后AC自动加1*/void LcdWriteDat(unsigned char dat){while ( LcdGetBF() );XBYTE[0xD001] = dat;}/*函数:LcdReadDat()功能:从LCD读出数据返回:读出的数据*//*unsigned char LcdReadDat(){volatile unsigned char dat;while ( LcdGetBF() );dat = XBYTE[0xD003];dat = XBYTE[0xD003]; //需要连续执行两次才能够读出真正的数据return dat;}*//*函数:LcdSetAC()功能:设置DDRAM(显示数据RAM)的AC(地址计数器)值参数:ac:地址计数器值,范围0~63*/void LcdSetAC(unsigned char ac){ac &= 0x3F;ac |= 0x80;LcdWriteCmd(ac);}/*函数:LcdClear()功能:LCD清屏,并使光标回到0*/void LcdClear(){LcdWriteCmd(0x01); //清屏命令LcdCursor = 0;}/*函数:LcdDelay()功能:延时(t*100)个机器周期*/void LcdDelay(unsigned char t){unsigned char n;do{n = 49;while ( --n != 0 );} while ( --t != 0 );}/*函数:LcdInit()功能:LCD初始化*/void LcdInit(){LcdWriteCmd(0x30); //设置基本指令集LcdDelay(3);LcdWriteCmd(0x30); //设置基本指令集(需要再执行一次)LcdDelay(1);LcdWriteCmd(0x0C); //开启显示LcdDelay(3);LcdClear(); //清屏LcdDelay(250);LcdWriteCmd(0x06); //设置进入点LcdDelay(10);}/*函数:LcdCheckAC()功能:根据光标位置调整AC*/void LcdCheckAC(){switch ( LcdCursor ){case 16:LcdSetAC(16);break;case 32:LcdSetAC(8);break;case 48:LcdSetAC(24);break;case 64:LcdCursor = 0;LcdSetAC(0);break;default:break;}/*函数:LcdPutChar()功能:显示ASCII码参数:c为可显示的ASCII码(0x20~0x7F)*/void LcdPutChar(unsigned char c){LcdWriteDat(c);LcdCursor++;LcdCheckAC();}/*函数:LcdPutHZ()功能:显示汉字参数:ch,cl:汉字编码*/void LcdPutHZ(unsigned char ch, unsigned char cl){if ( LcdCursor & 0x01 ){//显示汉字时,必须偶地址对准,即光标位置不能是奇数LcdPutChar(' '); //额外输出一个空格}LcdWriteDat(ch);LcdWriteDat(cl);LcdCursor += 2;LcdCheckAC();}/*函数:LcdPuts()功能:显示字符串参数:*s:要显示的字符串(可同时包含ASCII码和汉字)*/void LcdPuts(unsigned char *s){unsigned char ch, cl;for (;;){ch = *s++;if ( ch == '\0' ) break;if ( ch < 0x80 ){LcdPutChar(ch);}else{cl = *s++;LcdPutHZ(ch,cl);}}}。

LCD12864(ST7920)串行驱动程序

LCD12864(ST7920)串行驱动程序
读写函数
0xf8为写命令的命令字;0xfa为写数据的命令字,这里用的是TI_F28027
在编写和调试过程中借鉴了一些网上的程序,在此表示感谢,
这里是已经调好的,在移植过程中,调试时注意先要通过示波器对函数
void send_data(Uint16 D_Ctrl,Uint16 D_data)
void send_data(Uint16 D_Ctrl,Uint16 D_data)
//LCD_CLK一个脉冲写一位
{
Uint16 i,j;
Uint16 temp;
//LCD_CS=1; //片选使能
GpioDataRegs.GPADAT.bit.GPIO16=1;
send_data (0xf8,y+j*2);
send_data (0xf8,x+i);
send_data (0xf8,0x30);
send_data (0xfa,data1);
send_data (0xfa,data1);
for(i=0;i<3;i++) // 串行数据的传送
{
if(i==0) //写第一个字节 格式1111 1ABC
{
temp=D_Ctrl;
}
if(i==1) //写第二个字节 第一次写 高四位放在第一次传送的高四位
{
temp=(D_data&0xf0);
功能:
实现在任意坐标写一个字
X列;Y行
===========================================================================*/

LCD19264的驱动程序

LCD19264的驱动程序

LCD19264的驱动程序#include "Public.h"#define Fisrt 01#define Second 02#define Third 03/*定义LCD控制端口*/sbit LCD_RS = P0^7;sbit LCD_RW = P0^6;sbit LCD_CE = P0^5;sbit LCD_CSA = P0^4;sbit LCD_REST = P0^3;sbit LCD_CSB = P0^2;sbit LCD_CSC = P0^1;#define DATA_BUS P2/************************************************************** *****函数功能说明:判断LCD忙函数1、2、3、*************************************************************** ****/void Read_busy(unsigned char Area){unsigned char temp = 0;do{LCD_CE = 0;LCD_RS = 0; switch(Area){case Fisrt:LCD_CSA = 0; break;case Second: LCD_CSB = 0; break;case Third:LCD_CSC = 0; break;default:break;}_nop_();LCD_CE = 1;_nop_();temp = DATA_BUS; LCD_CE = 0;LCD_RW = 0; switch(Area){case Fisrt:LCD_CSA = 1; break;case Second: LCD_CSB = 1; break;case Third:break;default:break;}LCD_CE = 1;}while(temp&0x80);}/************************************************************** *****函数功能说明:设置坐标1、液晶分为三个区 A、B、C2、设置每个区的坐标3、送坐标到总线上*************************************************************** ****/void Set_Locatexy(unsigned char x_add,unsigned char y_add) {switch(x_add&0xc0){case 0x00:Write_command(Fisrt,x_add&0x3f)break;case 0x40:break;case 0x80:break;default:break;}/************************************************************** *****函数功能说明:写数据1、液晶分为三个区 A、B、C2、设置每个区的片选信号3、送数据到总线上*************************************************************** ****/void Write_data(unsigned char Area_Num,unsigned char Lcd_data){Read_busy(Area_Num);LCD_CE = 0; /*写入到LCM*/LCD_RW = 0;LCD_RS = 1; //数据switch(Area_Num){case Fisrt:LCD_CSA = 0;break;case Second:LCD_CSB = 0;break;case Third:LCD_CSC = 0;break;default:break;_nop_();LCD_CE = 1;_nop_();DATA_BUS = Lcd_data;_nop_();_nop_();LCD_CE = 0;LCD_RW = 1;switch(Area_Num){case Fisrt:LCD_CSA = 1;break;case Second:LCD_CSB = 1;break;case Third:LCD_CSC = 1;break;default:break;}LCD_CE = 1;}/************************************************************** *****函数功能说明:写命令1、液晶分为三个区 A、B、C2、设置每个区的片选信号3、送命令到总线上*******************************************************************/void Write_command(unsigned char Area_Num,unsigned char Lcd_Command){Read_busy(Area_Num);LCD_CE = 0; /*写入到LCM*/LCD_RW = 0;LCD_RS = 0; //指令switch(Area_Num){case Fisrt:LCD_CSA = 0;break;case Second:LCD_CSB = 0;break;case Third:LCD_CSC = 0;break;default:break;}_nop_();LCD_CE = 1;_nop_();DATA_BUS = Lcd_Command;_nop_();_nop_();LCD_CE = 0;LCD_RW = 1;switch(Area_Num){case Fisrt:LCD_CSA = 1;break;case Second:LCD_CSB = 1;break;case Third:LCD_CSC = 1;break;default:break;}LCD_CE = 1;}void Lcminit( void ){LCD_REST = 0;_nop_();LCD_REST = 1;Write_command(Fisrt,0x40); Write_command(Second,0x40); Write_command(Third,0x40);Write_command(Fisrt,0xb8); Write_command(Second,0xb8); Write_command(Third,0xb8);Write_command(Fisrt,0xc0);Write_command(Second,0xc0); Write_command(Third,0xc0);Write_command(Fisrt,0x3f); Write_command(Second,0x3f); Write_command(Third,0x3f); }。

19264显示驱动程序

19264显示驱动程序

19264控制器KS0108#include <at89x52.h>#include <intrins.h>#include "zimo.h"#define RS P2_6 /*"H" is send or read the data;"L" is the instruction*/ #define RW P3_6#define E P2_5 /*Operation enable*/#define CS1 P2_4#define CS2 P2_3#define CS3 P2_2#define DATA P0#define uchar unsigned char#define uint unsigned int/* -------------------------------------------------Delay some time----------- */void delay10ms(unsigned char x){unsigned char i,j,k;for(i=0;i<x;i++)for(j=0;j<10;j++)for(k=0;k<120;k++);}/* -------------------------------------------------Send the instruction to the First KS0108 window--*/void OutFI(uchar i){unsigned char data_sta;do{E=0;RW=1;RS=0;CS1=0;_nop_();E=1;_nop_();data_sta=DATA;E=0;RW=0;CS1=1;E=1;}while(data_sta&0x80);E=0;RW=0;RS=0;CS1=0;_nop_();E=1;_nop_();DATA=i;_nop_();E=0;RW=1;CS1=1;E=1;}/* ------------------------------------------------- Send the instruction to the Second KS0108 window.--*/void OutSI(uchar i){unsigned char data_sta;do{E=0;RW=1;RS=0;CS2=0;_nop_();E=1;_nop_();data_sta=DATA;E=0;RW=0;CS2=1;E=1;}while(data_sta&0x80);E=0;RW=0;RS=0;CS2=0;_nop_();E=1;_nop_();DATA=i;_nop_();E=0;RW=1;CS2=1;E=1;}/* ------------------------------------------------- Send the instruction to the Third KS0108 window--*/void OutTI(uchar i){unsigned char data_sta;do{E=0;RW=1;RS=0;CS3=0;_nop_();E=1;_nop_();data_sta=DATA;E=0;RW=0;CS3=1;E=1;}while(data_sta&0x80);E=0;RW=0;RS=0;CS3=0;_nop_();E=1;_nop_();DATA=i;_nop_();E=0;RW=1;CS3=1;E=1;}/* -------------------------------------------------Send the data to the First ks0108 Window--*/void OutFD(uchar i){unsigned char data_sta;do{E=0;RW=1;RS=0;CS1=0;_nop_();E=1;_nop_();data_sta=DATA;E=0;RW=0;CS1=1;E=1;}while(data_sta&0x80);E=0;RW=0;RS=1;CS1=0;_nop_();E=1;_nop_();DATA=i;_nop_();E=0;RW=1;CS1=1;E=1;}/* ------------------------------------------------- Send the data to the Second ks0108 Window--*/void OutSD(uchar i){unsigned char data_sta;do{E=0;RW=1;RS=0;CS2=0;_nop_();E=1;_nop_();data_sta=DATA;E=0;RW=0;CS2=1;E=1;}while(data_sta&0x80);E=0;RW=0;RS=1;CS2=0;_nop_();E=1;_nop_();DATA=i;_nop_();E=0;RW=1;CS2=1;E=1;}/* ------------------------------------------------- Send the data to the Third ks0108 Window--*/void OutTD(uchar i){unsigned char data_sta;do{E=0;RW=1;RS=0;CS3=0;_nop_();data_sta=DATA;E=0;RW=0;CS3=1;E=1;}while(data_sta&0x80);E=0;RW=0;RS=1;CS3=0;_nop_();E=1;_nop_();DATA=i;_nop_();E=0;RW=1;CS3=1;E=1;}/* ------------------------------------------------- Read the data to the First ks0108 Window--*//*unsigned char RD_data_F(){unsigned char data_sta;do{E=0;RW=1;RS=0;CS1=0;_nop_();E=1;_nop_();data_sta=DATA;E=0;RW=0;CS1=1;E=1;}while(data_sta&0x80);E=0;RW=1;RS=1;CS1=0;_nop_();E=1;_nop_();_nop_();_nop_();data_sta=DATA;_nop_();E=0;RW=0;CS1=1;E=1;return (data_sta);}/* ------------------------------------------------- Read the data to the Second ks0108 Window--*//*unsigned char RD_data_S(){unsigned char data_sta;do{E=0;RW=1;RS=0;CS2=0;_nop_();E=1;_nop_();_nop_();_nop_();data_sta=DATA;E=0;RW=0;CS2=1;E=1;}while(data_sta&0x80);E=0;RW=1;RS=1;CS2=0;_nop_();data_sta=DATA;_nop_();E=0;CS2=1;E=1;return (data_sta);}/* ------------------------------------------------- Read the data to the Third ks0108 Window--*//*unsigned char RD_data_T(){unsigned char data_sta;do{E=0;RW=1;RS=0;CS3=0;_nop_();E=1;_nop_();_nop_();_nop_();data_sta=DATA;E=0;RW=0;CS3=1;E=1;}while(data_sta&0x80);E=0;RW=1;RS=1;CS3=0;_nop_();E=1;_nop_();data_sta=DATA;_nop_();E=0;CS3=1;E=1;return(data_sta);}/* ------------------------------------------------- Initialize the LCD,The system reset,invoke First time-*/void InitLCD(){OutFI(0x40); /*Set the Y address 0 */OutSI(0x40);OutTI(0x40);OutFI(0xb8); /*Set the Page 0 */OutSI(0xb8);OutTI(0xb8);OutFI(0xc0); /*Set the display start line 0 */OutSI(0xc0);OutTI(0xc0);OutFI(0x3f); /*Display ON */OutSI(0x3f);OutTI(0x3f);}/* -------------------------------------------------Clear the three ks0108's display ram.Clrscr screen-*/void Clrscreen(){unsigned char i,j;for(i=0;i<8;i++){OutFI(0xb8|i);for(j=0;j<64;j++){OutFI(j|0x40);OutFD(0);}}for(i=0;i<8;i++)(OutSI(0xb8|i);for(j=0;j<64;j++)(OutSI(j|0x40);OutSD(0);}}for(i=0;i<8;i++)(OutTI(0xb8|i);for(j=0;j<64;j++)(OutTI(j|0x40);OutTD(0);}}}/* -------------------------------------------------Display Chinese ideograph;x_add is the x address;It has 4 layers,0,1,2,3; Width is the Chinese ideograph width;bmp is the table's name-*/void DrawBmp(uchar x_add,uchar layer,uchar width,uchar *bmp)(unsigned char x;unsigned int i=0;for(x=x_add;x<x_add+width;x++)(if (x>127) /*The Third KS0108*/(OutTI((x-128)|0x40); /*Set the x address*/OutTI(layer|0xb8); /*Set the y address*/OutTD(bmp[i]); /*Send thd data to LCD ram*/OutTI((x-128)|0x40); /*Display the down screen*/ OutTI((layer|0xb8)+1); i++; /*Display zimo table address add 1*/ OutTD(bmp[i]);}else if (x>63) /*The Second ks0108*/{OutSI((x-64)|0x40);OutSI(layer|0xb8);OutSD(bmp[i]);OutSI((x-64)|0x40);OutSI((layer|0xb8)+1);i++;OutSD(bmp[i]);}else /*The First ks0108*/{OutFI(x|0x40);OutFI(layer|0xb8);OutFD(bmp[i]);OutFI(x|0x40);OutFI((layer|0xb8)+1);i++;OutFD(bmp[i]);}i++;}}/* -------------------------------------------------Display Chinese ideograph;x_add is the x address;It has 4 layers,0,1,2,3; Width is the Chinese ideograph width;bmp is the table's name.-*/void DrawBmp_f(uchar x_add,uchar layer,uchar width,uchar *bmp) {unsigned char x;unsigned int i=0;for(x=x_add;x<x_add+width;x++) (if (x>127)(OutTI((x-128)|0x40);OutTI(layer|0xb8);OutTD(~bmp[i]);OutTI((x-128)|0x40);OutTI((layer|0xb8)+1);i++;OutTD(~bmp[i]);}else if (x>63)(OutSI((x-64)|0x40);OutSI(layer|0xb8);OutSD(~bmp[i]);OutSI((x-64)|0x40);OutSI((layer|0xb8)+1);i++;OutSD(~bmp[i]);}else(OutFI(x|0x40);OutFI(layer|0xb8);OutFD(~bmp[i]);OutFI(x|0x40);OutFI((layer|0xb8)+1);i++;OutFD(~bmp[i]);}i++;}}/*Display indention; x_add is the x address;It has 4 layers,0,1,2,3; Width is the Chinese ideograph width-*/void _DrawBmp_(uchar x_add,uchar layer,uchar width){unsigned char x;for(x=x_add;x<x_add+width;x++){if (x>127){OutTI((x-128)|0x40);OutTI(layer|0xb8);OutTD(0);OutTI((x-128)|0x40);OutTI((layer|0xb8)+1);OutTD(0);}else if (x>63){OutSI((x-64)|0x40);OutSI(layer|0xb8);OutSD(0);OutSI((x-64)|0x40);OutSI((layer|0xb8)+1);OutSD(0);}else{OutFI(x|0x40);OutFI(layer|0xb8);OutFD(0);OutFI(x|0x40);OutFI((layer|0xb8)+1);OutFD(0);/* --------------------------------------------------Display indention; x_add is the x address;It has 4 layers,0,1,2,3; Width is the Chinese ideograph width-*/void _DrawBmp_black(uchar x_add,uchar layer,uchar width){unsigned char x;for(x=x_add;x<x_add+width;x++){if (x>127){OutTI((x-128)|0x40);OutTI(layer|0xb8);OutTD(0xff);OutTI((x-128)|0x40);OutTI((layer|0xb8)+1);OutTD(0xff);}else if (x>63){OutSI((x-64)|0x40);OutSI(layer|0xb8);OutSD(0xff);OutSI((x-64)|0x40);OutSI((layer|0xb8)+1);OutSD(0xff);}else{OutFI(x|0x40);OutFI(layer|0xb8);OutFD(0xff);}}OutFI(x|0x40);OutFI((layer|0xb8)+1);OutFD(0xff);}}}/* --------------------------------------------------Display the line display_data_graph is the display graph data-*/void _DrawBmp_line(uchar x_add,uchar layer,uchar width,uchar display_data_graph) {unsigned char x;unsigned int i=0;for(x=x_add;x<x_add+width;x++){if (x>127){OutTI((x-128)|0x40);OutTI(layer|0xb8);OutTD(display_data_graph);}else if (x>63){OutSI((x-64)|0x40);OutSI(layer|0xb8);OutSD(display_data_graph);}else{OutFI(x|0x40);OutFI(layer|0xb8);OutFD(display_data_graph);}i++;/*Display the column display_data_graph is the display graph data-*/void _DrawBmp_column(uchar x,uchar width) {unsigned int i=0;if (x>127){for(i=0;i<width;i++){OutTI((x-128)|0x40);OutTI(i|0xb8);OutTD(0xff);}}else if (x>63){for(i=0;i<width;i++){OutSI((x-64)|0x40);OutSI(i|0xb8);OutSD(0xff);}}else{for(i=0;i<width;i++){OutFI(x|0x40);OutFI(i|0xb8);OutFD(0xff);}}}}}。

PIC18单片机LCD液晶显示器驱动程序

PIC18单片机LCD液晶显示器驱动程序

//***********************************************//* Main.C *//***********************************************//* W-AP002 MPLAB C18 Advance Workshop *//* Written by: Richard Yang *//* Sr. Corporate Applications Engr.*//* Microchip Technology Inc. *//* Date: 16 January 2003 *//* Revision: 1 *//***********************************************//*********************************************************** #include <p18f452.h>#include <delays.h>#include "P18F_LCD.h"void InitializePORT(void);#pragma idata access My_RAM_1near char LCD_RAM_MSG[ ]="Richard Yang";near unsigned char LCD_Char='0';#pragma romdata RomDataconst rom char LCD_ROM_MSG[ ] ="WAP-002 Workshop";#pragma code//*********************************************************** /* */ /* Main Program */ /* */ //*********************************************************** void main(void){InitializePORT( );OpenLCD( );putcLCD('!');while(1);}//************************************************//* Function: Initialize PORT *//************************************************void InitializePORT(void){PORTA=0x00;TRISA=0b11011011; // RA2 as LCD-E control, RA5 as CS Control for SPIPORTD=0x00;TRISD=0x00; // Set PORTD as Output port}#pragma code#pragma romdata CONFIGconst rom unsigned char CONFIG1L=0xff ; // Don't care byteconst rom unsigned char CONFIG1H=0b00100010 ; // Disable OSC switch , XXXXX010 = HS Oscconst rom unsigned char CONFIG2L=0b00000001 ; // Disable PWRT , Disable BORconst rom unsigned char CONFIG2H=0b00000000 ; // Disable WDT timerconst rom unsigned char CONFIG3L=0xff ; // Don't care byteconst rom unsigned char CONFIG3H=0b00000000 ; // XXXXXXX0 = CCP2 --> RB3const rom unsigned char CONFIG4L=0b00000001 ; // 0XXXXXXX Backgroung Debug Enable ( ICD )const rom unsigned char CONFIG4H=0xff ; // Don't care byteconst rom unsigned char CONFIG5L=0b00001111 ; // Not PROG code protectedconst rom unsigned char CONFIG5H=0b11000000 ; // Not EEPROM code protectedconst rom unsigned char CONFIG6L=0b00001111 ;const rom unsigned char CONFIG6H=0b11100000 ;const rom unsigned char CONFIG7L=0b00001111 ;const rom unsigned char CONFIG7H=0b01000000 ;#pragma romdata// Declaration file for LCD related subroutinesvoid OpenLCD (void) ;void WriteCmdLCD ( unsigned char ) ;void WriteDataLCD( unsigned char ) ;void putsLCD( char * ) ;void putrsLCD( const rom char * ) ;void putcLCD( unsigned char ) ;void puthexLCD( unsigned char ) ;void LCD_Set_Cursor( unsigned char , unsigned char ) ;void LCD_CMD_W_Timing( void ) ;void LCD_L_Delay( void ) ;void LCD_S_Delay( void ) ;void LCD_DAT_W_Timing ( void ) ;#include <p18f452.h>#include <delays.h>#include "P18F_LCD.h"//// Defines for I/O ports that provide LCD data & control// PORTD[0:3]-->DB[4:7]: Higher order 4 lines data bus with bidirectional// : DB7 can be used as a BUSY flag// PORTA,2 --> [E] : LCD operation start signal control// PORTD,5 --> [RW]: LCD Read/Write control// PORTD,4 --> [RS]: LCD Register Select control// : "0" for Instrunction register (Write), Busy Flag (Read) // : "1" for data register (Read/Write)//#define CPU_SPEED 16 // CPU speed is 16 Mhz !!#define LCD_RS PORTDbits.RD4 // The definition of control pins #define LCD_RW PORTDbits.RD5#define LCD_E PORTAbits.RA2#define LCD_DATA LATD // PORTD[0:3] as LCD DB[4:7] //#define LCD_CTRL LATA#define DIR_LCD_DATA TRISD// LCD Module commands#define DISP_2Line_8Bit 0b00111000#define DISP_2Line_4Bit 0b00101000#define DISP_ON 0x00C // Display on#define DISP_ON_C 0x00E // Display on, Cursor on#define DISP_ON_B 0x00F // Display on, Cursor on, Blink cursor#define DISP_OFF 0x008 // Display off#define CLR_DISP 0x001 // Clear the Display#define ENTRY_INC 0x006 //#define ENTRY_INC_S 0x007 //#define ENTRY_DEC 0x004 //#define ENTRY_DEC_S 0x005 //#define DD_RAM_ADDR 0x080 // Least Significant 7-bit are for address#define DD_RAM_UL 0x080 // Upper Left coner of the Display#pragma udataunsigned char Temp_CMD ;unsigned char Str_Temp ;unsigned char Out_Mask ;#pragma codevoid OpenLCD(void){//ADCON1=(ADCON1 & 0xF0)|0b00001110; // Set AN0 for analog inputLCD_E=0;LCD_DATA = 0x00; // LCD DB[4:7] & RS & R/W --> LowDIR_LCD_DA TA = 0x00; // LCD DB[4:7} & RS & R/W are output functionTRISAbits.TRISA2=0; // Set E pin as outputLCD_DATA = 0b00000011 ;LCD_CMD_W_Timing() ;LCD_L_Delay() ;LCD_DATA = 0b00000011 ;LCD_CMD_W_Timing() ;LCD_L_Delay() ;LCD_DATA = 0b00000011 ;LCD_CMD_W_Timing() ;LCD_L_Delay() ;LCD_DATA = 0b00000010 ;LCD_CMD_W_Timing() ;LCD_L_Delay() ;WriteCmdLCD(DISP_2Line_4Bit) ;LCD_S_Delay() ;WriteCmdLCD(DISP_ON) ;LCD_S_Delay() ;WriteCmdLCD(ENTRY_INC) ;LCD_S_Delay() ;WriteCmdLCD(CLR_DISP) ;LCD_L_Delay() ;}//*********************************************// _ ______________________________// RS _>--<______________________________// _____// RW \_____________________________// __________________// E ____________/ \___// _____________ ______// DB _____________>--------------<______//***********************************************// Write Command to LCD module//void WriteCmdLCD( unsigned char LCD_CMD){Temp_CMD = (LCD_CMD & 0xF0)>>4 ; // Send high nibble to LCD bus LCD_DATA= (LCD_DA TA & 0xF0)|Temp_CMD ;LCD_CMD_W_Timing () ;Temp_CMD = LCD_CMD & 0x0F ; // Send low nibble to LCD bus LCD_DATA= (LCD_DA TA & 0xF0)|Temp_CMD ;LCD_CMD_W_Timing () ;LCD_S_Delay() ; // Delay 100uS for execution}//***********************************************// Write Data to LCD module//void WriteDataLCD( unsigned char LCD_CMD){Temp_CMD = (LCD_CMD & 0xF0)>>4 ; // Send high nibble to LCD bus LCD_DATA= (LCD_DA TA & 0xF0)|Temp_CMD ;LCD_DAT_W_Timing () ;Temp_CMD = LCD_CMD & 0x0F ; // Send low nibble to LCD bus LCD_DATA= (LCD_DA TA & 0xF0)|Temp_CMD ;LCD_DAT_W_Timing () ;LCD_S_Delay() ; // Delay 100uS for execution}void putcLCD(unsigned char LCD_Char){WriteDataLCD(LCD_Char) ;}void LCD_CMD_W_Timing( void ){LCD_RS = 0 ; // Set for Command InputNop();// LCD_RW = 0 ;Nop();LCD_E = 1 ;Nop();Nop();LCD_E = 0 ;}void LCD_DAT_W_Timing( void ){LCD_RS = 1 ; // Set for Data InputNop();// LCD_RW = 0 ;Nop();LCD_E = 1 ;Nop();LCD_E = 0 ;}//***********************************************// Set Cursor position on LCD module// CurY = Line (0 or 1)// CurX = Position ( 0 to 15)//void LCD_Set_Cursor(unsigned char CurY, unsigned char CurX) {WriteCmdLCD( 0x80 + CurY * 0x40 + CurX) ;LCD_S_Delay() ;}//***********************************************// Put a ROM string to LCD Module//void putrsLCD( const rom char *Str ){while (1){Str_Temp = *Str ;if (Str_Temp != 0x00 ){WriteDataLCD(Str_Temp) ;Str ++ ;}elsereturn ;}}//***********************************************// Put a RAM string to LCD Module//void putsLCD( char *Str){while (1){Str_Temp = *Str ;if (Str_Temp != 0x00 )WriteDataLCD(Str_Temp) ;Str ++ ;}elsereturn ;}}void puthexLCD(unsigned char HEX_Val){unsigned char Temp_HEX ;Temp_HEX = (HEX_Val >> 4) & 0x0f ;if ( Temp_HEX > 9 )Temp_HEX += 0x37 ;else Temp_HEX += 0x30 ;WriteDataLCD(Temp_HEX) ;Temp_HEX = HEX_Val & 0x0f ;if ( Temp_HEX > 9 )Temp_HEX += 0x37 ;else Temp_HEX += 0x30 ;WriteDataLCD(Temp_HEX) ;}//******************************************************************************* **// Delay for atleast 10 ms//******************************************************************************* **void LCD_L_Delay(void){Delay10KTCYx(CPU_SPEED / 4) ;}//******************************************************************************* **// Delay for 100 us//******************************************************************************* **void LCD_S_Delay(void){Delay100TCYx(CPU_SPEED/4) ;}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include <lm3sxxx.h>#define fuc_PERIPH SYSCTL_PERIPH_GPIOE#define fuc_PORT GPIO_PORTE_BASE#define rs_PIN GPIO_PIN_0#define rw_PIN GPIO_PIN_1#define en_PIN GPIO_PIN_2#define lcd_PERIPH SYSCTL_PERIPH_GPIOD#define lcd_PORT GPIO_PORTD_BASE#define lcd_PINS 0xff#define SysCtlPeriEnable SysCtlPeripheralEnable#define SysCtlPeriDisable SysCtlPeripheralDisable#define GPIOPinTypeIn GPIOPinTypeGPIOInput#define GPIOPinTypeOut GPIOPinTypeGPIOOutput#define GPIOPinTypeOD GPIOPinTypeGPIOOutputOD#define FIRST_ADDR 0 //定义字符/汉字显示起始位置unsigned char CGRAM[]={0x08,0x20,0x1c,0x10,0x1c,0x1c,0xff,0x9e,0x7f,0x1e,0x1c,0x1f,0x3e,0x1f,0x3e,0x1f ,0x77,0x1f,0x41,0x3f,0x00,0x7e,0x00,0xfe,0x83,0xfc,0x7f,0xf8,0x3f,0xf0,0x0f,0xc0 ,};unsigned char BMP1[];unsigned char BMP2[];unsigned char BMP3[];unsigned char BMP4[];unsigned char BMP5[];unsigned char BMP6[];unsigned char BMP7[];unsigned char BMP8[];unsigned char Num[]={'0','1','2','3','4','5','6','7','8','9','.'};void delay (int m){int n;for(n=0;n<=m;n++);}void check(void) //判断是否忙碌{delay(500);}void write_com(unsigned char com) //写显示命令{GPIOPinWrite(lcd_PORT , lcd_PINS, com); //P0=com;GPIOPinWrite(fuc_PORT , rs_PIN, 0X00); // rs=0;GPIOPinWrite(fuc_PORT , rw_PIN, 0X00); //rw=0GPIOPinWrite(fuc_PORT , en_PIN, 0Xff); // lcden=0;check();GPIOPinWrite(fuc_PORT , en_PIN, 0X00); //lcden=1;GPIOPinWrite(lcd_PORT , lcd_PINS, 0xff); //P0=com;}void write_data(unsigned char date) //写显示数据{GPIOPinWrite(lcd_PORT , lcd_PINS, date); //P0=com;GPIOPinWrite(fuc_PORT , rs_PIN, 0Xff); // rs=0;GPIOPinWrite(fuc_PORT , rw_PIN, 0X00); //rw=0GPIOPinWrite(fuc_PORT , en_PIN, 0xff); // lcden=0;check();GPIOPinWrite(fuc_PORT , en_PIN, 0X00); //lcden=1;GPIOPinWrite(lcd_PORT , lcd_PINS, 0xff); //P0=com;}void LCD_INIT(void) //初始化LCD{SysCtlPeriEnable(lcd_PERIPH); // 使能LcD所在的GPIO 端口GPIOPinTypeOut(lcd_PORT,lcd_PINS);SysCtlPeriEnable(fuc_PERIPH); // 使能LcD功能端口所在的GPIO 端口 GPIOPinTypeOut(fuc_PORT,rs_PIN|en_PIN|rw_PIN );GPIOPinWrite(fuc_PORT , en_PIN, 0Xff); //lcden=1;write_com(0x01); //清除屏幕显示,将DDRAM的地址计数器清零delay(5);write_com(0x30); //清除屏幕显示,将DDRAM的地址计数器清零delay(5);write_com(0x30); //8BIT控制界面,基本指令集delay(5);write_com(0X0C);delay(5);write_com(0x01); // /清除屏幕显示,将DDRAM的地址计数器清零delay(5);write_com(0x06); //DDRAM的地址计数器(AC)加1delay(5);}//********************************************************************// 名称 : DisStr16()// 功能 : 12864显示16*16字符串函数// 输入 : hang显示的行数,lie显示的列数,*p显示的内容// 输出 : 无//*********************************************************************** void zhifuchuan16(unsigned char hang,unsigned char lie,char *p){unsigned char a=0,i=0;if(lie>8) lie=1;switch(hang){case 1: a=0x80;break;case 2: a=0x90;break;case 3: a=0x88;break;case 4: a=0x98;break;}a=a+lie-1;delay(5);write_com(a);delay(5);while(1){if((i/2+lie)>8) break;if(*p=='\0') break;write_data(*p);p++;i++;}GPIOPinWrite(lcd_PORT , lcd_PINS, 0xff);//IO1PIN=IO1PIN&0xff00ffff|0x00010000;}//********************************************************************//* 名称 : DisStr8()//* 功能 : 12864显示8*16字符串函数//* 输入 : hang显示的行数,lie显示的列数,*p显示的内容//* 输出 : 无//***********************************************************************/void zhifuchuan8(unsigned char hang,unsigned char lie,char *p){unsigned char a,i=0;if(lie<1) lie=1;if(lie>16) lie=16;lie=lie-1;if(hang==1) a=0x80;if(hang==2) a=0x90;if(hang==3) a=0x88;if(hang==4) a=0x98;a=a+lie/2;write_com(a);if(lie%2==1) write_data(0x20);while(1){if((i+lie)>15) break;if(*p=='\0') break;write_data(*p);p++;i++;}//IO1PIN=IO1PIN&0xff00ffff|0x00010000;}/********************************************************************* 名称 : DisChar()* 功能 : 显示单个数字字符函数* 输入 : hang显示的行数,lie显示的列数,sign显示的内容* 输出 : 无***********************************************************************/void DisChar(unsigned char hang,unsigned char lie,unsigned int sign){unsigned char a;if(lie<1) lie=1;if(lie>16) lie=16;lie=lie-1;if(hang==1) a=0x80;if(hang==2) a=0x90;if(hang==3) a=0x88;if(hang==4) a=0x98;a=a+lie/2;write_com(a);if(lie%2==1) write_data(0x20);write_data(sign+0x30);//IO1PIN=IO1PIN&0xff00ffff|0x00010000;}/* 名称 : DisNum()* 功能 : 显示单个数字字符函数* 输入 : hang显示的行数,lie显示的列数,sign显示的内容* 输出 : 无***********************************************************************/void DisNum(unsigned char hang,unsigned char lie,unsigned int num1,unsigned int num2){unsigned char a;if(lie<1) lie=1;if(lie>16) lie=16;lie=lie-1;if(hang==1) a=0x80;if(hang==2) a=0x90;if(hang==3) a=0x88;if(hang==4) a=0x98;a=a+lie/2;write_com(a);if(lie%2==1) write_data(0x20);write_data(num1+0x30);write_data(num2+0x30);//IO1PIN=IO1PIN&0xff00ffff|0x00010000;}/********************************************************************* 名称 : DisImg(uint xs,uint ys,uint xe,uint ye,uchar *img)* 功能 : 显示图片 xs为图片显示的起始横坐标,xs=1-16xe为图片显示的结束横坐标,xe=2-17宽单位为8个像素点,图片大小必须为的宽必须为8的倍数,且小于128,如宽为16时,xe-xs=2 即宽度为2*8=16个像素点ys为图片显示的起始纵坐标,ys=1-64ye为图片显示的结束纵坐标,ye=2-65高单位为1个像素,图片高小于64,如高为19,ye-ys=19 即高度为 19个像素点* 输入 : 无* 输出 : 无***********************************************************************/void DisImg(unsigned int xs,unsigned int ys,unsigned int xe,unsigned int ye,unsigned char *img){unsigned int j=0;unsigned char x,y,xxs,xxe,i=0,k=0;xs-=1;ys-=1;xe-=1;ye-=1;xxs=xs/2;xxe=xe/2;for(y=ys;y<=ye;y++){for(x=xxs;x<xxe;x++){if(y>=32) i=8,k=32;write_com(0x36); //8位数据总线,扩展指令集,绘图显示开write_com(y+0x80-k); //行地址write_com(x+0x80+i); //列地址write_com(0x30);if(xs%2==1) write_data(0x00);write_data(img[j++]);write_data(img[j++]);}}}/********************************************************************* 名称 : CLR()* 功能 : 清屏* 输入 : 无* 输出 : 无***********************************************************************/void CLR(){write_com(0x01);delay(1);}/********************************************************************/********************************************************************* 名称 : CLRGDRAM()* 功能 : 清整个GDRAM空间* 输入 : 无* 输出 : 无***********************************************************************/void CLRGDRAM(){unsigned char x,y,i;CLR();zhifuchuan16(1,1," ");for(i=0;i<9;i+=8) //0时上半屏,8时下半屏for(y=0;y<32;y++) //列地址(0~32) (0~32)for(x=0;x<8;x++) //行地址(0~7) (8~15){write_com(0x36); //8位数据总线,扩展指令集,绘图显示开 write_com(y+0x80); //行地址write_com(x+0x80+i); //列地址write_com(0x30);write_data(0x00);write_data(0x00);}CLR();}//***********************************闪烁******************************************************//// void shanshuo ()//{// write_com(0x02);// write_com(0x0e);void LCD_set_xy( unsigned char hang, unsigned char lie ){unsigned char a=0,i=0;if(lie>8) lie=1;switch(hang){case 1: a=0x80;break;case 2: a=0x90;break;case 3: a=0x88;break;case 4: a=0x98;break;}a=a+lie-1;delay(5);write_com(a);}void LCD_falsh(unsigned char hang,unsigned char lie,unsigned char falsh){LCD_set_xy( hang, lie );if(falsh)write_com(0x0e);}//**************************************************************************** //*火影图片*///*-- 宽度x高度=128x64 --*/unsigned char BMP2[]={0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF ,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF ,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF ,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF ,0XFC,0X00,0X00,0X03,0XFF,0XFF,0XF1,0X33,0X3F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFE,0X3F ,0XFC,0X00,0X00,0X40,0X3E,0XFC,0X00,0X10,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFE,0X7F ,0XFC,0X00,0X00,0X40,0X38,0X00,0X00,0X01,0XC3,0XFF,0XFF,0XFF,0XF8,0X00,0XFF,0X7F ,0XFC,0X00,0X00,0XC0,0X50,0X27,0XFE,0X00,0X07,0XFF,0XFF,0XC0,0X00,0X00,0X7F,0X3F ,0XFC,0X00,0X00,0XC0,0X11,0XFF,0XFE,0X00,0X0F,0XFF,0X00,0X00,0X00,0X00,0X2F,0X3F ,0XFC,0X00,0X00,0XC0,0X00,0XF7,0XFE,0X00,0X1F,0XF8,0X03,0XFF,0XFF,0XF8,0X23,0XBF ,0XFC,0X00,0X01,0XC0,0X00,0XF7,0XFE,0X80,0X3F,0XF0,0XFF,0XFF,0XFF,0XF4,0X11,0XBF ,0XFC,0X00,0X01,0XC0,0X01,0XFF,0XFE,0X01,0X3F,0X61,0X7F,0XFF,0XCF,0XFC,0X00,0XFF ,0XFC,0X00,0X01,0XC0,0X00,0XF9,0XFE,0X00,0XEE,0X23,0X3F,0XF8,0X1F,0XFC,0X00,0X3F ,0XFC,0X00,0X01,0XD0,0X00,0XFF,0X80,0XE4,0X0C,0X03,0X3F,0XF7,0XFF,0XFC,0X00,0X3F ,0XFC,0X00,0X01,0XC0,0X00,0X00,0X00,0XF5,0X0A,0X03,0X3F,0XEC,0X3F,0XF8,0X00,0X3F ,0XFC,0X00,0X01,0X80,0X02,0X01,0X03,0X79,0X16,0X02,0X3F,0XE9,0X3F,0XF8,0X00,0X3F ,0XFC,0X00,0X00,0X00,0X03,0X07,0X66,0XFB,0X14,0X02,0X7F,0XCB,0X5F,0XFC,0X00,0X3F ,0XFC,0X00,0X00,0X00,0X03,0X87,0XFF,0XFF,0X20,0X02,0X7F,0XCC,0X5F,0XFC,0X00,0X3F ,0XFC,0X00,0X00,0X00,0X03,0XDF,0XFF,0XF0,0X00,0X03,0X7F,0XA7,0X9F,0XFC,0X00,0X3F ,0XFC,0X00,0X00,0X00,0X01,0XFF,0XFF,0XF0,0X00,0X03,0X7F,0XA0,0X3F,0XF0,0X00,0X3F ,0XFC,0X00,0X00,0X00,0X01,0XFF,0XFF,0XD0,0X40,0X01,0X7F,0XFD,0XFF,0XF4,0X01,0XBF ,0XFC,0X00,0X00,0X00,0X01,0XFF,0XFF,0XF0,0X00,0X01,0X7F,0XFF,0XFD,0XF8,0X01,0X3F ,0XFC,0X00,0X00,0X00,0X00,0XFF,0XFF,0XC0,0X00,0X00,0X7F,0XFF,0XF0,0X00,0X02,0X3F ,0XFC,0X00,0X00,0X00,0X00,0XF9,0X7F,0XE0,0X03,0X00,0X00,0X00,0X00,0X00,0X0C,0XBF ,0XFC,0X00,0X00,0X00,0X00,0X7D,0XFF,0X80,0X01,0X80,0X00,0X00,0X00,0X0F,0XE8,0X3F ,0XFC,0X00,0X00,0X00,0X00,0X7F,0XFF,0X00,0X00,0XA8,0X00,0X00,0X02,0X03,0XE1,0XBF ,0XFC,0X00,0X00,0X00,0X00,0X3E,0X30,0X00,0X03,0X4F,0X81,0XFF,0XFC,0X01,0XE1,0XBF ,0XFC,0X00,0X00,0X00,0X00,0X0F,0XE0,0X00,0X03,0X0F,0X00,0XFF,0XC4,0X45,0XE1,0XBF ,0XFC,0X00,0X00,0X00,0X00,0X1F,0X00,0X00,0X03,0X1F,0X40,0X47,0XEC,0X0F,0XE9,0XBF ,0XFC,0X00,0X00,0X00,0X00,0X30,0X00,0X00,0X03,0X0F,0X40,0X6F,0XFE,0X0F,0XF9,0XBF ,0XFC,0X00,0X00,0X00,0X00,0X20,0X00,0X00,0X03,0X0F,0XC3,0XFF,0XFF,0X0F,0XF3,0X3F ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X3F,0XE0,0XFF,0XFF,0XDF,0XE3,0X3F ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1F,0XFB,0XFF,0XFF,0XFF,0XE6,0X3F ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X8F,0XFF,0XFF,0XFF,0XFF,0XCC,0X3F ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XC7,0XFF,0XFF,0XFF,0XFF,0XCC,0X3F ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X77,0XFF,0XFF,0XFF,0XFF,0XDC,0X3F ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X37,0XFF,0XFF,0XFF,0XFF,0X18,0X3F ,0XFC,0X00,0X00,0X00,0X02,0X00,0X00,0X00,0X00,0X33,0XFF,0XFF,0XFF,0XFF,0XB8,0X3F ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X13,0XFF,0XFF,0XFF,0XFF,0XFE,0X3F ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X07,0XFF,0XFF,0XFF,0XFF,0XFF,0X3F ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1D,0XFF,0XFF,0XFF,0XFF,0X3F,0XBF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X1F,0XFF,0XFD,0X3F,0XFF,0X7F,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X3C,0XFF,0XFC,0X3F,0XFF,0X7F,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XFC,0XFF,0XFE,0X7F,0XFE,0X7F,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XF8,0X7F,0XFF,0XFF,0XFC,0X4F,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0XF8,0X3F,0XFF,0XFF,0XF8,0X4F,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF8,0X1F,0XFF,0XFF,0XF9,0X07,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF0,0X0F,0XFF,0XFF,0XE7,0X07,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF8,0X07,0XFF,0XFF,0XC3,0X07,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XF8,0X63,0XFF,0XFF,0X81,0X0F,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFC,0X50,0XFF,0XFE,0X00,0X0F,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFC,0X40,0X3F,0XFC,0X00,0X1F,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFC,0X41,0X0F,0XF0,0X00,0X3F,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFE,0X01,0XC0,0X00,0X38,0X7F,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0X27,0XF0,0X00,0X7C,0XFF,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XA7,0XFC,0X00,0XFF,0XFF,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XE7,0XFF,0XFE,0XFF,0XFF,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XF7,0XFF,0XFD,0XFF,0XFF,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XFF,0XFF,0XFC,0XFF,0XFF,0XFF ,0XFC,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XFF,0XFE,0X3F,0X7F,0XFF,0XFF ,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF ,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF ,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF ,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF ,};。

相关文档
最新文档