9325改横屏不成功。显示有问题。谁帮忙看一下。或者能给个横屏的驱动看一下。谢谢了
[复制链接]
坚屏显示是没问题的。 但改成了横屏之后就显示不正常,不知是那里没改好。
#include"STC_NEW_8051.H"
#define WINDOW_XADDR_START 0x0050 // Horizontal Start Address Set #define WINDOW_XADDR_END 0x0051 // Horizontal End Address Set #define WINDOW_YADDR_START 0x0052 // Vertical Start Address Set #define WINDOW_YADDR_END 0x0053 // Vertical End Address Set #define GRAM_XADDR 0x0020 // GRAM Horizontal Address Set #define GRAM_YADDR 0x0021 // GRAM Vertical Address Set #define GRAMWR 0x0022 // memory write
/* LCD color */ #define White 0xFFFF #define Black 0x0000 #define Blue 0x001F #define Blue2 0x051F #define Red 0xF800 #define Magenta 0xF81F #define Green 0x07E0 #define Cyan 0x7FFF #define Yellow 0xFFE0
sbit CS=P3^3; //片选 sbit RES=P4^5; //复位 sbit RS=P5^2; //数据/命令选择 sbit RW=P1^3; //sbit RD=P1^4; //数据口使用P1 //====================================================//
void main (void); void ILI9325_Initial(void); void show_colour_bar (void); void Init_data(unsigned char x, unsigned int y); void Write_Cmd(unsigned char DH,unsigned char DL); void Write_Data(unsigned char DH,unsigned char DL); void delayms(unsigned int tt); void show_photo(void); void Show_RGB (unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1,unsigned int Color); unsigned char code pic[]; void Write_Data_U16(unsigned int y); static void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1); void ClearScreen(unsigned int bColor); void LCD_PutChar8x16(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor); void LCD_PutChar(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor); void LCD_PutString(unsigned short x, unsigned short y, char *s, unsigned int fColor, unsigned int bColor);
void LCD_PutChar8x8(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor); void PutGB1616(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor,unsigned int bColor); void PutGB3232(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor,unsigned int bColor); //================================================//
void main(void) { unsigned char x; unsigned char y; P4SW|=0x70; CS=1; delayms(5); RES=0; delayms(5); RES=1; delayms(5); ILI9325_Initial(); while(1) { ClearScreen(White); LCD_PutString(0,0,"https://bbs.eeworld.com.cn",Red,Green); ///前景颜色和背景颜色,可以直接预定义,也可以直接填入16进制数字 LCD_PutString(0,32,"abcdmmmmsss",Red,Green); LCD_PutString(16,64,"电子网",Red,Green); LCD_PutString(16,96,"电子科技有限公司",Red,Green); LCD_PutString(16,128,"abcdefghijklmnopqistuvwxyz",Red,Green); LCD_PutChar8x16(8,160,'h',Red,Green); LCD_PutChar8x16(24,160,'m',Red,Green); LCD_PutChar8x16(40,160,'w',Red,Green); LCD_PutChar8x16(56,160,'a',Red,Green); LCD_PutChar8x16(72,160,'E',Red,Green); while(1); } }
void ClearScreen(unsigned int bColor) { unsigned int i,j; LCD_SetPos(0,320,0,240);//320x240 for (i=0;i<325;i++) { for (j=0;j<240;j++) Write_Data_U16(bColor); } }
///////////////////////////////////////////////////////////// #include "8X16.h" void LCD_PutChar8x16(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor) { unsigned int i,j; x=312-x; LCD_SetPos(x,x+8-1,y,y+16-1); for(i=0; i<16;i++) { unsigned char m=Font8x16[c*16+i]; for(j=0;j<8;j++) { if((m&0x80)==0x80) { Write_Data_U16(fColor); } else { Write_Data_U16(bColor); } m<<=1; } } }
void LCD_PutChar(unsigned short x, unsigned short y, char c, unsigned int fColor, unsigned int bColor) { LCD_PutChar8x16( x, y, c, fColor, bColor ); }
#include "GB1616.h" //16*16汉字字模
void PutGB1616(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor,unsigned int bColor) { unsigned int i,j,k; x=304-x; LCD_SetPos(x, x+16-1,y, y+16-1); Write_Data_U16(fColor);
for (k=0;k<64;k++) { //64标示自建汉字库中的个数,循环查询内码 if ((codeGB_16[k].Index[0]==c[0])&&(codeGB_16[k].Index[1]==c[1])) { for(i=0;i<32;i++) { unsigned short m=codeGB_16[k].Msk; for(j=0;j<8;j++) { if((m&0x80)==0x80) { Write_Data_U16(fColor); } else { Write_Data_U16(bColor); } m<<=1; } } } } }
#include "GB3232.h" //32*32汉字字模
void PutGB3232(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor,unsigned int bColor) { unsigned int i,j,k; x=288-x; LCD_SetPos(x, x+32-1,y, y+32-1); for (k=0;k<15;k++) { //15标示自建汉字库中的个数,循环查询内码 if ((codeGB_32[k].Index[0]==c[0])&&(codeGB_32[k].Index[1]==c[1])) { for(i=0;i<128;i++) { unsigned short m=codeGB_32[k].Msk; for(j=0;j<8;j++) { if((m&0x80)==0x80) { Write_Data_U16(fColor); } else { Write_Data_U16(bColor); } m<<=1; } } } } }
void LCD_PutString(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_PutChar(x+l*8,y,*s,fColor,bColor); s++;l++; } else { PutGB1616(x+l*8,y,(unsigned char*)s,fColor,bColor); s+=2;l+=2; } } }
//====================== 显示彩条 ======================// void show_colour_bar (void) { int V,H; LCD_SetPos(0,320,0,240);//320x240 for(H=0;H<240;H++) { for(V=0;V<40;V++) Write_Data(0xf8,0x00); } for(H=0;H<240;H++) { for(V=40;V<80;V++) Write_Data(0x07,0xe0); } for(H=0;H<240;H++) { for(V=80;V<120;V++) Write_Data(0x00,0x1f); } for(H=0;H<240;H++) { for(V=120;V<160;V++) Write_Data(0xff,0xe0); } for(H=0;H<240;H++) { for(V=160;V<200;V++) Write_Data(0xf8,0x1f); } for(H=0;H<240;H++) { for(V=200;V<240;V++) Write_Data(0x07,0xff); } for(H=0;H<240;H++) { for(V=240;V<280;V++) Write_Data(0xff,0xff); } for(H=0;H<240;H++) { for(V=280;V<320;V++) Write_Data(0x00,0x00); } }
//=======================================================//
void Init_data (unsigned char x,unsigned int y) { unsigned char m,n; m=y>>8; n=y; Write_Cmd(0x00,x); Write_Data(m,n); }
void Write_Data_U16(unsigned int y) { unsigned char m,n; m=y>>8; n=y; Write_Data(m,n); } //====================== 写命令 ==========================//
void Write_Cmd(unsigned char DH,unsigned char DL) { CS=0; RS=0;
P2=DH; RW=0; RW=1;
P2=DL; RW=0; RW=1; CS=1; }
//===================== 写数据 ===========================//
void Write_Data(unsigned char DH,unsigned char DL) { CS=0; RS=1; P2=DH; RW=0; RW=1;
P2=DL; RW=0; RW=1; CS=1; }
//======================================================= void delayms(unsigned int count) { int i,j; for(i=0;i<count;i++) { for(j=0;j<260;j++); } }
//===================== 初始化代码 =======================// void ILI9325_Initial(void) { ////////////////////////////////////////////////////////// delayms(50); //根据不同晶振速度可以调整延时,保障稳定显示 Init_data(0x0001,0x0100); Init_data(0x0002,0x0700); Init_data(0x0003,0x1018); Init_data(0x0004,0x0000); Init_data(0x0008,0x0207); Init_data(0x0009,0x0000); Init_data(0x000A,0x0000); Init_data(0x000C,0x0000); Init_data(0x000D,0x0000); Init_data(0x000F,0x0000); //power on sequence VGHVGL Init_data(0x0010,0x0000); Init_data(0x0011,0x0007); Init_data(0x0012,0x0000); Init_data(0x0013,0x0000); //vgh Init_data(0x0010,0x1290); Init_data(0x0011,0x0227); //delayms(100); //vregiout Init_data(0x0012,0x001d); //0x001b //delayms(100); //vom amplitude Init_data(0x0013,0x1500); //delayms(100); //vom H Init_data(0x0029,0x0018); Init_data(0x002B,0x000D); //gamma Init_data(0x0030,0x0004); Init_data(0x0031,0x0307); Init_data(0x0032,0x0002);// 0006 Init_data(0x0035,0x0206); Init_data(0x0036,0x0408); Init_data(0x0037,0x0507); Init_data(0x0038,0x0204);//0200 Init_data(0x0039,0x0707); Init_data(0x003C,0x0405);// 0504 Init_data(0x003D,0x0F02); //ram Init_data(0x0050,0x0000); Init_data(0x0051,0x00EF); Init_data(0x0052,0x0000); Init_data(0x0053,0x013F); Init_data(0x0060,0xA700); Init_data(0x0061,0x0001); Init_data(0x006A,0x0000); // Init_data(0x0080,0x0000); Init_data(0x0081,0x0000); Init_data(0x0082,0x0000); Init_data(0x0083,0x0000); Init_data(0x0084,0x0000); Init_data(0x0085,0x0000); // Init_data(0x0090,0x0010); Init_data(0x0092,0x0600); Init_data(0x0093,0x0003); Init_data(0x0095,0x0110); Init_data(0x0097,0x0000); Init_data(0x0098,0x0000); Init_data(0x0007,0x0133); // Init_data(0x0022);//
}
/*===========================================================*/
/************************************************************* 函数名称:LCD_DefineDispWindow 功 能:定义显示窗体 参 数:x0: 窗体中X坐标中较小者 x1: 窗体中X坐标中较大者 y0: 窗体中Y坐标中较小者 y1: 窗体中Y坐标中较大者 返 回 值:无 *************************************************************/ static void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1) {
Init_data(WINDOW_XADDR_START,y0); Init_data(WINDOW_XADDR_END,y1); Init_data(WINDOW_YADDR_START,x0); Init_data(WINDOW_YADDR_END,x1); Init_data(GRAM_XADDR,y0); Init_data(GRAM_YADDR,x0); Write_Cmd (0x00,0x22);//LCD_WriteCMD(GRAMWR); }
|