/************************************************************************* * * Driver demo for graphics/text lcd * LCD is HYUNDAI Model HG25601-C 256 x 128 * Controller is EPSON SED 1330F * * Note: pin 4 is from middle potentiometer, from -12 volts, ground * assumes an 8155 is memory mapped to an 8051 * Port A of the 8155 is used for data to the LCD * * Wiring pin from LCD to 8051 as follows: * * * LCD 8051 * * 1 no connection * 2 GND * 3 +5 volts * 4 from middle pot (150 ohms) 1=-12 volts, 2=middle, 3=ground * 5 reset P1.0 * 6 read P1.1 * 7 write P1.2 * 8 chip select P1.5 * 9 A0 P1.6 * 10 Data 0 Port A 0 * 11 Data 1 Port A 1 * 12 Data 2 Port A 2 * 13 Data 3 Port A 3 * 14 Data 4 Port A 4 * 15 Data 5 Port A 5 * 16 Data 6 Port A 6 * 17 Data 7 Port A 7 * * Read pin can be tied to high (+5 volts) if you are not planning * on reading status of the lcd. * *************************************************************************/ #include <8051reg.h> #include <8051io.h> #define IO_CONTROL *(char*)0x0100 #define PORT_A *(char*)0x0101 #define LCDreset 0x00 #define LCDnop 0x47 #define CmdSetup 0x47 #define CmdWrite 0x43 #define DataSetup 0x07 #define DataWrite 0x03 #define SystemSet 0x40 #define SleepIn 0x53 #define DispOFF 0x58 #define DispON 0x59 #define Scroll 0x44 #define CSRForm 0x5d #define CharAddr 0x5c #define CSRRight 0x4c #define CSRLeft 0x4d #define CSRUp 0x4e #define CSRDown 0x4f #define HorzScroll 0x5a #define Overlay 0x5b #define CSRW 0x46 #define CSRR 0x47 #define MWRITE 0x42 #define MREAD 0x43 unsigned char logo[] = { 0x00, 0x00, 0x03, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xf0, 0x00, 0x00, 0x03, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x0f, 0xc0, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0xff, 0xc0, 0x1f, 0xe0, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0x00, 0xff, 0xc0, 0x3f, 0xf0, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x3f, 0xf0, 0x00, 0xff, 0xc0, 0x7f, 0xf0, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x7f, 0xf0, 0x00, 0xff, 0xc0, 0x7f, 0xf8, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0xff, 0xc0, 0x7f, 0xf8, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0xff, 0xc0, 0xff, 0xf8, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xf8, 0x00, 0xff, 0xc0, 0xff, 0xf8, 0x01, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xf8, 0x01, 0xff, 0xc0, 0xff, 0xfc, 0x01, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xfc, 0x01, 0xff, 0xc0, 0xff, 0xfc, 0x01, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xfc, 0x01, 0xff, 0xc0, 0xff, 0xfe, 0x01, 0xff, 0xc0, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x01, 0xff, 0xc0, 0xff, 0xfe, 0x01, 0xff, 0x80, 0x00, 0x00, 0x00, 0xff, 0xfe, 0x01, 0xff, 0x80, 0xff, 0xff, 0x03, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x03, 0xff, 0x00, 0xff, 0xff, 0x03, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x03, 0xff, 0x00, 0x7f, 0xff, 0x87, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0x87, 0xfe, 0x00, 0x1f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xfc, 0x00, 0x0f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf8, 0x00, 0x03, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xf0, 0x00 }; int current_row = 0; int current_col = 0; main() { unsigned int address; unsigned char addrl, addrh; unsigned char lines_down; unsigned char byte_across; unsigned int i, j, x; lines_down = 42; byte_across = 13; IO_CONTROL = 0x0f; delay(); P1 = LCDnop; P1 = LCDreset; P1 = LCDnop; writeCommand(SystemSet); writeData(0x30); writeData(0x87); writeData(0x07); writeData(0x27); writeData(0x2f); writeData(0xc7); writeData(0x28); writeData(0x00); writeCommand(Overlay); writeData(0x00); writeCommand(Scroll); writeData(0x00); writeData(0x00); writeData(0xc8); writeData(0xe8); writeData(0x03); writeData(0xc8); writeCommand(CSRForm); writeData(0x04); writeData(0x86); writeCommand(CSRRight); writeCommand(HorzScroll); writeData(0x00); writeCommand(DispON); writeData(0x16); clearLCD(); gotoxy(5, 18); writeString("CONSULTING!"); address = 0x03e8; address += 800; j = 0; for (i = 0; i < lines_down; i++) { addrl = address; addrh = address >> 8; writeCommand(CSRW); writeData(addrl); writeData(addrh); writeCommand(MWRITE); for (x = 0; x < byte_across; x++) { writeData(logo[j]); j++; } address += 40; } gotoxy(11, 0); writeString("Programmer, network admin"); gotoxy(12, 0); writeString("Embedded systems, PC repair"); gotoxy(13, 0); writeString("icruz@sbcglobal.net"); gotoxy(14, 0); writeString("http://pages.sbcglobal.net/icruz/"); for (;;); } gotoxy(row, col) int row; int col; { int loc; char loc_lo, loc_hi; loc = col + 40 * row; loc_lo = loc; loc_hi = loc >> 8; writeCommand(CSRRight); writeCommand(CSRW); writeData(loc_lo); writeData(loc_hi); } writeGraph() { char add_low, add_high; int address, i, k; address = 0x03e8; k = 0; for (i=0; i<8; i++) { add_low = address; add_high = address >> 8; writeCommand(CSRW); writeData(add_low); writeData(add_high); writeCommand(MWRITE); /* writeData(array[i]); */ address += 40; } } writeTest() { int i; gotoxy(0,0); writeString("Writing ASCII pattern in ascending order"); gotoxy(1,0); writeCommand(MWRITE); for (i=0; i<160; i++) writeData((char)i); gotoxy(8,0); writeString("Writing ASCII pattern in descending order"); gotoxy(9,0); writeCommand(MWRITE); for (i=160; i>0; i--) writeData((char)i); } writeString(str) char *str; { int i, len; writeCommand(MWRITE); len = strlen(str); for (i=0; i