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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 static uint16_t ao_lcd_time = 3;
23 static uint8_t ao_lcd_mutex;
28 volatile uint16_t count;
30 for (count = 0; count < ao_lcd_time; count++)
35 ao_lcd_send_ins(uint8_t ins)
37 // printf("send ins %02x\n", ins);
38 // ao_lcd_wait_idle();
41 ao_lcd_port_put_nibble(0, ins >> 4);
42 ao_lcd_port_put_nibble(0, ins & 0xf);
46 ao_lcd_put_byte(uint8_t c)
48 // printf ("send data %02x\n", c);
49 // ao_lcd_wait_idle();
51 ao_lcd_port_put_nibble(1, c >> 4);
52 ao_lcd_port_put_nibble(1, c & 0x0f);
56 ao_lcd_putstring(char *string)
60 ao_mutex_get(&ao_lcd_mutex);
61 while ((c = (uint8_t) *string++))
62 ao_lcd_put_byte((uint8_t) c);
63 ao_mutex_put(&ao_lcd_mutex);
66 #define AO_LCD_POWER_CONTROL 0x54
69 ao_lcd_contrast_set(uint8_t contrast)
71 ao_mutex_get(&ao_lcd_mutex);
72 ao_lcd_send_ins(AO_LCD_POWER_CONTROL | ((contrast >> 4) & 0x3));
73 ao_lcd_send_ins(0x70 | (contrast & 0xf));
74 ao_mutex_put(&ao_lcd_mutex);
78 ao_lcd_cursor_on(void)
80 ao_mutex_get(&ao_lcd_mutex);
81 ao_lcd_send_ins(0x08 | 0x04 | 0x02 | 0x01);
82 ao_mutex_put(&ao_lcd_mutex);
86 ao_lcd_cursor_off(void)
88 ao_mutex_get(&ao_lcd_mutex);
89 ao_lcd_send_ins(0x08 | 0x04);
90 ao_mutex_put(&ao_lcd_mutex);
96 ao_mutex_get(&ao_lcd_mutex);
97 ao_lcd_send_ins(0x01);
100 ao_lcd_send_ins(0x04 | 0x02);
101 ao_mutex_put(&ao_lcd_mutex);
105 ao_lcd_goto(uint8_t addr)
107 ao_mutex_get(&ao_lcd_mutex);
108 ao_lcd_send_ins(0x80 | addr);
109 ao_lcd_send_ins(0x04 | 0x02);
110 ao_mutex_put(&ao_lcd_mutex);
116 /* get to 4bit mode */
117 ao_lcd_port_put_nibble(0, 0x3);
118 ao_lcd_port_put_nibble(0, 0x3);
119 ao_lcd_port_put_nibble(0, 0x3);
120 ao_lcd_port_put_nibble(0, 0x2);
123 ao_lcd_send_ins(0x28);
124 /* function set, instruction table 1 */
125 ao_lcd_send_ins(0x29);
128 ao_lcd_send_ins(0x14);
130 /* Power/icon/contrast control*/
131 ao_lcd_send_ins(AO_LCD_POWER_CONTROL);
133 /* Follower control */
134 ao_lcd_send_ins(0x6d);
135 ao_delay(AO_MS_TO_TICKS(200));
138 ao_lcd_contrast_set(0x18);
141 ao_lcd_send_ins(0x08 | 0x04);