summaryrefslogtreecommitdiff
path: root/n/lcd/src/lcd.c
diff options
context:
space:
mode:
authorleblanc2006-03-12 14:50:21 +0000
committerleblanc2006-03-12 14:50:21 +0000
commit5641bdcf875ea66ef16a5cd718b87ba3af920d5d (patch)
tree2c93a8243a7de01f33de0784e2ac5b48f8fb04b6 /n/lcd/src/lcd.c
parent547d4bd275b05bc418482b6d14a44350ba8292dc (diff)
On a fait l'affichage LCD en 8 bits
Diffstat (limited to 'n/lcd/src/lcd.c')
-rw-r--r--n/lcd/src/lcd.c148
1 files changed, 148 insertions, 0 deletions
diff --git a/n/lcd/src/lcd.c b/n/lcd/src/lcd.c
new file mode 100644
index 0000000..8b4ed85
--- /dev/null
+++ b/n/lcd/src/lcd.c
@@ -0,0 +1,148 @@
+/* lcd.c */
+/* lcd - affiche des messages sur l'écran lcd. {{{
+ *
+ * Copyright (C) 2006 Christophe Le Blanc
+ *
+ * Robot APB Team/Efrei 2006.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+#include "common.h"
+#include "modules/utils/utils.h"
+#include "modules/uart/uart.h"
+#include "modules/proto/proto.h"
+#include "io.h"
+
+#include <string.h>
+
+/** Envois une commande. */
+void
+lcd_send_command (u8 cmd)
+{
+ PORTC = (PORTC & 0xf0) | (cmd >> 4);
+ PORTD = (PORTD & 0x03) | (cmd << 5);
+ PORTB = (PORTB & 0xfe) | (cmd >> 3 & 0x01);
+ PORTD = PORTD | 0x10;
+ PORTD = PORTD & 0xef;
+ utils_delay_us (40);
+}
+
+/* Envois un caractère. */
+void
+lcd_send_character (u8 c)
+{
+ PORTC = (PORTC & 0xf0) | (c >> 4);
+ PORTD = (PORTD & 0x03) | (c << 5) | 0x04;
+ PORTB = (PORTB & 0xfe) | (c >> 3 & 0x01);
+ PORTD = PORTD | 0x10;
+ PORTD = PORTD & 0xef;
+ utils_delay_us (40);
+}
+
+/* Envois une chaîne de caractère. */
+void
+lcd_send_string_n (const char *s,u8 i)
+{
+ u8 cpt ;
+ lcd_send_command(0x01);
+ utils_delay_ms(2);
+ lcd_send_command(0x02);
+ utils_delay_ms(2);
+ for (cpt = 0 ; cpt < i ; cpt++)
+ {
+ if (cpt == 16)
+ {
+ lcd_send_command(0xc0);
+ utils_delay_us(40);
+ }
+ lcd_send_character(s[cpt]);
+ }
+}
+
+/* Envois une chaîne de caractère. */
+void
+lcd_send_string (const char *s)
+{
+ lcd_send_string_n (s, strlen (s));
+}
+
+/* Initialisation du lcd. */
+void
+lcd_init (void)
+{
+ DDRC = 0x0f;
+ DDRD = 0xfc;
+ DDRB = 0x01;
+ utils_delay_ms (15);
+ lcd_send_command (0x38);
+ utils_delay_ms (4.5);
+ lcd_send_command (0x38);
+ utils_delay_ms (1);
+ lcd_send_command (0x38);
+ lcd_send_command (0x38);
+ lcd_send_command (0x08);
+ lcd_send_command (0x01);
+ utils_delay_ms (2);
+ lcd_send_command (0x06);
+ lcd_send_command (0x80);
+ lcd_send_command (0x0f);
+}
+
+void
+proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
+{
+ switch (cmd)
+ {
+ case 'z':
+ if (size != 0)
+ {
+ proto_send0 ('?');
+ return;
+ }
+ else
+ {
+ utils_reset ();
+ }
+ break;
+ case 'p':
+ lcd_send_string_n (args, size);
+ break;
+ default:
+ /* This is to handle default commands, return an error. */
+ proto_send0 ('?');
+ return;
+ }
+ /* When no error acknoledge. */
+ proto_send (cmd, size, args);
+}
+
+/* Fonction principale */
+int
+main (void)
+{
+ sei ();
+ uart0_init ();
+ proto_send0 ('z');
+ lcd_init ();
+ while (1)
+ {
+ uint8_t c = uart0_getc ();
+ proto_accept (c);
+ }
+ return 0;
+}