1 /*-------------------------------------------------------------------------
2 lcd.c - lcd routines for the DS80C390 (tested on TINI)
4 Written By - Johan Knol, johan.knol@iduna.nl
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 In other words, you are welcome to use, share and improve this program.
21 You are forbidden to forbid anyone else to use, share and improve
22 what you give them. Help stamp out software-hoarding!
23 -------------------------------------------------------------------------*/
30 #define LCD_COLLUMNS 20
32 xdata at 0x380002 static unsigned char lcdIwr;
33 xdata at 0x38000a static unsigned char lcdDwr;
37 xdata at 0x380003 static unsigned char lcdIrd;
38 xdata at 0x38000b static unsigned char lcdDrd;
40 #define LcdWait { while (lcdIrd&0x80) ; }
45 #define LcdWait { ClockMicroSecondsDelay(100) ; }
49 // set the dd ram addresses for the rows
50 // this one is for a 20x4 LCD
51 xdata static unsigned char lcdLinesStart[LCD_ROWS]={0, 0x40, 0x14, 0x54};
55 ClockMilliSecondsDelay(16); // >15 ms
58 ClockMilliSecondsDelay(5); // >4.1 ms
61 ClockMicroSecondsDelay(101); // >100 us
64 ClockMicroSecondsDelay(101); // >100 us
66 lcdIwr=0x38; // interface 8 bit
67 ClockMicroSecondsDelay(41); // >40 us
69 lcdIwr=0x0c; // display on
70 ClockMicroSecondsDelay(41); // >40 us
76 lcdIwr=0x0c; // display on
81 lcdIwr=0x08; // display off
101 void LcdCharDefine() {
106 lcdIwr=0x01; // display clear
107 ClockMilliSecondsDelay(6); // > 5ms
111 lcdIwr=0x80; // set dd ram address 0
115 void LcdGoto(unsigned int collumnRow) { // msb=collumn, lsb=row
117 lcdLinesStart[collumnRow&0xff] + (collumnRow>>8);
121 void LcdPutChar(char c) {
126 void LcdPutString (char *string) {
128 while (c=*string++) {
133 void LcdLPutString (unsigned int collumnRow, char *string) {
135 LcdPutString(string);
138 // let's hope that no one ever printf's more than the display width,
139 // however they will :), so to be sure
140 static char lcdPrintfBuffer[LCD_COLLUMNS*4];
142 void LcdPrintf (xdata const char *format, ...) reentrant {
145 va_start (arg, format);
146 vsprintf (lcdPrintfBuffer, format, arg);
147 puts (lcdPrintfBuffer);
148 LcdPutString(lcdPrintfBuffer);
153 void LcdLPrintf (unsigned int collumnRow, xdata const char *format, ...) reentrant {
158 // we can not just call LcdPrintf since we have no idea what is on the stack,
159 // so we have to do it all over again
160 va_start (arg, format);
161 vsprintf (lcdPrintfBuffer, format, arg);
163 LcdPutString(lcdPrintfBuffer);