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);
79 ao_mutex_get(&ao_lcd_mutex);
80 ao_lcd_send_ins(0x01);
83 ao_lcd_send_ins(0x04 | 0x02);
84 ao_mutex_put(&ao_lcd_mutex);
88 ao_lcd_goto(uint8_t addr)
90 ao_mutex_get(&ao_lcd_mutex);
91 ao_lcd_send_ins(0x80 | addr);
92 ao_lcd_send_ins(0x04 | 0x02);
93 ao_mutex_put(&ao_lcd_mutex);
99 /* get to 4bit mode */
100 ao_lcd_port_put_nibble(0, 0x3);
101 ao_lcd_port_put_nibble(0, 0x3);
102 ao_lcd_port_put_nibble(0, 0x3);
103 ao_lcd_port_put_nibble(0, 0x2);
106 ao_lcd_send_ins(0x28);
107 /* function set, instruction table 1 */
108 ao_lcd_send_ins(0x29);
111 ao_lcd_send_ins(0x14);
113 /* Power/icon/contrast control*/
114 ao_lcd_send_ins(AO_LCD_POWER_CONTROL);
116 /* Follower control */
117 ao_lcd_send_ins(0x6d);
118 ao_delay(AO_MS_TO_TICKS(200));
121 ao_lcd_contrast_set(0x18);
124 ao_lcd_send_ins(0x08 | 0x04);
131 ao_lcd_contrast(void)
134 if (ao_cmd_status == ao_cmd_success) {
135 printf("setting contrast to %02x\n", ao_cmd_lex_i);
136 ao_lcd_contrast_set(ao_cmd_lex_i & 0x3f);
141 ao_cmd_hex_nibble(void)
143 if ('0' <= ao_cmd_lex_c && ao_cmd_lex_c <= '9')
144 return ao_cmd_lex_c - '0';
145 if ('a' <= ao_cmd_lex_c && ao_cmd_lex_c <= 'f')
146 return ao_cmd_lex_c - ('a' - 10);
147 if ('A' <= ao_cmd_lex_c && ao_cmd_lex_c <= 'F')
148 return ao_cmd_lex_c - ('A' - 10);
149 ao_cmd_status = ao_cmd_syntax_error;
160 if (ao_cmd_status != ao_cmd_success)
162 ao_lcd_send_ins(0x80 | (ao_cmd_lex_i ? 0x40 : 0x00));
164 while (ao_cmd_lex_c != '\n') {
168 c = ao_cmd_hex_nibble() << 4;
170 c |= ao_cmd_hex_nibble();
177 ao_lcd_put_byte(' ');
183 ao_lcd_delay_set(void)
186 if (ao_cmd_status == ao_cmd_success) {
187 printf("setting LCD delay to %d\n", ao_cmd_lex_i);
188 ao_lcd_time = ao_cmd_lex_i;
192 __code struct ao_cmds ao_lcd_cmds[] = {
193 { ao_lcd_start, "S\0Start LCD" },
194 { ao_lcd_contrast, "C <contrast>\0Set LCD contrast" },
195 { ao_lcd_string, "s <line> <string>\0Send string to LCD" },
196 { ao_lcd_delay_set, "t <delay>\0Set LCD delay" },
204 ao_cmd_register(&ao_lcd_cmds[0]);