本帖最后由 zhyue12 于 2015-10-28 15:11 编辑
在使用时最好采用16MHZ的时钟频率,当时使用32M时驱动不了,需要重新调时序。
- #include "LCD.h"
- void main_Write_COM(uint CH)
- {
- uchar a,b;
- a = (CH >> 8);
- b = (uchar)CH;
- RS = 0;
- CS = 0;
- RD = 1;
- PORTD = a;
- PORTA = b;
- WR = 0;
- WR = 1;
- CS = 1;
- }
- void main_Write_DATA(uint DH)
- {
- uchar a,b;
- a = (DH >> 8);
- b = (uchar)DH;
- CS = 0;
- RS = 1;
- RD = 1;
- PORTD = a;
- PORTA = b;
- WR = 0;
- WR = 1;
- CS = 1;
- }
- void REST(void)
- {
- RES = 1;
- delay(10);
- RES = 0;
- delay(100);
- RES = 1;
- delay(120);
- }
- void main_address_set(void)
- {
- main_Write_COM(0x2A); //x address area set
- main_Write_DATA(0x00); //
- main_Write_DATA(0x00); //
- main_Write_DATA(0x00); //
- main_Write_DATA(0xEF);
-
- main_Write_COM(0x2B); //y address set
- main_Write_DATA(0x00); //
- main_Write_DATA(0x00); //
- main_Write_DATA(0x01); //
- main_Write_DATA(0x3F); //
- main_Write_COM(0x2C);
- }
- void address_set(uint XS,uint YS,uint x_total,uint y_total)
- {
- uint XS_L,XS_H,YS_L,YS_H,XE,YE,XE_H,XE_L,YE_H,YE_L;
- XS_H=XS/256;
- XS_L=XS%256;
- YS_H=YS/256;
- YS_L=YS%256;
- XE=XS+x_total-1;
- YE=YS+y_total-1;
- XE_H=XE/256;
- XE_L=XE%256;
- YE_H=YE/256;
- YE_L=YE%256;
- main_Write_COM(0x2A); //x address area set
- main_Write_DATA(XS_H); //
- main_Write_DATA(XS_L); //
- main_Write_DATA(XE_H); //
- main_Write_DATA(XE_L);
-
- main_Write_COM(0x2B); //y address set
- main_Write_DATA(YS_H); //
- main_Write_DATA(YS_L); //
- main_Write_DATA(YE_H); //
- main_Write_DATA(YE_L); //
- main_Write_COM(0x2C);
-
- }
- void disp_color(uint XS,uint YS,uint x_total,uint y_total,uint color)
- {
- uchar i,j;
- address_set(XS,YS,x_total,y_total);
- for(i=YS;i<(YS+y_total);i++)
- {
- for(j=XS;j<(XS+x_total);j++)
- {
- main_Write_DATA(color);
- }
- }
- }
- void main_Pattern(unsigned int jm)
- {
- int i,j;
- main_address_set();
- for(j=0;j<320;j++)
- {
- for(i=0;i<240;i++)
- {
- main_Write_DATA(jm);
- }
- }
- }
- void disp_chinese(uint x,uint y,uint k_x,uint k_y,
- uchar *dp,uint front_color,uint back_color)
- {
- uint size,i,j;
-
- address_set(x,y,k_x,k_y);
-
- size = (k_x * k_y) / 8;
-
- for(i=0;i
- {
- data_out(*dp,front_color,back_color);
- dp++;
- }
- }
- void disp_num(uint x,uint y,uint k_x,uint k_y,uchar num,uchar sz[],
- uint front_color,uint back_color)
- {
- uint size,a,i;
- address_set(x,y,k_x,k_y);
- size = (k_x * k_y) / 8;
- a = num *size;
- for(i=a;i<(a+size);i++)
- {
- data_out(*(sz+i),front_color,back_color);
- }
- }
- void data_out(uchar c_data,uint front_color,uint back_color)
- {
- uchar i;
- for(i=0;i<8;i++)
- {
- if(c_data&0x80)
- {
- main_Write_DATA(front_color);
- }
- else
- {
- main_Write_DATA(back_color);
- }
- c_data<<=1;
- }
- }
- void disp_line(uint x,uint y,uint k_x,uint k_y,uint color)
- {
- uint i,size;
- address_set(x,y,k_x,k_y);
- size = k_x * k_y;
- for(i=0;i
- {
- main_Write_DATA(color);
- }
- }
- void main_init(void)
- {
-
- /* main_Write_COM(0xCF);
- main_Write_DATA(0x00);
- main_Write_DATA(0x81);
- main_Write_DATA(0X30);
-
- main_Write_COM(0xED);
- main_Write_DATA(0x64);
- main_Write_DATA(0x03);
- main_Write_DATA(0X12);
- main_Write_DATA(0X81);
-
- main_Write_COM(0xE8);
- main_Write_DATA(0x85);
- main_Write_DATA(0x10);
- main_Write_DATA(0x7e);
-
- main_Write_COM(0xCB);
- main_Write_DATA(0x39);
- main_Write_DATA(0x2C);
- main_Write_DATA(0x00);
- main_Write_DATA(0x34);
- main_Write_DATA(0x02);
-
- main_Write_COM(0xF7);
- main_Write_DATA(0x20);
-
- main_Write_COM(0xEA);
- main_Write_DATA(0x00);
- main_Write_DATA(0x00);
-
- main_Write_COM(0xB1);
- main_Write_DATA(0x00);
- main_Write_DATA(0x1B);
-
- main_Write_COM(0xB6); // Display Function Control
- main_Write_DATA(0x0A);
- main_Write_DATA(0xA2);
-
- main_Write_COM(0xC0); //Power control
- main_Write_DATA(0x21); //VRH[5:0]
-
- main_Write_COM(0xC1); //Power control
- main_Write_DATA(0x11); //SAP[2:0];BT[3:0]
-
- main_Write_COM(0xC5); //VCM control
- main_Write_DATA(0x3F);
- main_Write_DATA(0x3C);
-
- main_Write_COM(0xC7); //VCM control2
- main_Write_DATA(0Xb5);
-
- main_Write_COM(0x36); // Memory Access Control
- main_Write_DATA(0x48);
-
- main_Write_COM(0x3A);//65K 16BIT
- main_Write_DATA(0x55);
-
- main_Write_COM(0xF2); // 3Gamma Function Disable
- main_Write_DATA(0x00);
-
- main_Write_COM(0x26); //Gamma curve selected
- main_Write_DATA(0x01);
-
- main_Write_COM(0xE0); //Set Gamma
- main_Write_DATA(0x0F);
- main_Write_DATA(0x26);
- main_Write_DATA(0x24);
- main_Write_DATA(0x0B);
- main_Write_DATA(0x0E);
- main_Write_DATA(0x09);
- main_Write_DATA(0x54);
- main_Write_DATA(0XA8);
- main_Write_DATA(0x46);
- main_Write_DATA(0x0C);
- main_Write_DATA(0x17);
- main_Write_DATA(0x09);
- main_Write_DATA(0x0F);
- main_Write_DATA(0x07);
- main_Write_DATA(0x00);
- main_Write_COM(0XE1); //Set Gamma
- main_Write_DATA(0x00);
- main_Write_DATA(0x19);
- main_Write_DATA(0x1B);
- main_Write_DATA(0x04);
- main_Write_DATA(0x10);
- main_Write_DATA(0x07);
- main_Write_DATA(0x2A);
- main_Write_DATA(0x47);
- main_Write_DATA(0x39);
- main_Write_DATA(0x03);
- main_Write_DATA(0x06);
- main_Write_DATA(0x06);
- main_Write_DATA(0x30);
- main_Write_DATA(0x38);
- main_Write_DATA(0x0F);
- main_Write_COM(0x11); //Exit Sleep
- delay(120);
- main_Write_COM(0x29); //Display on
- */
- main_Write_COM(0xfd); //enter
- main_Write_DATA(0x06);
- main_Write_DATA(0x07);
- main_Write_COM(0x66);
- main_Write_DATA(0x80);
- main_Write_COM(0x80);
- main_Write_DATA(0x05);
- ///Delay_ms(5);
- main_Write_COM(0x80);
- main_Write_DATA(0x01);
- main_Write_COM(0xb6);
- main_Write_DATA(0x02);//rev,gs,ss,sm
- main_Write_DATA(0xa2);
- main_Write_COM(0x36);
- main_Write_DATA(0xC8); // 刷屏方向
- main_Write_COM(0x3a);
- main_Write_DATA(0x65);
- main_Write_COM(0x60);
- main_Write_DATA(0x22);//vrh
- main_Write_COM(0x63);
- main_Write_DATA(0x08);
- main_Write_COM(0x64);
- main_Write_DATA(0x0c);
- main_Write_COM(0x68);
- main_Write_DATA(0x70);
- main_Write_COM(0x69);
- main_Write_DATA(0x1f);
- main_Write_COM(0x6a);
- main_Write_DATA(0xc4);
- main_Write_COM(0x6b); //VCM5-0
- main_Write_DATA(0x20);
- main_Write_COM(0x6c); //VDV4-0
- main_Write_DATA(0x16);
- main_Write_COM(0x6d);
- main_Write_DATA(0x77);
- main_Write_COM(0x6e);
- main_Write_DATA(0x84);
- main_Write_COM(0x6f);
- main_Write_DATA(0x48);
- main_Write_COM(0xf7); //frc_en
- main_Write_DATA(0x10);
- main_Write_COM(0x70);
- main_Write_DATA(0x44);
-
- main_Write_COM(0xed);
- main_Write_DATA(0xf9);
- main_Write_DATA(0xf9);
- main_Write_DATA(0x00);
- main_Write_DATA(0x00);
- main_Write_DATA(0x11);
- main_Write_DATA(0x00);
- main_Write_COM(0xe0); //gmama set 2.4
- main_Write_DATA(0x10); //PKP0[4:0]
- main_Write_DATA(0x19); //PKP1[4:0]
- main_Write_DATA(0x0d); //PKP2[4:0]
- main_Write_DATA(0x1a); //PKP3[4:0]
- main_Write_DATA(0x07); //PKP4[4:0]
- main_Write_DATA(0x13); //PKP5[4:0]
- main_Write_DATA(0x14); //PKP6[4:0]
- main_Write_COM(0xe1);
- main_Write_DATA(0x2b); //PRP0[6:0]
- main_Write_DATA(0x5f); //PRP1[6:0]
- main_Write_COM(0xe2);
- main_Write_DATA(0x1b); //VRP0[5:0]
- main_Write_DATA(0x28); //VRP1[5:0]
- main_Write_DATA(0x28); //VRP2[5:0]
- main_Write_DATA(0x18); //VRP3[5:0]
- main_Write_DATA(0x15); //VRP4[5:0]
- main_Write_DATA(0x17); //VRP5[5:0]
- main_Write_COM(0xe3);
- main_Write_DATA(0x10); //PKN0[4:0]
- main_Write_DATA(0x17); //PKN1[4:0]
- main_Write_DATA(0x05); //PKN2[4:0]
- main_Write_DATA(0x13); //PKN3[4:0]
- main_Write_DATA(0x08); //PKN4[4:0]
- main_Write_DATA(0x13); //PKN5[4:0]
- main_Write_DATA(0x06); //PKN6[4:0]
- main_Write_COM(0xe4);
- main_Write_DATA(0x0b); //PRN0[6:0]
- main_Write_DATA(0x50); //PRN1[6:0]
- main_Write_COM(0xe5);
- main_Write_DATA(0x17); //VRN0[5:0]
- main_Write_DATA(0x24); //VRN1[5:0]
- main_Write_DATA(0x15); //VRN2[5:0]
- main_Write_DATA(0x17); //VRN3[5:0]
- main_Write_DATA(0x17); //VRN4[5:0]
- main_Write_DATA(0x1f); //VRN5[5:0]
- main_Write_COM(0x66); //OSC trim
- main_Write_DATA(0x94);
- main_Write_COM(0x67); //i_trim
- main_Write_DATA(0x07);
- main_Write_COM(0xb1); //frame rate
- main_Write_DATA(0x00);
- main_Write_DATA(0x12);
- main_Write_COM(0xec);
- main_Write_DATA(0x33);
- main_Write_DATA(0x11);
- main_Write_DATA(0x11);
- main_Write_DATA(0x00);
- main_Write_DATA(0x18);
- main_Write_DATA(0x18);
- main_Write_COM(0xfd); //exit
- main_Write_DATA(0xfa);
- main_Write_DATA(0xfb);
- main_Write_COM(0x11); // exit sleep
- //Delay_ms(300);
- main_Pattern(0xffff);
- main_Write_COM(0x29); // display on
- }
复制代码
0
|
|
|
|