//------------------------------------------- // Shenzhen TOPWAY Technology Co. Ltd. // LCD Module: LM3122 // Display size: 202x32 // Driver/Controller: AX6120/AX6121 // Date: 2005-02-24 //------------------------------------------- #include #include #include #define u_char unsigned char #define u_int unsigned int sbit RES = P3^5; sbit _WR1 = P3^1; sbit _WR2 = P3^2; sbit _WR3 = P3^3; sbit A0 = P3^6; // DataBus = P1 //==================== // Display Data //==================== /*-- TOPWAY 202x32 --*/ u_int code Logo1[]={ 0xFE,0xFE,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0xFE,0xFE,0x00,0x00,0x80, 0xE0,0x70,0x38,0x18,0x0C,0x06,0x06,0x02,0x03,0x01,0x81,0x81,0x81,0x81,0x81,0x81, 0x81,0x01,0x03,0x02,0x06,0x06,0x0C,0x1C,0x38,0x70,0xE0,0xC0,0x00,0x00,0x00,0x00, 0xFE,0xFE,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02,0x06,0x04,0x04,0x0C,0x18,0x30,0xE0,0xC0,0x00,0x06,0x7E,0xFA, 0x82,0x02,0x02,0x02,0x02,0x02,0xFE,0xFE,0x80,0x00,0x00,0x00,0x00,0xF0,0xFE,0x1E, 0x02,0x02,0x02,0x02,0x02,0x1E,0xFE,0xF0,0x00,0x00,0x00,0x00,0x80,0xFE,0xFE,0x02, 0x02,0x02,0x02,0x02,0x82,0xFA,0x7E,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0xE0,0xFC,0x1E,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x1E,0xFC,0xE0, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x0E,0x1E,0x7A,0xE2,0x82,0x02, 0x02,0x02,0x02,0x06,0x1E,0x78,0xE0,0x80,0x00,0x00,0x00,0x80,0xE0,0x78,0x1E,0x06, 0x02,0x02,0x02,0x02,0x82,0xE2,0x7A,0x1E,0x0E,0x02,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xF8,0xFF,0x0F,0x01,0x00,0x00,0x00,0x00,0x00, 0xF0,0xFE,0x0F,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x0F,0xFE,0xF0,0x00, 0x00,0x00,0x00,0x00,0x01,0x07,0xFF,0xF8,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x7F,0x7F,0x41,0x41,0x41,0x41,0x41,0x41,0x63,0x3E,0x1C,0x00,0x00, 0x00,0x00,0x00,0x00,0x80,0xFF,0x7F,0x00,0x00,0x07,0xFF,0xF8,0x80,0x00,0x00,0x00, 0x00,0x3F,0xFF,0xE0,0x00,0xC0,0xFE,0x7F,0x03,0x00,0x80,0xFC,0xFC,0xFC,0x80,0x00, 0x03,0x7F,0xFE,0xC0,0x00,0xE0,0xFF,0x3F,0x00,0x00,0x00,0x00,0x80,0xF8,0xFF,0x07, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xF8,0x3F,0x07,0x00,0x00,0x00,0x00, 0xF0,0xFE,0x0F,0xFE,0xE0,0x00,0x00,0x00,0x00,0x07,0x3F,0xF8,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x1E,0x38,0xE0,0xC0,0x00,0x00,0x00, 0x01,0x07,0x1E,0x38,0x1E,0x07,0x01,0x00,0x00,0x00,0xC0,0xE0,0x38,0x1E,0x07,0x01, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x1F,0xFF,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x0F,0x7F,0xF0,0xC0,0x80,0x00, 0x00,0x00,0x00,0x00,0x80,0xC0,0xF0,0x7F,0x0F,0x00,0x00,0x00,0x00,0x00,0x80,0xE0, 0xFF,0x1F,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xE0,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x30,0x10,0x10,0x18,0x0C,0x0E,0x07,0x01, 0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xF8,0x80,0x00,0x00,0x00,0x0F,0xFF,0xFE,0x7F, 0x03,0x00,0x00,0xE0,0xFF,0x1F,0x00,0x1F,0xFF,0xE0,0x00,0x00,0x03,0x7F,0xFE,0xFF, 0x0F,0x00,0x00,0x00,0x80,0xF8,0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0, 0xF8,0x3F,0x07,0x01,0x00,0x00,0x00,0x00,0x78,0x7F,0x47,0x40,0x40,0x40,0x47,0x7F, 0x78,0x00,0x00,0x00,0x00,0x01,0x0F,0x3F,0xF8,0xC0,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0F,0xFC,0xF8,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0xF8,0xFC,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x0E, 0x1C,0x18,0x30,0x60,0x60,0x40,0xC0,0x80,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x80, 0xC0,0x40,0x60,0x60,0x30,0x18,0x1C,0x0E,0x07,0x01,0x00,0x00,0x00,0x00,0xFF,0xFF, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x0F,0xFF,0xF0,0x80,0x80,0x80,0x81,0x81,0x80,0x80,0x80,0xF8,0xFF,0x07,0x00, 0x00,0x00,0x07,0xFF,0xF8,0x80,0x80,0x80,0x81,0x81,0x80,0x80,0x80,0xF0,0xFF,0x0F, 0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xF0,0xFE,0x8F,0x81,0x80,0x80,0x80,0x80,0xC0, 0xF8,0x38,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x38,0xF8,0xC0,0x80,0x80, 0x80,0x80,0x81,0x8F,0xFE,0xF0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0xFF,0xFF,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xFF,0xFF,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //==================== // delay routine //==================== void delay100us(void) //delay 100us for 12MHz { u_char data i; for(i=0;i<=70;i++) {_nop_(); _nop_();} } void delay1ms(void) //delay 1ms for 12MHz { u_char data i; for(i=0;i<=250;i++) {_nop_(); _nop_();} } void delay100ms(void) { u_char data j; for(j=0;j<=100;j++) {delay1ms();} } //==================== // write command //==================== void wr_command(u_char ChipNo,command) { P1 = command; A0=0; _nop_(); switch(ChipNo) { case 0: _WR1=0; _WR2=0; _WR3=0; break;// write into all driver case 1: _WR1=0; _WR2=1; _WR3=1; break;// write into 1st driver case 2: _WR1=1; _WR2=0; _WR3=1; break;// write into 2nd driver case 3: _WR1=1; _WR2=1; _WR3=0; break;// write into 3rd driver } _WR1=1; _WR2=1; _WR3=1; delay100us(); } //==================== // write data //==================== void wr_data(u_char ChipNo,ddata) { P1 = ddata; A0=1; _nop_(); switch(ChipNo) { case 0: _WR1=0; _WR2=0; _WR3=0; break; // write into all driver case 1: _WR1=0; _WR2=1; _WR3=1; break; // write into 1st driver case 2: _WR1=1; _WR2=0; _WR3=1; break; // write into 2nd driver case 3: _WR1=1; _WR2=1; _WR3=0; break; // write into 3rd driver } _WR1=1; _WR2=1; _WR3=1; } //==================== // clear screen //==================== void ClrScreen() // fill 00h into DD RAM { u_char i,j; for(i=0;i<4;i++) { wr_command(0,0xb8 | i); // select page wr_command(0,0x00); // start form column 0 for(j=0;j<80;j++) { wr_data(0,0x00);// fill 00h in to DD RAM } } } //==================== // Write a Screen //==================== void WriteScreen(u_int *DisplayData) // DisplayData should be 202x32/8 = 808 bytes { u_char TempData; u_char i, j; for(i=0;i<4;i++) { wr_command(0,0xb8 | i); // select page wr_command(0,0); // all chip start form column 0 for(j=0;j<201;j++) { TempData=(*(DisplayData+(i*202)+j)); if (j<61) { wr_data(1,TempData); // 0-60 column goto chip1 } else if ((j>=61)&(j<=140)) { wr_data(2,TempData); // 61-141 column goto chip2 } else { wr_data(3,TempData); // 141-201 column goto chip3 } } } } //==================== // Init LCD module //==================== void initLCDM(void) { _WR1=1; _WR2=1; _WR3=1; // init WR status RES = 0; delay1ms(); RES = 1; delay1ms(); RES = 0; // RES=0, 80 I/F mode wr_command(0,0xa9); // set duty cycle 1/32 wr_command(0,0xa4); // static drive = OFF wr_command(0,0xa0); // adc=0 wr_command(0,0xc0); // display start line =0; wr_command(0,0xaf); // display ON; //wr_command(0,0xee); // read modify write=Off; } //************************ // Main Program //************************ void main(void) { SP = 0x60; // stack pointer EA = 0; // disable interrupts initLCDM(); // init LCD module ClrScreen(); // clear DD RAM WriteScreen(Logo1); //send a screen of display while(1) // end of program { _nop_(); } }