#include #include #include #define SET_HIGH(PIN) PORTC |= _BV(PIN) #define SET_LOW(PIN) PORTC &= ~_BV(PIN) #define CS 0 #define RS 1 #define WR 2 #define RD 3 #define RESET 4 #define red 0xf800 #define green 0x07e0 #define blue 0x001f #define black 0x0000 #define white 0xffff #define gray 0x8c51 #define yellow 0xFFE0 #define cyan 0x07FF #define purple 0xF81F unsigned int colorc[]={red,green,blue,black,white,gray,yellow,cyan,purple}; void Trans_Dat(unsigned int index, unsigned int data) { unsigned char low8 = index; unsigned char high8 = index >> 8; SET_LOW(CS); SET_LOW(RS); SET_HIGH(WR); PORTD = high8; SET_LOW(WR); SET_HIGH(WR); PORTD = low8; SET_LOW(WR); SET_HIGH(WR); SET_HIGH(RS); low8 = data; high8 = data >> 8; PORTD = high8; SET_LOW(WR); SET_HIGH(WR); PORTD = low8; SET_LOW(WR); SET_HIGH(WR); SET_HIGH(CS); } void init_LCD(void) { SET_HIGH(RD); SET_HIGH(RESET); _delay_ms(1); SET_LOW(RESET); _delay_ms(5); SET_HIGH(RESET); _delay_ms(10); Trans_Dat(0x00E3, 0x3008); // Set internal timing Trans_Dat(0x00E7, 0x0012); // Set internal timing Trans_Dat(0x00EF, 0x1231); // Set internal timing Trans_Dat(0x0001, 0x0100); // set SS and SM bit Trans_Dat(0x0002, 0x0700); // set line inversion Trans_Dat(0x0003, 0x1030); // set GRAM write direction and BGR=1. Trans_Dat(0x0004, 0x0000); // Resize register Trans_Dat(0x0008, 0x0207); // set the back porch and front porch Trans_Dat(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0] Trans_Dat(0x000A, 0x0000); // FMARK function Trans_Dat(0x000C, 0x0000); // RGB interface setting Trans_Dat(0x000D, 0x0000); // Frame marker Position Trans_Dat(0x000F, 0x0000); // RGB interface polarity //--------------Power On sequence --------------// Trans_Dat(0x0010, 0x0000); // SAP, BT[3:0], AP[2:0], DSTB, SLP, STB Trans_Dat(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0] Trans_Dat(0x0012, 0x0000); // VREG1OUT voltage Trans_Dat(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude _delay_ms(200); // Dis-charge capacitor power voltage Trans_Dat(0x0010, 0x1490); // SAP, BT[3:0], AP[2:0], DSTB, SLP, STB Trans_Dat(0x0011, 0x0227); // R11h=0x0221 at VCI=3.3V ,DC1[2:0], DC0[2:0], VC[2:0] _delay_ms(50); // Delayms 50ms Trans_Dat(0x0012, 0x001c); // External reference voltage= Vci; _delay_ms(50); // Delayms 50ms Trans_Dat(0x0013, 0x0A00); // R13=0F00 when R12=009E;VDV[4:0] for VCOM amplitude Trans_Dat(0x0029, 0x000F); // R29=0019 when R12=009E;VCM[5:0] for VCOMH//0012// Trans_Dat(0x002B, 0x000D); // Frame Rate = 91Hz _delay_ms(50); // Delayms 50ms Trans_Dat(0x0020, 0x0000); // GRAM horizontal Address Trans_Dat(0x0021, 0x0000); // GRAM Vertical Address // ----------- Adjust the Gamma Curve ----------// Trans_Dat(0x0030, 0x0000); Trans_Dat(0x0031, 0x0203); Trans_Dat(0x0032, 0x0001); Trans_Dat(0x0035, 0x0205); Trans_Dat(0x0036, 0x030C); Trans_Dat(0x0037, 0x0607); Trans_Dat(0x0038, 0x0405); Trans_Dat(0x0039, 0x0707); Trans_Dat(0x003C, 0x0502); Trans_Dat(0x003D, 0x1008); //------------------ Set GRAM area ---------------// Trans_Dat(0x0050, 0x0000); // Horizontal GRAM Start Address Trans_Dat(0x0051, 0x00EF); // Horizontal GRAM End Address Trans_Dat(0x0052, 0x0000); // Vertical GRAM Start Address Trans_Dat(0x0053, 0x013F); // Vertical GRAM Start Address Trans_Dat(0x0060, 0xA700); // Gate Scan Line Trans_Dat(0x0061, 0x0001); // NDL,VLE, REV Trans_Dat(0x006A, 0x0000); // set scrolling line //-------------- Partial Display Control ---------// Trans_Dat(0x0080, 0x0000); Trans_Dat(0x0081, 0x0000); Trans_Dat(0x0082, 0x0000); Trans_Dat(0x0083, 0x0000); Trans_Dat(0x0084, 0x0000); Trans_Dat(0x0085, 0x0000); //-------------- Panel Control -------------------// Trans_Dat(0x0090, 0x0010); Trans_Dat(0x0092, 0x0600); //0x0000 Trans_Dat(0x0093, 0x0003); Trans_Dat(0x0095, 0x0110); Trans_Dat(0x0097, 0x0000); Trans_Dat(0x0098, 0x0000); Trans_Dat(0x0007, 0x0133); // 262K color and display ON } void Display(unsigned int color, int x,int y) { int i,j; for(i=0;i