/* ** ################################################################### ** Filename : Hyundai_HG25504_LCD_TEST.c ** DataSheets: SED1330F/1335F/1336F LCD Controller ICs Technical Manual ** REV: Sept 1995 Version 0.4 ** ** SPEC SHEET FOR CAT# LCD-101 256x128 Graphic LCD Hyundai HG25504 ** ** Compiler : CodeWarrior compiler ** Processor : MC68HC908JL16CSPE ** Date/Time : 2.27.2008 ** Abstract : ** This Program tests the Hyundai HG25504 LCD on the Motorolla ** MC68HC908JL16 Micro Processor ** ** It will display "HELLO . . . . .____ 0123456789" ** ** PIN Connections: ** ** PTA0 - LED ** ** LCD: ** PIN1 GND - GND ** PIN2 GND - GND ** PIN3 VCC - VCC ** PIN4 Vcont - -10v ** PIN5 /RST - PTA5 ** PIN6 /RD - VCC ** PIN7 /WR - PTA1 ** PIN8 /CS - PTD1 ** PIN9 A0 - PTA4 ** ** PIN10-17 D0-D7 - PTB0-PTB7 ** ** ** Omair Khan ** University of Southern California ** www.omair-khan.com ** ** Referenced from Duane Beker ** http://www.sover.net/~snowleop/gdisp3/ ** ** Revisions: ** none ** ** ################################################################### */ #include /* for EnableInterrupts macro */ #include "derivative.h" /* include peripheral declarations */ /* The following puts the dummy interrupt service routine at location MY_ISR_ROM which is defined in the PRM file as the start of the FLASH ROM */ #pragma CODE_SEG MY_ISR_ROM #pragma TRAP_PROC void dummyISR(void) { } /* This pragma sets the code storage back to default area of ROM as defined in the PRM file. */ #pragma CODE_SEG DEFAULT void init_uP(void); void init_LCD(void); void writeLCDcmd(unsigned char data,int a); void writeNUM(int a); #pragma DATA_SEG __SHORT_SEG MY_ZEROPAGE /* ********************************** * * * Main * * * ********************************** */ void main(void) { int rc=0; init_uP(); init_LCD(); writeLCDcmd(0x46,1); //set cursor address to top of text block (addr 0x0000) writeLCDcmd(0x00,0); writeLCDcmd(0x00,0); writeLCDcmd(0x42,1); //send mwrite cmd writeLCDcmd(0x48,0); //H writeLCDcmd(0x45,0); //E writeLCDcmd(0x4C,0); //L writeLCDcmd(0x4C,0); //L writeLCDcmd(0x4F,0); //O writeLCDcmd(0x46,1); //set cursor address to top row col 5 at addr 0x1005 writeLCDcmd(0x05,0); writeLCDcmd(0x10,0); writeLCDcmd(0x42,1); //send mwrite cmd writeLCDcmd(0b01010101,0); //draw off on off ... dots writeLCDcmd(0xFF,0); //draw straight line writeLCDcmd(0x46,1); //set cursor address to top of text block (addr 0x0016) writeLCDcmd(0x16,0); writeLCDcmd(0x00,0); writeLCDcmd(0x42,1); //send mwrite cmd for(rc=0; rc<9; rc++) writeNUM(rc); while (1) { PTA_PTA0=0; //turn off LED for(rc=0;rc<20000;rc++); PTA_PTA0=1; //turn on LED for(rc=0;rc<20000;rc++); PTA_PTA0=0; //turn off LED } /* please make sure that you never leave this function */ } /* ********************************************************************************* * * * Functions * * * ********************************************************************************* */ void init_uP(){ CONFIG1_COPD = 1; // disable COP reset DDRA_DDRA5=1; PTA_PTA5=0; // reset lcd DDRB = 0xFF; //set port B for output (LCD DATABUS) DDRA_DDRA0=1; //LED DDRA_DDRA1=1; //LCD /WR PTA_PTA1=1; DDRA_DDRA4=1; //LCD A0 PTA_PTA4=1; DDRD_DDRD1=1; //LCD /CS PTD_PTD1=1; } /* ********************************** * * * LCD * * * ********************************** */ void init_LCD() { int ra=0; PTA_PTA5=1; // deactivate reset writeLCDcmd(0x58,1); //turn off display writeLCDcmd(0x40,1); //initialize LCD writeLCDcmd(0x30,0); //Int CG, 32chr CGRAM, 8lines/char, single pane, No invert, lcd, normal shift clock writeLCDcmd(0x87,0); //8 pixel wide characters, 2 frame AC drive writeLCDcmd(0x07,0); //vertical char size=8 pixels writeLCDcmd(0x1F,0); //32 display bytes per line writeLCDcmd(0x23,0); //tot. addr range per line (4 extra for horz blk) writeLCDcmd(0x7F,0); //128 display lines writeLCDcmd(0x20,0); //low byte of virtual screen width writeLCDcmd(0x00,0); //high byte of virtual screen width writeLCDcmd(0x44,1); //send scroll cmd writeLCDcmd(0x00,0); //set layer 1 home addr to 0x0000 writeLCDcmd(0x00,0); writeLCDcmd(0x7F,0); //128 lines for layer 1 writeLCDcmd(0x00,0); //set layer 2 (graphic) home address to 0x1000 writeLCDcmd(0x10,0); writeLCDcmd(0x7F,0); //128 lines for layer 2 //layers 3 and 4 not used writeLCDcmd(0x5A,1); //set hor scroll cmd writeLCDcmd(0x00,0); //no hor scroll adjustment writeLCDcmd(0x5B,1); //set overlay selections cmd writeLCDcmd(0x00,0); //OR layers, text block 1, 2 layer (layer 2 can only be graphic) writeLCDcmd(0x4C,1); //auto cursor increment +1 cmd writeLCDcmd(0x46,1); //cursor write cmd writeLCDcmd(0x00,0); //0x00 addr writeLCDcmd(0x00,0); writeLCDcmd(0x42,1); //send mwrite cmd //for a total of 512 ascii spaces (0x20) for(ra=1;ra<512;++ra) writeLCDcmd(0x20,0); //send 7168 zeros of data to clr out CGRAM area //(28 x 256 = 7168) //from 0400h to 0FFFh and the graphics area from //1000h to 1FFFh for(ra=0; ra<3584; ++ra) writeLCDcmd(0x00,0); for(ra=0; ra<4096; ++ra) writeLCDcmd(0x00,0); writeLCDcmd(0x5D,1); //set cursor format writeLCDcmd(0x04,0); //five pixels wide writeLCDcmd(0x86,0); //vertical cursor size=7 pixels block cursor writeLCDcmd(0x59,1); //display ON writeLCDcmd(0b00010100,0); //(0b00010100) no layer 3, show layer 2, show layer 1, no cursor writeLCDcmd(0x5C,1); //set CGRAM addr cmd writeLCDcmd(0x00,0); //CGRAM addr = 0x0400 writeLCDcmd(0x04,0); //----- DISPLAY IS CLEARED AND ON ------ } void writeLCDcmd(unsigned char data,int a) { PTB = data; //put data on databus if(a==1) PTA_PTA4 = 1; //write to (0 = data, 1 = command) register if(a==0) PTA_PTA4 = 0; PTD_PTD1 = 0; //enable /CS PTA_PTA1 = 0; //enable /WR PTA_PTA1 = 1; //disable /WR PTD_PTD1 = 1; //disable /CS } void writeNUM(int a) { writeLCDcmd((0x30)+a,0); }