23 #define LCD_PORT PORTC
26 #define LCD_RW 0 // not used on the Atmega32 board
28 #define LCD_POUT PORTC
31 asm volatile ("nop; nop; nop; nop; nop; nop; nop; nop;" \
32 "nop; nop; nop; nop; nop; nop; nop; nop;" \
33 "nop; nop; nop; nop;")
36 #define LCD_CLR 0 // DB0: clear display
37 #define LCD_HOME 1 // DB1: return to home position
38 #define LCD_ENTRY_MODE 2 // DB2: set entry mode
39 #define LCD_ENTRY_INC 1 // DB1: increment
40 #define LCD_ENTRY_SHIFT 0 // DB2: shift
41 #define LCD_ON_CTRL 3 // DB3: turn lcd/cursor on
42 #define LCD_ON_DISPLAY 2 // DB2: turn display on
43 #define LCD_ON_CURSOR 1 // DB1: turn cursor on
44 #define LCD_ON_BLINK 0 // DB0: blinking cursor
45 #define LCD_MOVE 4 // DB4: move cursor/display
46 #define LCD_MOVE_DISP 3 // DB3: move display (0-> move cursor)
47 #define LCD_MOVE_RIGHT 2 // DB2: move right (0-> left)
48 #define LCD_FUNCTION 5 // DB5: function set
49 #define LCD_FUNCTION_8BIT 4 // DB4: set 8BIT mode (0->4BIT mode)
50 #define LCD_FUNCTION_2LINES 3 // DB3: two lines (0->one line)
51 #define LCD_FUNCTION_10DOTS 2 // DB2: 5x10 font (0->5x7 font)
52 #define LCD_CGRAM 6 // DB6: set CG RAM address
53 #define LCD_DDRAM 7 // DB7: set DD RAM address
58 const uint8_t lcdLineAddr[LCD_LINES] = { 0x00, 0x40 };
61 void lcdWriteInit(uint8_t data);
62 void lcdControlWrite(uint8_t data);
63 void ourLcdControlWrite(uint8_t data);
64 void lcdDataWrite(uint8_t data);
65 void lcdSetCursor(uint8_t data);
66 void lcdWrite(uint8_t data);
106 ourLcdControlWrite(1 << LCD_ON_CTRL | 1 << LCD_ON_DISPLAY);
110 void lcdWriteInit(uint8_t data)
112 cbi(LCD_PORT, LCD_RS);
113 lcdControlWrite(data);
117 void lcdControlWrite(uint8_t data)
120 cbi(LCD_PORT, LCD_RS);
125 outb(LCD_DDR, inb(LCD_DDR)|0xF0);
127 outb(LCD_POUT, (inb(LCD_POUT)&0x0F) | (data&0xF0));
128 sbi(LCD_PORT, LCD_E);
130 cbi(LCD_PORT, LCD_E);
134 void ourLcdControlWrite(uint8_t data)
139 cbi(LCD_PORT, LCD_RS);
142 sbi(LCD_PORT, LCD_E);
144 outb(LCD_DDR, inb(LCD_DDR)|0xF0);
146 outb(LCD_POUT, (inb(LCD_POUT)&0x0F) | (data&0xF0));
150 cbi(LCD_PORT, LCD_E);
153 sbi(LCD_PORT, LCD_E);
154 outb(LCD_POUT, (inb(LCD_POUT)&0x0F) | (data<<4));
158 cbi(LCD_PORT, LCD_E);
162 void lcdSetCursor(uint8_t data)
164 cbi(LCD_PORT, LCD_RS);
165 lcdWrite(data | 0x80);
169 void lcdDataWrite(uint8_t data)
171 sbi(LCD_PORT, LCD_RS);
177 void lcdWrite(uint8_t data)
180 outb(LCD_DDR, inb(LCD_DDR)|0xF0);
182 outb(LCD_POUT, (inb(LCD_POUT)&0x0F) | (data&0xF0));
184 sbi(LCD_PORT, LCD_E);
187 cbi(LCD_PORT, LCD_E);
191 outb(LCD_POUT, (inb(LCD_POUT)&0x0F) | (data<<4));
193 sbi(LCD_PORT, LCD_E);
196 cbi(LCD_PORT, LCD_E);
202 void lcdPrintHex_(uint8_t data, uint8_t row, uint8_t col)
204 lcdSetCursor(lcdLineAddr[row] + col);
206 uint8_t temp = ((data & 0xF0) >> 4) + 0x30;
212 temp = (data & 0x0F) + 0x30;
220 void lcdPrintDecU08_(uint8_t data, uint8_t row, uint8_t col)
222 lcdSetCursor(lcdLineAddr[row] + col);
224 uint8_t ones = data % 10;
225 uint8_t tens = (data % 100) / 10;
226 uint8_t hundreds = (data % 1000) / 100;
229 lcdDataWrite(hundreds + 0x30);
231 lcdDataWrite(tens + 0x30);
232 lcdDataWrite(ones + 0x30);
236 void lcdPrintDecS08_(int8_t data, uint8_t row, uint8_t col)
240 uint8_t hundreds = 0;
242 lcdSetCursor(lcdLineAddr[row] + col);
250 tens = (data % 100) / 10;
251 hundreds = (data % 1000) / 100;
252 lcdDataWrite(hundreds + 0x30);
253 lcdDataWrite(tens + 0x30);
254 lcdDataWrite(ones + 0x30);
257 void lcdWriteStr_(
const char *str, uint8_t row, uint8_t col)
265 lcdSetCursor(lcdLineAddr[row] + col);
269 for (i = 0; (i < LCD_LINE_LENGTH - col) && (str[i] !=
'\0'); i++)
271 lcdDataWrite(str[i]);