Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / ds390 / lcd390.c
1 /*-------------------------------------------------------------------------
2   lcd.c - lcd routines for the DS80C390 (tested on TINI)
3   
4    Written By - Johan Knol, johan.knol@iduna.nl
5     
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
9    later version.
10    
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.
15    
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.
19    
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 -------------------------------------------------------------------------*/
24
25 #include <tinibios.h>
26 #include <stdio.h>
27 #include <stdarg.h>
28
29 #define LCD_COLLUMNS 20
30 #define LCD_ROWS 4
31
32 /* set the dd ram addresses for the rows
33    this one is for a 20x4 LCD
34 */
35 static unsigned char lcdLinesStart[LCD_ROWS]={0, 0x40, 0x14, 0x54};
36
37 /* Commercial TINI stick connector boards don't support rw
38    control for the lcd-display.
39    My own board does, and it makes it much faster.
40 */
41
42 //#define LCD_RW
43
44 __xdata __at (0x380002) static unsigned char lcdIwr;
45 __xdata __at (0x38000a) static unsigned char lcdDwr;
46
47 #ifdef LCD_RW
48
49 __xdata __at (0x380003) static unsigned char lcdIrd;
50 __xdata __at (0x38000b) static unsigned char lcdDrd;
51
52 #define LcdWait { while (lcdIrd&0x80) ; }
53
54 #else // ifdef LCD_RW
55
56 // wait for 100us
57 #define LcdWait { ClockMicroSecondsDelay(100) ; }
58
59 #endif // ifdef LCD_RW
60
61 void LcdInit() {
62   
63   ClockMilliSecondsDelay(16); // >15 ms
64   
65   lcdIwr=0x38 ;
66   ClockMilliSecondsDelay(5); // >4.1 ms
67   
68   lcdIwr=0x38;
69   ClockMicroSecondsDelay(101); // >100 us
70   
71   lcdIwr=0x38;
72   ClockMicroSecondsDelay(101); // >100 us
73   
74   lcdIwr=0x38; // interface 8 bit
75   ClockMicroSecondsDelay(41); // >40 us
76   
77   lcdIwr=0x0c; // display on
78   ClockMicroSecondsDelay(41); // >40 us
79
80   LcdClear();
81 }
82
83 void LcdOn() {
84   lcdIwr=0x0c; // display on
85   LcdWait;
86 }
87
88 void LcdOff() {
89   lcdIwr=0x08; // display off
90   LcdWait;
91 }
92
93 void LcdCursorOn() {
94   // TODO
95 }
96
97 void LcdCursorOff() {
98   // TODO
99 }
100
101 void LcdScrollOn() {
102   // TODO
103 }
104
105 void LcdScrollOff() {
106   // TODO
107 }
108
109 void LcdCharDefine() {
110   // TODO
111 }
112
113 void LcdClear() {
114   lcdIwr=0x01; // display clear
115   ClockMilliSecondsDelay(6); // > 5ms
116 }
117
118 void LcdHome() {
119   lcdIwr=0x80; // set dd ram address 0
120   LcdWait;
121 }
122
123 void LcdGoto(unsigned int collumnRow) { // msb=collumn, lsb=row
124   lcdIwr=0x80 + \
125     lcdLinesStart[collumnRow&0xff] + (collumnRow>>8);
126   LcdWait;
127 }
128
129 void LcdPutChar(char c) {
130   lcdDwr=c;
131   LcdWait;
132 }
133
134 void LcdPutString (char *string) {
135   char c;
136   while (c=*string++) {
137     LcdPutChar (c);
138   }
139 }
140
141 void LcdLPutString (unsigned int collumnRow, char *string) {
142   LcdGoto(collumnRow);
143   LcdPutString(string);
144 }
145
146 // let's hope that no one ever printf's more than the display width,
147 // however they will :), so to be sure
148 static char lcdPrintfBuffer[LCD_COLLUMNS*4];
149
150 void LcdPrintf (const char *format, ...) __reentrant {
151   va_list arg;
152
153   va_start (arg, format);
154   vsprintf (lcdPrintfBuffer, format, arg);
155   puts (lcdPrintfBuffer);
156   LcdPutString(lcdPrintfBuffer);
157
158   va_end (arg);
159 }
160
161 void LcdLPrintf (unsigned int collumnRow, const char *format, ...) __reentrant {
162   va_list arg;
163
164   LcdGoto(collumnRow);
165
166   // we can not just call LcdPrintf since we have no idea what is on the stack,
167   // so we have to do it all over again
168   va_start (arg, format);
169   vsprintf (lcdPrintfBuffer, format, arg);
170
171   LcdPutString(lcdPrintfBuffer);
172
173   va_end (arg);
174 }