2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 static uint16_t ao_lcd_time = 3;
22 static __xdata uint8_t ao_lcd_mutex;
27 volatile uint16_t count;
29 for (count = 0; count < ao_lcd_time; count++)
34 ao_lcd_send_ins(uint8_t ins)
36 // printf("send ins %02x\n", ins);
37 // ao_lcd_wait_idle();
40 ao_lcd_port_put_nibble(0, ins >> 4);
41 ao_lcd_port_put_nibble(0, ins & 0xf);
45 ao_lcd_put_byte(uint8_t c)
47 // printf ("send data %02x\n", c);
48 // ao_lcd_wait_idle();
50 ao_lcd_port_put_nibble(1, c >> 4);
51 ao_lcd_port_put_nibble(1, c & 0x0f);
55 ao_lcd_putstring(char *string)
59 ao_mutex_get(&ao_lcd_mutex);
60 while ((c = (uint8_t) *string++))
61 ao_lcd_put_byte((uint8_t) c);
62 ao_mutex_put(&ao_lcd_mutex);
65 #define AO_LCD_POWER_CONTROL 0x54
68 ao_lcd_contrast_set(uint8_t contrast)
70 ao_mutex_get(&ao_lcd_mutex);
71 ao_lcd_send_ins(AO_LCD_POWER_CONTROL | ((contrast >> 4) & 0x3));
72 ao_lcd_send_ins(0x70 | (contrast & 0xf));
73 ao_mutex_put(&ao_lcd_mutex);
77 ao_lcd_cursor_on(void)
79 ao_mutex_get(&ao_lcd_mutex);
80 ao_lcd_send_ins(0x08 | 0x04 | 0x02 | 0x01);
81 ao_mutex_put(&ao_lcd_mutex);
85 ao_lcd_cursor_off(void)
87 ao_mutex_get(&ao_lcd_mutex);
88 ao_lcd_send_ins(0x08 | 0x04);
89 ao_mutex_put(&ao_lcd_mutex);
95 ao_mutex_get(&ao_lcd_mutex);
96 ao_lcd_send_ins(0x01);
99 ao_lcd_send_ins(0x04 | 0x02);
100 ao_mutex_put(&ao_lcd_mutex);
104 ao_lcd_goto(uint8_t addr)
106 ao_mutex_get(&ao_lcd_mutex);
107 ao_lcd_send_ins(0x80 | addr);
108 ao_lcd_send_ins(0x04 | 0x02);
109 ao_mutex_put(&ao_lcd_mutex);
115 /* get to 4bit mode */
116 ao_lcd_port_put_nibble(0, 0x3);
117 ao_lcd_port_put_nibble(0, 0x3);
118 ao_lcd_port_put_nibble(0, 0x3);
119 ao_lcd_port_put_nibble(0, 0x2);
122 ao_lcd_send_ins(0x28);
123 /* function set, instruction table 1 */
124 ao_lcd_send_ins(0x29);
127 ao_lcd_send_ins(0x14);
129 /* Power/icon/contrast control*/
130 ao_lcd_send_ins(AO_LCD_POWER_CONTROL);
132 /* Follower control */
133 ao_lcd_send_ins(0x6d);
134 ao_delay(AO_MS_TO_TICKS(200));
137 ao_lcd_contrast_set(0x18);
140 ao_lcd_send_ins(0x08 | 0x04);