summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--n/lcd/src/lcd.c128
1 files changed, 123 insertions, 5 deletions
diff --git a/n/lcd/src/lcd.c b/n/lcd/src/lcd.c
index 518c900..842a06d 100644
--- a/n/lcd/src/lcd.c
+++ b/n/lcd/src/lcd.c
@@ -46,8 +46,8 @@ lcd_send_command (u8 cmd)
{
PORTC = (PORTC & 0xf0) | (cmd & 0x0f);
// Pas de RS car on n'écrit pas sur le lcd, c'est une commande !
- PORTD = PORTD | 0x80;
- PORTD = PORTD & 0x7f;
+ PORTD = PORTD | 0x80; // puis E à 1
+ PORTD = PORTD & 0x7f; //
utils_delay_us (40);
}
@@ -55,16 +55,23 @@ lcd_send_command (u8 cmd)
void
lcd_send_character (u8 c)
{
- PORTC = (PORTC & 0xf0) | c; // c'est ça !
+ PORTC = (PORTC & 0xf0) | (c>>4); // c'est ça !
PORTD = (PORTD | 0x40); // 1 à RS
PORTD = PORTD | 0x80; // puis 1 à E
PORTD = PORTD & 0x7f; // puis on remet 0 à E
utils_delay_us (40);
+
+
+ PORTC = (PORTC & 0xf0) | (c & 0xf); // c'est ça !
+ PORTD = PORTD | 0x80; // puis 1 à E
+ PORTD = PORTD & 0x7f; // puis on remet 0 à E
+ PORTD = (PORTD & 0xBF); // 0 à RS
+ utils_delay_us (40);
}
/* Envois une chaîne de caractère. */
void
-lcd_send_string_n (const char *s,u8 i)
+lcd_send_string_n (const char *s, u8 i)
{
u8 cpt ;
lcd_transit_command(0x01); // suffit d'envoyer les bits de gauche à droite : D7D6D5D4 en hexa
@@ -94,7 +101,13 @@ void
lcd_init (void)
{
DDRC = 0x0f;
- DDRD = 0xfc;
+ DDRD = 0xC0;
+ // PD0 RX ( uart )
+ // PD1 TX ( uart )
+ // PD2 - PD5 clavier
+ // PD6 RS ( lcd )
+ // PD7 E ( lcd )
+ PORTD = 0x3C; // pull up
DDRB = 0x01;
utils_delay_ms (15); // suffit d'envoyer les bits de gauche à droite : D7D6D5D4 en hexa
lcd_transit_command (0x01); // efface ecran
@@ -112,10 +125,96 @@ lcd_init (void)
}
void
+lcd_clear(void)
+{
+ lcd_send_command (0x0);
+ lcd_send_command (0x1);
+ utils_delay_ms (20);
+}
+
+char
+key_read (void)
+{
+ char key = 0;
+ PORTC = (PORTC & 0xf0) | 0x0f;
+ uint8_t i = 0;
+ while ( key == 0)
+ {
+ switch (i)
+ {
+ case 0 : PORTC = (PORTC & 0xf0) | 0x0E;
+ break;
+ case 1 : PORTC = (PORTC & 0xf0) | 0x0D;
+ break;
+ case 2 : PORTC = (PORTC & 0xf0) | 0x0B;
+ break;
+ case 3 : PORTC = (PORTC & 0xf0) | 0x07;
+ break;
+ }
+ uint8_t key_tmp = PIND;
+ if ( ~(key_tmp & 0x3c) & 0x04 )
+ switch (i)
+ {
+ case 0 : key = '1';
+ break;
+ case 1 : key = '4';
+ break;
+ case 2 : key = '7';
+ break;
+ case 3 : key = 'A';
+ break;
+ }
+ else if ( ~(key_tmp & 0x3c) & 0x08)
+ switch (i)
+ {
+ case 0 : key = '2';
+ break;
+ case 1 : key = '5';
+ break;
+ case 2 : key = '8';
+ break;
+ case 3 : key = '0';
+ break;
+ }
+ else if ( ~(key_tmp & 0x3c) & 0x10)
+ switch (i)
+ {
+ case 0 : key = '3';
+ break;
+ case 1 : key = '6';
+ break;
+ case 2 : key = '9';
+ break;
+ case 3 : key = 'B';
+ break;
+ }
+ else if ( ~(key_tmp & 0x3c) & 0x20)
+ switch (i)
+ {
+ case 0 : key = '3';
+ break;
+ case 1 : key = 'E';
+ break;
+ case 2 : key = 'D';
+ break;
+ case 3 : key = 'C';
+ break;
+ }
+ i++;
+ if (i==4)
+ i=0;
+ }
+ PORTC = (PORTC & 0xf0);
+ return key;
+}
+
+
+void
proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
{
switch (cmd)
{
+ // reset
case 'z':
if (size != 0)
{
@@ -127,9 +226,27 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
utils_reset ();
}
break;
+ // affiche un message 32 caractère
case 'p':
lcd_send_string_n (args, size);
break;
+ // Efface l'écran
+ case 'C':
+ if (size != 0)
+ {
+ proto_send0 ('?');
+ return;
+ }
+ else
+ {
+ lcd_clear ();
+ }
+ break;
+ // Lit une touche au clavier (bloquant)
+ // revoit un caractère {1234567890ABCDEF}
+ case 'R':
+ proto_send1b ('R',key_read ());
+ break;
default:
/* This is to handle default commands, return an error. */
proto_send0 ('?');
@@ -147,6 +264,7 @@ main (void)
uart0_init ();
proto_send0 ('z');
lcd_init ();
+ lcd_send_string (" LCD initialise Attend Grub ");
while (1)
{
uint8_t c = uart0_getc ();