Programme de test de l'afficheur LCD Grove 16x2 Black on Yellow sur bus I2C

Dependencies:   mbed

Committer:
pierreprovent
Date:
Tue Dec 08 15:46:51 2020 +0000
Revision:
1:1342700e4846
Programme de test afficheur LCD Grove 16x2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pierreprovent 1:1342700e4846 1 #include "mbed.h"
pierreprovent 1:1342700e4846 2 #include "LCD.h"
pierreprovent 1:1342700e4846 3
pierreprovent 1:1342700e4846 4 LCD::LCD(PinName sda, PinName scl):i2c(sda, scl)
pierreprovent 1:1342700e4846 5 {
pierreprovent 1:1342700e4846 6 init();
pierreprovent 1:1342700e4846 7 }
pierreprovent 1:1342700e4846 8
pierreprovent 1:1342700e4846 9 void LCD::clear()
pierreprovent 1:1342700e4846 10 {
pierreprovent 1:1342700e4846 11 sendCommand(?????????????);
pierreprovent 1:1342700e4846 12 wait_us(1600);
pierreprovent 1:1342700e4846 13 }
pierreprovent 1:1342700e4846 14
pierreprovent 1:1342700e4846 15 void LCD::print(char *str)
pierreprovent 1:1342700e4846 16 {
pierreprovent 1:1342700e4846 17 data[0] = 0x40;
pierreprovent 1:1342700e4846 18 while(*str) {
pierreprovent 1:1342700e4846 19 data[1] = *str;
pierreprovent 1:1342700e4846 20 i2c.write(LCD_ADDRESS, data, 2);
pierreprovent 1:1342700e4846 21 str++;
pierreprovent 1:1342700e4846 22 }
pierreprovent 1:1342700e4846 23 }
pierreprovent 1:1342700e4846 24
pierreprovent 1:1342700e4846 25 void LCD::cursor(char col, char row)
pierreprovent 1:1342700e4846 26 {
pierreprovent 1:1342700e4846 27 if(row == 0) {
pierreprovent 1:1342700e4846 28 col = col | 0x80;
pierreprovent 1:1342700e4846 29 } else {
pierreprovent 1:1342700e4846 30 col = col | 0xc0;
pierreprovent 1:1342700e4846 31 }
pierreprovent 1:1342700e4846 32 sendCommand(col);
pierreprovent 1:1342700e4846 33 }
pierreprovent 1:1342700e4846 34
pierreprovent 1:1342700e4846 35 void LCD::sendCommand(char value)
pierreprovent 1:1342700e4846 36 {
pierreprovent 1:1342700e4846 37 data[0] = 0x80 ; // Co = 1, RS = 0 (Command transmitted)
pierreprovent 1:1342700e4846 38 data[1] = value;
pierreprovent 1:1342700e4846 39 i2c.write(LCD_ADDRESS, data, 2);
pierreprovent 1:1342700e4846 40 }
pierreprovent 1:1342700e4846 41
pierreprovent 1:1342700e4846 42 void LCD::init()
pierreprovent 1:1342700e4846 43 {
pierreprovent 1:1342700e4846 44 // Attendre au moins 30 ms après la mise en tension de la carte
pierreprovent 1:1342700e4846 45 wait_ms(50);
pierreprovent 1:1342700e4846 46 // Choisir le type d'affichage : 2 lignes de 5x8 points /caractère
pierreprovent 1:1342700e4846 47 sendCommand(???????????????);
pierreprovent 1:1342700e4846 48 // Attendre au moins 39 us
pierreprovent 1:1342700e4846 49 wait_us(45);
pierreprovent 1:1342700e4846 50 // Allumer l'afficheur, pas de curseur, il ne clignote pas
pierreprovent 1:1342700e4846 51 sendCommand(????????????);
pierreprovent 1:1342700e4846 52 // Attendre au moins 39 us
pierreprovent 1:1342700e4846 53 wait_us(45);
pierreprovent 1:1342700e4846 54 // Effacer l'afficheur
pierreprovent 1:1342700e4846 55 ???????????????
pierreprovent 1:1342700e4846 56 // Curseur se déplace à droite à chaque caractère, pas de "shift" de l'affichage
pierreprovent 1:1342700e4846 57 sendCommand(0x06);
pierreprovent 1:1342700e4846 58 }