/********************************************************** ILI9325 8位 240X320液晶屏 例程序 **********************************************************/ #include //C51单片机程序 #include "Font8x16.h" //8X16 字母 数字 符号 #include "GB1616.h" //16*16汉字字模 /********************************************************** 液晶屏 16位 引脚定义 **********************************************************/ #define DataBusH P2 //高8位 并行数据口 //#define DataBusL P0 //底8位 并行数据口 sbit LCD_CS= P1^0; //片选 sbit LCD_RS= P1^1; //数据/命令选择 sbit LCD_WR= P1^2; //写数据 sbit LCD_RD= P1^3; //读数据 sbit LCD_RES=P1^4; //复位 /********************************************************** 时间延时函数 **********************************************************/ void delayms(unsigned int count) { unsigned int i,j; for(i=0;i>8,dataa); } /********************************************************** 写寄存器 写地址/参数 **********************************************************/ void adderset(int xs,int xe,int ys,int ye) { send_host_reg_command(0x0046,xe); send_host_reg_command(0x0047,xs); send_host_reg_command(0x0048,ye); send_host_reg_command(0x0049,ys); // send_host_reg_command(0x0022,PixelColor); // // Lcd_Write_Cmd(0x00,0x50); Lcd_Write_Data(xs>>8,xs); //hs // Lcd_Write_Cmd(0x00,0x51); Lcd_Write_Data(xe>>8,xe); //he // Lcd_Write_Cmd(0x00,0x52); Lcd_Write_Data(ys>>8,ys); //vs // Lcd_Write_Cmd(0x00,0x53); Lcd_Write_Data(ye>>8,ye); //ve // // Lcd_Write_Cmd(0x00,0x20); Lcd_Write_Data(xs>>8,xs); //h // Lcd_Write_Cmd(0x00,0x21); Lcd_Write_Data(ys>>8,ys); //v Lcd_Write_Cmd(0x00,0x22);//LCD_WriteCMD(GRAMWR); } /********************************************************** 显示 中文 汉字 **********************************************************/ void PutGB1616(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor,unsigned int bColor) { unsigned int i,j,k; adderset(x,x+16-1,y,y+16-1); //设定 内部 X,Y轴 寄存器 for (k=0;k<64;k++) { //64标示自建汉字库中的个数,循环查询内码 if((GB_16[k].Index[0]==c[0])&&(GB_16[k].Index[1]==c[1])){ for(i=0;i<32;i++) { unsigned short m=GB_16[k].Msk[i]; for(j=0;j<8;j++) { if((m&0x80)==0x80) Lcd_Write_Data(fColor>>8,fColor); else Lcd_Write_Data(bColor>>8,bColor); m<<=1; } } }}} void LCD_wenzhi(unsigned short x, unsigned short y, unsigned char *s, unsigned int fColor, unsigned int bColor) { unsigned char l=0; while(*s){ PutGB1616(x+l*8,y,(unsigned char*)s,fColor,bColor);s+=2;l+=2; } } /********************************************************** 显示 字母 数字 符号 **********************************************************/ void LCD_PutChar8x16(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor) { unsigned int i,j; adderset(x,x+8-1,y,y+16-1); //设定 内部 X,Y轴 寄存器 for(i=0; i<16;i++) { unsigned char m=Font8x16[c*16+i]; for(j=0;j<8;j++) { if((m&0x80)==0x80) Lcd_Write_Data(fColor>>8,fColor); else Lcd_Write_Data(bColor>>8,bColor); m<<=1; } } } void LCD_zhifu(unsigned short x, unsigned short y, unsigned char *s, unsigned int fColor, unsigned int bColor) { unsigned char l=0; while(*s) { if( *s < 0x80) { LCD_PutChar8x16(x+l*8,y,*s,fColor,bColor); s++;l++; } } } /********************************************************** 显示 变量数字 **********************************************************/ void LCD_shuzi(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor) { unsigned int i,j; adderset(x,x+8-1,y,y+16-1); //设定 内部 X,Y轴 寄存器 for(i=0; i<16;i++) { unsigned char m=SSZZ[c][i]; for(j=0;j<8;j++) { if((m&0x80)==0x80) Lcd_Write_Data(fColor>>8,fColor); else Lcd_Write_Data(bColor>>8,bColor); m<<=1; } } } /********************************************************** 写入图片 函数(X 起始轴,X 结束轴 , Y 起始轴,Y 结束轴 , 数组库) **********************************************************/ void LCD_TEST_JPG(int x1,int x2,int y1,int y2,unsigned char *id) { unsigned char i,j,pixH,pixL; adderset(x1,x2-1,y1,y2-1); //设定 内部 X,Y轴 寄存器 id++; //取模软件 进一位 for(i=0;i>8,RPG); } /********************************************************** 刷全屏刷色 **********************************************************/ void LCD_TEST_SingleColor(unsigned int RPG) { int i,j; // adderset(0,240,0,320);//320x240 send_host_reg_command(0x0046,0x00EF); //Horizontal end send_host_reg_command(0x0047,0x0000);// Horizontal start send_host_reg_command(0x0048,0x01AF);//Vertical end send_host_reg_command(0x0049,0x0000); //Vertical start send_host_reg_command(0x0000,0x0022); for (i=0;i<320;i++) for (j=0;j<240;j++) Lcd_Write_Data(0,0); // Lcd_Write_Data(RPG>>8,RPG); } /********************************************************** ILI9325 内部寄存器 初始化 **********************************************************/ void LCD_ILI9325_INT(void) { LCD_CS=1; delayms(50); LCD_RES=0;delayms(100); LCD_RES=1;delayms(1000); //*********************************************Start intial Sequence delayms(50); Lcd_Write_Cmd(0,0x0024); delayms(60); send_host_reg_command (0x0007,0x0110); send_host_reg_command (0x0001,0x0136); send_host_reg_command (0x0002,0x0000); send_host_reg_command (0x0003,0x1000); send_host_reg_command (0x0008,0x0072); send_host_reg_command (0x000B,0x3300); send_host_reg_command (0x000C,0x0000); send_host_reg_command (0x000F,0x0D01); delayms(50); send_host_reg_command (0x0080,0x0101); delayms(50); send_host_reg_command (0x0011,0x0000); send_host_reg_command (0x0012,0x0000); send_host_reg_command (0x0013,0x0000); send_host_reg_command (0x0014,0x0000); delayms(20); send_host_reg_command (0x0011,0x0010); send_host_reg_command (0x0012,0x3222); send_host_reg_command (0x0013,0x2060); send_host_reg_command (0x0014,0x004F); send_host_reg_command (0x0010,0x0700); delayms(20); send_host_reg_command (0x0011,0x0112); delayms(15); send_host_reg_command (0x0011,0x0312); delayms(15); send_host_reg_command (0x0011,0x0712); delayms(10); send_host_reg_command (0x0011,0x0F1C); delayms(30); send_host_reg_command (0x0011,0x0F3B); delayms(40); send_host_reg_command (0x0015,0x0010); send_host_reg_command (0x0040,0x0000); send_host_reg_command (0x0046,0x00EF); send_host_reg_command (0x0047,0x0000); send_host_reg_command (0x0048,0x01AF); send_host_reg_command (0x0049,0x0000); // Gamma (R) send_host_reg_command (0x0050,0x0204); send_host_reg_command (0x0051,0x0402); send_host_reg_command (0x0052,0x0A01); send_host_reg_command (0x0053,0x010A); send_host_reg_command (0x0054,0x0A00); send_host_reg_command (0x0055,0x0300); send_host_reg_command (0x0056,0x000F); send_host_reg_command (0x0057,0x000F); send_host_reg_command (0x0058,0x000E); send_host_reg_command (0x0059,0x000D); delayms(30); send_host_reg_command (0x0007,0x0116); delayms(60); send_host_reg_command (0x0007,0x0117); delayms(15); delayms(50); send_host_reg_command(0x0000,0x0022); } /********************************************************** 主函数 **********************************************************/ void main(void) { unsigned int ID; LCD_CS=1; delayms(50); LCD_RES=0;delayms(100); LCD_RES=1;delayms(1000); ID=LCD_READ_ID(); //读出 液晶屏 IC的ID LCD_ILI9325_INT(); //寄存器 初始化 LCD_TEST_SingleColor(0x0); //刷白屏 //高8底8位 颜色总和 0x0000(黑)0xffFF(白) LCD_Color_with_ADD(0,239,0,435,0x00); //局部刷色(x1,x2,y1,y2,0x00,0xff) delayms(1000); LCD_Color_with_ADD(0,239,0,435,0xf800); delayms(100); LCD_Color_with_ADD(0,239,0,435,0x07e0); delayms(100); LCD_Color_with_ADD(0,239,0,435,0x001f); delayms(100); // LCD_TEST_JPG(90,150,110,180,ABC); // //写入图片(X 起始轴,X 结束轴 , Y 起始轴,Y 结束轴 , 数组库) // LCD_wenzhi(20,200,"深圳市",0x07e0,0xf800); // LCD_wenzhi(68,200,"宏",0x07e0,0xf800); // LCD_wenzhi(84,200,"捷",0x07e0,0xf800); // LCD_wenzhi(100,200,"百",0x07e0,0xf800); // LCD_wenzhi(116,200,"鑫",0x07e0,0xf800); // LCD_wenzhi(132,200,"科技有限公司",0x07e0,0xf800); // LCD_zhifu(50,250,"0 1 2 3 4 5 6 7 8 9",0x001f,0xf800); // LCD_zhifu(10,280,"abcdefghijklmnopqistuvwxyz",0x001f,0xf800); // LCD_zhifu(15,300,"`,./<>';:[]{}\|?)(-=+*&^%$",0x001f,0xf800); ///* // LCD_shuzi(20,20,0,0x0000,0xffff); //写入变量 数字 // LCD_shuzi(30,20,1,0x0000,0xffff); //写入变量 数字 // LCD_shuzi(40,20,2,0x0000,0xffff); //写入变量 数字 // LCD_shuzi(50,20,3,0x0000,0xffff); //写入变量 数字 // LCD_shuzi(60,20,4,0x0000,0xffff); //写入变量 数字 // LCD_shuzi(70,20,5,0x0000,0xffff); //写入变量 数字 ///*******************显示液晶屏ID*******************************/ // LCD_zhifu(20,20,"ID ILI",0xf800,0xffff); //显示 ID 字母 // LCD_shuzi(80,20,(ID>>8)/16,0xf800,0xffff); //写入变量 数字 // LCD_shuzi(90,20,(ID>>8)%16,0xf800,0xffff); //写入变量 数字 // LCD_shuzi(100,20,(ID<<8)%255/16,0xf800,0xffff); //写入变量 数字 // LCD_shuzi(110,20,(ID<<8)%255%16,0xf800,0xffff); //写入变量 数字 // LCD_shuzi(150,20,8,0xf800,0xffff); //写入变量 数字 // LCD_wenzhi(170,20,"位",0xf800,0xffff); //写入中文 // LCD_TEST_SingleColor(0xffff);delayms(3000); //白 // LCD_TEST_SingleColor(0x0000);delayms(3000); //黑 // LCD_TEST_SingleColor(0xf800);delayms(3000); //红 // LCD_TEST_SingleColor(0x07e0);delayms(3000); //绿 // LCD_TEST_SingleColor(0x001f);delayms(3000); //蓝 // LCD_TEST_SingleColor(0xffe0);delayms(3000); //黄 // LCD_TEST_SingleColor(0x07ff);delayms(3000); //青 // LCD_TEST_SingleColor(0xf81f);delayms(3000); //粉 while(1); } /********************************************************** ILI9325 16位 240X320液晶屏 例程序 **********************************************************/