void lcdPutc(char c) { if(c == '\n') { cur_col = 0; if(cur_row < LCD_ROWS-1) cur_row++; lcdGoto(cur_row, cur_col); } else { if(cur_col >= LCD_COLS) { cur_col = 0; if(cur_row < LCD_ROWS-1) cur_row++; lcdGoto(cur_row, cur_col); } lcdData(c); cur_col++; } }
void main ( void ) { ///// initialize keypad WrPortI ( PDFR,NULL,0x00 ); // parallel Port D All I/O WrPortI ( PDDCR,NULL,0xC0 ); // PD7..PD6 Open Collector WrPortI ( PDDDR,NULL,0xC0 ); // PD7..PD6 Output ///// initialize lcd WrPortI ( PADR,&PADRShadow,0x00 ); // Assure Outputs are Low WrPortI ( SPCR,&SPCRShadow,0x84 ); // parallel Port A = Outputs WrPortI ( PADR,&PADRShadow,PADRShadow&0x01 ); // Set Contrast at GND delay ( 1500 ); // Wait 15 mSec (LCD to Stabilize) lcdCmd4 ( 0x30 ); // Set to 8-Bit Interface delay ( 410 ); // Wait 4.1 mSec lcdCmd4 ( 0x30 ); // Set 8-Bit Interface delay ( 10 ); // Wait 100 uSec lcdCmd4 ( 0x30 ); // Set 8-Bit Interface lcdCmd4 ( 0x20 ); // Set 8-Bit Interface lcdCmd ( 0x28 ); // Set Dual Line Display lcdCmd ( 0x06 ); // Disable Display Shift lcdCmd ( 0x0C ); // Display On, Cursor Off lcdCmd ( 0x01 ); // Clear Screen, Home Cursor, Backlight On delay ( 164 ); // Wait 1.64 mSec for (;;) { WrPortI ( PDDR,NULL,0x40 ); // Scan Row 0 lcdGoto ( 0,0 ); // Cursor on column 0, row 0 keyCol (); // Scan for keypress WrPortI ( PDDR,NULL,0x80 ); // Scan Row 1 lcdGoto ( 0,1 ); // Cursor on column 0, row 1 keyCol (); // Scan for keypress } }