/***************************************************************************** Company :RICH LCM moudle :2.4"/240*320 MCU :SSD1297 Type :80 system 16-bit bus interface Note :Crystal:40MHz,Vcc=Vci=2.8V /******************************************************************************* Name :SHOW Function : Description :2009-04-08 µ÷تش Modefitied :RDT028C0SA00-Sub LCD Company : Version :V00 ********************************************************************************/ #include #define DBH P2 #define DBL P0 #define P4 0xd8 #define red 0xf800 #define green 0x07e0 #define blue 0x001f #define black 0x0000 #define white 0xffff #define gr 0x7bef #define C 0 #define D 1 unsigned char a; unsigned int pic; bit Delayflag=0; //****************************************************************************** void Initial(void); void writelcm(unsigned int x,bit R); void WriteRegister(unsigned char RegisterName,unsigned int RegisterValue); void FillColour(unsigned int Colour); void FillGray(unsigned int Gray); void FillSkripe(void); void Block(void); void Field(void); void Photo(unsigned char Number); bit KeyScan(void); void AddressSlect(unsigned char Add); void write_xdata(int erom); void Delay(unsigned char i); void dummy(); //****************************************************************************** sbit CS =P1^7; sbit CE1 =P1^3; sbit CE2 =P1^4; sbit OE =P4^0; sbit RS =P1^6; sbit W_R =P3^6; sbit R_D =P3^7; sbit RES =P3^5; sbit A16 =P1^0; sbit A17 =P1^1; sbit A18 =P1^2; sbit G =P1^5; sbit DB0 =P1^4; sbit DB9 =P3^4; sbit Key0 =P3^2; sbit Key1 =P3^3; sbit Key2 =0xda; sbit Key3 =0xdb; void main(void) { TMOD=0x01; Delay(5); G=0; RES=1; Delay(50); RES=0; Delay(10); Initial(); while(1) { for(a=1;a<3;a++) { WriteRegister(0x44, 0xef00); // Horizontal RAM Address WriteRegister(0x45, 0x0000); // Vertical RAM Start Address WriteRegister(0x46, 0x013f); // Vertical GRAM end Address WriteRegister(0x4e, 0x0000); //X GDDRAM WriteRegister(0x4f, 0x0000); //Y GDDRAM writelcm(0x0022,0); switch(a) { case 0:Photo(0);break; case 1:Photo(1);break; case 2:Photo(2);break; case 3:Photo(3);break; case 4:Photo(4);break; case 5:FillColour(black);break; case 6:FillColour(white);break; case 7:FillColour(red);break; case 8:FillColour(green);break; case 9:FillColour(blue);break; case 10:FillGray(white);break; case 11:Field();break; default:break; } Delay(100); } } } //*************************Initial********************************** void Initial(void) { //******************sub lcd initial*************** WriteRegister(0xE5, 0x8000); WriteRegister(0x28, 0x0006); // enable test command WriteRegister(0x07, 0x0021); WriteRegister(0x00, 0x0001); // Start internal OSC Delay(3); WriteRegister(0x07, 0x0023); WriteRegister(0x10, 0x0000); // Sleep mode off Delay(3); WriteRegister(0x07, 0x0033); // Display on WriteRegister(0x01, 0x2b3f); // Driver output control WriteRegister(0x02, 0x0600); // Set to line inversion WriteRegister(0x11, 0x6030); // Entry mode setup WriteRegister(0x03, 0xa6a8); // Step-up factor/cycle setting WriteRegister(0x0f, 0x0000); // Gate scan position start at G0 WriteRegister(0x0e, 0x3100); // Set alternating amplitude of VCOM WriteRegister(0x1e, 0x009f); // Set VcomH voltage WriteRegister(0x0C, 0x0005); // Adjust VCIX2 output voltage WriteRegister(0x0D, 0x0005); // Set amplitude magnification of VLCD63 WriteRegister(0x0b, 0x5308); // Frame cycle control // ----------- Special command ---------- WriteRegister(0x25, 0xe000); // Frame freq control WriteRegister(0x3f, 0xbb84); // System setting WriteRegister(0x27, 0x0567); // Internal Vcomh/Vcoml timing WriteRegister(0x20, 0x316c); // Internal VCOM strength // ----------- Adjust the Gamma Curve ---------- WriteRegister(0x3a, 0x1000); WriteRegister(0x3b, 0x0008); WriteRegister(0x30, 0x0007); WriteRegister(0x31, 0x0003); WriteRegister(0x32, 0x0300); WriteRegister(0x33, 0x0101); WriteRegister(0x34, 0x0707); WriteRegister(0x35, 0x0002); WriteRegister(0x36, 0x0503); WriteRegister(0x37, 0x0202); WriteRegister(0x3a, 0x1000); WriteRegister(0x3b, 0x0008); //------------------ Set GRAM area --------------- WriteRegister(0x44, 0xef00); // Horizontal RAM Address WriteRegister(0x45, 0x0000); // Vertical RAM Start Address WriteRegister(0x46, 0x013f); // Vertical GRAM end Address WriteRegister(0x4e, 0x0000); WriteRegister(0x4f, 0x0000); WriteRegister(0x48, 0x0000); WriteRegister(0x49, 0x013f); WriteRegister(0x4a, 0xef00); WriteRegister(0x4b, 0x013f); writelcm(0x0022,0); //Write RAM data } //*************************Write command& data************************************** void WriteRegister(unsigned char RegisterName,unsigned int RegisterValue) { G=0; RS=0; CS=0; DBH=0; DBL=RegisterName; DBH=0; DBL=RegisterName; W_R=0; W_R=0; W_R=1; W_R=1; RS=1; DBH=RegisterValue>>8; DBL=RegisterValue; DBH=RegisterValue>>8; DBL=RegisterValue; W_R=0; W_R=0; W_R=1; W_R=1; RS=1; CS=1; } //****************************************************************************** void writelcm(unsigned int data1,bit di) { G=0; RS=di; CS=0; DBH=data1>>8; DBL=data1; DBH=data1>>8; DBL=data1; W_R=0; W_R=0; W_R=1; W_R=1; RS=~di; CS=1; } //****************************************************************************** void write_xdata(int erom)//EXTERNAL DATA WRITE SUB { RS=1;RS=1; CS=0;CS=0; R_D=1;R_D=1; DBL=erom; erom>>=8; DBH=erom; W_R=1;W_R=1; W_R=0;W_R=0; W_R=1;W_R=1; CS=1;CS=1; } //****************************************************************************** /*Function Name ;Key_Test() */ /*Entireness variable :Key_Value */ /*Local variable :None */ /*Description ;This subroutine detects the keyboard and input the value of the key,then return the key value to the program which call it. */ bit KeyScan(void) { Key0=Key1=Key2=Key3=1; if((Key0&&Key1&&Key2&&Key3)!=1) { TH1=0x90;TL1=0;TF1=0;TR1=1;while(TF1==0); //Delay 30ms TF1=0;TR1=0;Key0=Key1=Key2=Key3=1; if((Key0&&Key1&&Key2&&Key3)!=1) { if(Key0==0)a=a<4?a:11; //Photo++ else if(Key1==0) { //Photo-- if((a>=1)&&(a=5)) a-=2; else if(a==0) a=3; else a=3; } else if(Key2==0) a=((a>=5)&&(a<11))?a:4; //Picture++ else if(Key3==0) { //Picture-- if((a>=6)&&(a=12)) a-=2; else if(a==4) a=10; else a=10; } return 1; } } //Keyboard detect faile else return 0; } //****************************************************************************** void Delay(unsigned char times) { unsigned char b; bit key=0; for(;times>0;times--) { b=Delayflag==0?1:20; for(;b>0;b--) { TH0=0x7e;TL0=0x00;TR0=1; do{key=KeyScan();}while((TF0==0)&&(key==0)); //Delay for 10ms TF0=0; if(key==1) { times=1; b=1; } } } TR0=0; Delayflag=key; } //****************************************************************************** void FillColour(unsigned int Colour) { unsigned int x,y; WriteRegister(0x44, 0xef00); // Horizontal RAM Address WriteRegister(0x45, 0x0000); // Vertical RAM Start Address WriteRegister(0x46, 0x013f); // Vertical GRAM end Address WriteRegister(0x4e, 0x0000); //X GDDRAM WriteRegister(0x4f, 0x0000); //Y GDDRAM writelcm(0x0022,C); for(y=0;y<320;y++) { for(x=0;x<240;x++) { writelcm(Colour,1); } } } //****************************************************************************** void FillGray(unsigned int Gray) { unsigned char x,y; unsigned char high; unsigned int decrement; WriteRegister(0x44, 0xef00); // Horizontal RAM Address WriteRegister(0x45, 0x0000); // Vertical RAM Start Address WriteRegister(0x46, 0x013f); // Vertical GRAM end Address WriteRegister(0x4e, 0x0000); //X GDDRAM WriteRegister(0x4f, 0x0000); //Y GDDRAM writelcm(0x0022,C); switch(Gray) { case red:decrement=0x1800;break; case green:decrement=0x00c0;break; case white:decrement=0x18c3;break; case blue:decrement=3;break; default:break; } for(y=0;y<10;y++) { for(high=0;high<32;high++) for(x=0;x<240;x++) { writelcm(Gray,D); } Gray-=decrement; } } //****************************************************************************** void Block(void) { unsigned char x1,y1; unsigned char x2,y2; pic=white; WriteRegister(0x44, 0xef00); // Horizontal RAM Address WriteRegister(0x45, 0x0000); // Vertical RAM Start Address WriteRegister(0x46, 0x013f); // Vertical GRAM end Address WriteRegister(0x4e, 0x0000); //X GDDRAM WriteRegister(0x4f, 0x0000); //Y GDDRAM writelcm(0x0022,C); for(y1=0;y1<10;y1++) { for(y2=0;y2<32;y2++) for(x1=0;x1<8;x1++) { for(x2=0;x2<30;x2++) { writelcm(pic,D); } pic=~pic; } pic=~pic; } } //****************************************************************************** void Field(void) { unsigned int x,y; WriteRegister(0x44, 0xef00); // Horizontal RAM Address WriteRegister(0x45, 0x0000); // Vertical RAM Start Address WriteRegister(0x46, 0x013f); // Vertical GRAM end Address WriteRegister(0x4e, 0x0000); //X GDDRAM WriteRegister(0x4f, 0x0000); //Y GDDRAM writelcm(0x0022,C); for(y=0;y<320;y++) for(x=0;x<240;x++) { if((y==0)||(y==1)||(y==159)||(y==160)||(y==318)||(y==319)) { writelcm(0xffff,1); } else if((x==0)||(x==1)||(x==119)||(x==120)||(x==238)||(x==239)) { writelcm(0xffff,1); } else{writelcm(0x0000,1);} } } //****************************************************************************** void FillSkripe(void) { unsigned int x,y; WriteRegister(0x44, 0xef00); // Horizontal RAM Address WriteRegister(0x45, 0x0000); // Vertical RAM Start Address WriteRegister(0x46, 0x013f); // Vertical GRAM end Address WriteRegister(0x4e, 0x0000); //X GDDRAM WriteRegister(0x4f, 0x0000); //Y GDDRAM writelcm(0x0022,C); for(y=40;y>0;y--) for(x=240;x>0;x--) writelcm(red,1); //Red for(y=40;y>0;y--) for(x=240;x>0;x--) writelcm(green,1); //green for(y=40;y>0;y--) for(x=240;x>0;x--) writelcm(blue,1); //blur for(y=40;y>0;y--) for(x=240;x>0;x--) writelcm(black,1); //black for(y=40;y>0;y--) for(x=240;x>0;x--) writelcm(white,1); //white for(y=40;y>0;y--) for(x=240;x>0;x--) writelcm(0xffe0,1); //red-green for(y=40;y>0;y--) for(x=240;x>0;x--) writelcm(0xf81f,1); //red-blue for(y=40;y>0;y--) for(x=240;x>0;x--) writelcm(0x07ff,1); //blue-green } //****************************************************************************** void AddressSlect(unsigned char Add) { switch(Add) { case 0:{A18=0;A17=0;A16=0;pic=0x0000;};break; case 1:{A18=0;A17=0;A16=1;pic=0x2c00;};break; case 2:{A18=0;A17=1;A16=0;pic=0x5800;};break; case 3:{A18=0;A17=1;A16=1;pic=0x8400;};break; case 4:{A18=1;A17=0;A16=0;pic=0xb000;};break; case 5:{A18=1;A17=0;A16=1;pic=0xDC00;};break; default:break; } } //****************************************************************************** void Photo(unsigned char Number) { unsigned int x,y; WriteRegister(0x44, 0xef00); // Horizontal RAM Address WriteRegister(0x45, 0x0000); // Vertical RAM Start Address WriteRegister(0x46, 0x013f); // Vertical GRAM end Address WriteRegister(0x4e, 0x0000); //X GDDRAM WriteRegister(0x4f, 0x0000); //Y GDDRAM writelcm(0x0022,C); AddressSlect(Number); G=1; CE1=0; CE2=0; for(y=0;y<320;y++) { for(x=0;x<240;x++) { if(pic==0xffff) { AddressSlect(++Number); write_xdata(pic++); pic=0x0000; } else write_xdata(pic++); } } } //******************************************************************************