Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
sbit CS=P2^5; //Chip selectsbit RES=P2^7; //Resetsbit RS=P2^4; //Data / command selectsbit RW=P2^3; // Data port using the P0
void main(){TRISB = 0; // Configure PORTB as outputPORTB = 0xAA; // Turn on odd numbered port pins}
//===================== Write data ===========================//void Write_Data(unsigned char DH,unsigned char DL){ CS=0; RS=1; P1=DH; RW=0; RW=1; P1=DL; RW=0; RW=1; CS=1;}
#include"reg52.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 0xFFE0sbit CS=P2^5; //Chip selectsbit RES=P2^7; //Resetsbit RS=P2^4; //Data / command selectsbit RW=P2^3; // Data port using the P0//====================================================//void main (void);void ILI9325_Initial(void);void show_colour_bar (void);void Write_Cmd_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){ CS=1; delayms(5); RES=0; delayms(5); RES=1; delayms(5); ILI9325_Initial(); while(1) { ClearScreen(0x0);//show_colour_bar(); LCD_PutString(2,40,"http://shop58797699.taobao.com/",Red,Blue); ///Foreground color and background color, can be directly pre-defined, it can fill in 16 hexadecimal numbersLCD_PutString(40,60,"I LOVE MY JOB ",Blue2,Yellow);LCD_PutString(40,80,"Yao Shuo ElectronicMagenta,Green);LCD_PutString(40,100,"Professional technical support forum",0x07e0,0xf800);LCD_PutString(40,120,"Professional Development Board",0xF800,Yellow);LCD_PutString(40,140,"1234567890",0xF800,Yellow);LCD_PutString(20,160,"abcdefghijklmnopqistuvwxyz",0xF800,Yellow);LCD_PutString(20,180,"`,./<>';:[]{}\|?)(-=+*&^%$",0xF800,Yellow);PutGB3232(20,200,"Love",Blue,Yellow); //32x32 Chinese characters to writePutGB3232(60,200,"Single",Blue,Red);PutGB3232(100,200,"red",Blue,Magenta);PutGB3232(140,200,"bye",Blue,Green);PutGB3232(180,200,"hi",Blue,Cyan); PutGB3232(20,240,"come",Blue,0X00); PutGB3232(60,240,"go",Blue,0X00); PutGB3232(100,240,"dind",Blue,0X00); PutGB3232(140,240,"bund",Blue,0X00); PutGB3232(180,240,"shang",Blue,0X00);PutGB3232(20,280,"chik",Blue,0X00); PutGB3232(60,280,"chap",Blue,0X00); PutGB3232(100,280,"sa ",Blue,0X00); PutGB3232(140,280,"pu",Blue,0X00); PutGB3232(180,280,"ra",Blue,0X00); // show_photo(); while(1); }}void ClearScreen(unsigned int bColor){unsigned int i,j;LCD_SetPos(0,240,0,320);//320x240for (i=0;i<320;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;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 character fontvoid PutGB1616(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor,unsigned int bColor){ unsigned int i,j,k; LCD_SetPos(x, x+16-1,y, y+16-1); for (k=0;k<64;k++) { // 64 marked the number of self in Chinese characters library, circulation check inner code) 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[i]; 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 character fontvoid PutGB3232(unsigned short x, unsigned short y, unsigned char c[2], unsigned int fColor,unsigned int bColor){ unsigned int i,j,k; LCD_SetPos(x, x+32-1,y, y+32-1); for (k=0;k<15;k++) { //15 mark in the number of Chinese characters library self, loop the query code 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[i]; 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; } } }//==================== R G B color display ====================//void Show_RGB (unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1,unsigned int Color){ unsigned int i,j; //address_set(); LCD_SetPos(x0,x1,y0,y1); for (i=y0;i<=y1;i++) { for (j=x0;j<=x1;j++) Write_Data_U16(Color); }}//====================== Display Color ======================//void show_colour_bar (void){ int V,H; LCD_SetPos(0,240,0,320);//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 show_photo(void){ unsigned char j; unsigned int i; unsigned long s=0; LCD_SetPos(0,240,0,320);//320x240 for (i=0;i<75;i++) { for (j=0;j<240;j++) Write_Data(0xff,0xff); } for (i=0;i<170;i++) { for (j=0;j<55;j++) Write_Data(0xff,0xff); for (j=0;j<130;j++) Write_Data(pic[s++],pic[s++]); for (j=0;j<55;j++) Write_Data(0xff,0xff); } for (i=0;i<75;i++) { for (j=0;j<240;j++) Write_Data(0xff,0xff); } }//=======================================================//void Write_Cmd_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);}//====================== Write command ==========================//void Write_Cmd(unsigned char DH,unsigned char DL){ CS=0; RS=0; P1=DH; RW=0; RW=1; P1=DL; RW=0; RW=1; CS=1;}//===================== Write data ===========================//void Write_Data(unsigned char DH,unsigned char DL){ CS=0; RS=1; P1=DH; RW=0; RW=1; P1=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++); } }//===================== Initialization code =======================//void ILI9325_Initial(void){ //############# void Power_Set(void) ################//Write_Cmd_Data(0x0000,0x0001);delayms(100);Write_Cmd_Data(0x0015,0x0030);Write_Cmd_Data(0x0011,0x0040);Write_Cmd_Data(0x0010,0x1628);Write_Cmd_Data(0x0012,0x0000);Write_Cmd_Data(0x0013,0x104d);delayms(100);Write_Cmd_Data(0x0012,0x0010);delayms(100);Write_Cmd_Data(0x0010,0x2620);Write_Cmd_Data(0x0013,0x344d); //304ddelayms(100);Write_Cmd_Data(0x0001,0x0100);Write_Cmd_Data(0x0002,0x0300);Write_Cmd_Data(0x0003,0x1030);Write_Cmd_Data(0x0008,0x0604);Write_Cmd_Data(0x0009,0x0000);Write_Cmd_Data(0x000A,0x0008);Write_Cmd_Data(0x0041,0x0002);Write_Cmd_Data(0x0060,0x2700);Write_Cmd_Data(0x0061,0x0001);Write_Cmd_Data(0x0090,0x0182);Write_Cmd_Data(0x0093,0x0001);Write_Cmd_Data(0x00a3,0x0010);delayms(50);//################# void Gamma_Set(void) ####################//Write_Cmd_Data(0x30,0x0000); Write_Cmd_Data(0x31,0x0502); Write_Cmd_Data(0x32,0x0307); Write_Cmd_Data(0x33,0x0305); Write_Cmd_Data(0x34,0x0004); Write_Cmd_Data(0x35,0x0402); Write_Cmd_Data(0x36,0x0707); Write_Cmd_Data(0x37,0x0503); Write_Cmd_Data(0x38,0x1505); Write_Cmd_Data(0x39,0x1505);delayms(50);//################## void Display_ON(void) ####################//Write_Cmd_Data(0x0007,0x0001);delayms(50);Write_Cmd_Data(0x0007,0x0021);Write_Cmd_Data(0x0007,0x0023);delayms(50);Write_Cmd_Data(0x0007,0x0033);delayms(50);Write_Cmd_Data(0x0007,0x0133);}/*===========================================================*//*************************************************************Function name: LCD_DefineDispWindowFunction: define display formParameters: x0: X coordinate in the form of the smallerx1: X coordinate in the form of the greatery0: Y coordinates form the smallery1: Y coordinates form the greaterReturn Value: None*************************************************************/static void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1){ Write_Cmd_Data(WINDOW_XADDR_START,x0); Write_Cmd_Data(WINDOW_XADDR_END,x1); Write_Cmd_Data(WINDOW_YADDR_START,y0); Write_Cmd_Data(WINDOW_YADDR_END,y1); Write_Cmd_Data(GRAM_XADDR,x0); Write_Cmd_Data(GRAM_YADDR,y0); Write_Cmd (0x00,0x22);//LCD_WriteCMD(GRAMWR);}