Ce site contient essentiellement des notes de travail. Le contenu est en constante évolution, et loin d'être achevé. (+ d'infos)
La plupart des documentations informatiques sont orientées Debian / Ubuntu.

Electronique/Hardware/Ecrans/LCD HD44780/Arduino

De Ordinoscope.net
Sauter à la navigation Sauter à la recherche

Introduction

L'exemple suivant est basé sur le câblage standard d'un écran HD44780.

L'utilisation d'un LCD shield requiert en principe la librairie LCD4Bit_mod.

 #include <LCD4Bit_mod.h> 
 LCD4Bit_mod lcd = LCD4Bit_mod(2);

Pour utiliser la librairie LiquidCrystal à la place, instruire l'objet avec ces paramètres:

 #include <LiquidCrystal.h>
 LiquidCrystal lcd (8, 9, 4, 5, 6, 7);

Plan de câblage

HD44780 - Arduino.png
Schéma fait avec Fritzing
HD44780 - Arduino schem.png

Pinout

LCD Pin Number Symbol Function
1 Vss Display power ground
2 Vdd Display power +5V
3 Vo Contrast Adjust. Altered by adjusting the voltage to this pin, grounding it sets it to maximum contrast.
4 RS Register select
5 R/W Data read/write selector. Its possible to read information from a display however there's no need for it here so grounding it sets it permanently write.
6 E Enable strobe
7 DB0 Data Bus 0
8 DB1 Data Bus 1
9 DB2 Data Bus 2
10 DB3 Data Bus 3
11 DB4 Data Bus 4
12 DB5 Data Bus 5
13 DB6 Data Bus 6
14 DB7 Data Bus 7
15 A LED backlight power +5V
16 K LED backlight power ground

Exemples

Caractères personnalisés

/*
Example usage of custom characters with LiquidCrystal LCD display on Arduino
It will show a turning clock on the upper-left of the screen
Bitmap designer can be found here: http://www.quinapalus.com/hd44780udg.html

 The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 */

#include <LiquidCrystal.h>
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);  // standard pinout
// LiquidCrystal lcd (8, 9, 4, 5, 6, 7);  // LCD shield pinout

int clock[8][7] = {
  {0x0,0xe,0x15,0x15,0x11,0xe,0x0},
  {0x0,0xe,0x17,0x15,0x11,0xe,0x0},
  {0x0,0xe,0x17,0x17,0x11,0xe,0x0},
  {0x0,0xe,0x17,0x17,0x13,0xe,0x0},
  {0x0,0xe,0x17,0x17,0x17,0xe,0x0},
  {0x0,0xe,0x17,0x17,0x1f,0xe,0x0},
  {0x0,0xe,0x17,0x1f,0x1f,0xe,0x0},
  {0x0,0xe,0x1f,0x1f,0x1f,0xe,0x0}
};

void setup() {
  lcd.begin (16,2);

  for (int i = 0; i < 8; i++) {
    defineCharacter(i, clock[i]);
  }
}

void loop() {
  for (int i = 0; i < 8; i++) {
    lcd.setCursor (0, 0);
    lcd.write (i);
    delay (500);
  }
}

/**
 * @see http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235524565
 */
int defineCharacter (int ascii, int *data) {
    int baseAddress = (ascii * 8) + 64;  
    // baseAddress = 64 | (ascii << 3);
    lcd.command(baseAddress);
    for (int i = 0; i < 8; i++)
        lcd.write (data[i]);
    lcd.command(128);
    return ascii;
}

Références