summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--n/lcd/src/lcd.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/n/lcd/src/lcd.c b/n/lcd/src/lcd.c
index 8b4ed85..adb590b 100644
--- a/n/lcd/src/lcd.c
+++ b/n/lcd/src/lcd.c
@@ -34,11 +34,10 @@
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;
+ PORTC = (PORTC & 0xf0) | cmd;
+ // Pas de RS car on n'écrit pas sur le lcd, c'est une commande !
+ PORTD = PORTD | 0x80;
+ PORTD = PORTD & 0x7f;
utils_delay_us (40);
}
@@ -46,11 +45,10 @@ lcd_send_command (u8 cmd)
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;
+ PORTC = (PORTC & 0xf0) | c; // 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);
}
@@ -59,15 +57,18 @@ void
lcd_send_string_n (const char *s,u8 i)
{
u8 cpt ;
- lcd_send_command(0x01);
+ lcd_send_command(0x0); // suffit d'envoyer les bits de gauche à droite : D7D6D5D4 en hexa
+ lcd_send_command(0x1);
utils_delay_ms(2);
- lcd_send_command(0x02);
+ lcd_send_command(0x0);
+ lcd_send_command(0x2);
utils_delay_ms(2);
for (cpt = 0 ; cpt < i ; cpt++)
{
if (cpt == 16)
{
- lcd_send_command(0xc0);
+ lcd_send_command(0xc);
+ lcd_send_command(0x0);
utils_delay_us(40);
}
lcd_send_character(s[cpt]);
@@ -88,19 +89,27 @@ lcd_init (void)
DDRC = 0x0f;
DDRD = 0xfc;
DDRB = 0x01;
- utils_delay_ms (15);
- lcd_send_command (0x38);
+ utils_delay_ms (15); // suffit d'envoyer les bits de gauche à droite : D7D6D5D4 en hexa
+ lcd_send_command (0x0); // efface ecran
+ lcd_send_command (0x1);
+ lcd_send_command (0x0);
+ lcd_send_command (0x0);
+ lcd_send_command (0x1);
+ lcd_send_command (0x3); // force 8 bits
utils_delay_ms (4.5);
- lcd_send_command (0x38);
+ lcd_send_command (0x3);
utils_delay_ms (1);
- lcd_send_command (0x38);
- lcd_send_command (0x38);
- lcd_send_command (0x08);
- lcd_send_command (0x01);
+ lcd_send_command (0x3);
+ lcd_send_command (0x2); // passage mode 4 bits
+ lcd_send_command (0x2); // def afficheur
+ lcd_send_command (0x8);
utils_delay_ms (2);
- lcd_send_command (0x06);
- lcd_send_command (0x80);
- lcd_send_command (0x0f);
+ lcd_send_command (0x0); // affichage fonction
+ lcd_send_command (0xc);
+ lcd_send_command (0x0); // déplacement curseur
+ lcd_send_command (0x6);
+ lcd_send_command (0x0); // efface ecran
+ lcd_send_command (0x1);
}
void