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

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
pierreprovent
Date:
Tue Dec 08 15:46:51 2020 +0000
Parent:
0:3dabc22261b1
Commit message:
Programme de test afficheur LCD Grove 16x2

Changed in this revision

LCD.cpp Show annotated file Show diff for this revision Revisions of this file
LCD.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 3dabc22261b1 -r 1342700e4846 LCD.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD.cpp	Tue Dec 08 15:46:51 2020 +0000
@@ -0,0 +1,58 @@
+#include "mbed.h"
+#include "LCD.h"
+
+LCD::LCD(PinName sda, PinName scl):i2c(sda, scl)
+{
+    init();
+}
+
+void LCD::clear()
+{
+    sendCommand(?????????????);
+    wait_us(1600);
+}
+
+void LCD::print(char *str)
+{
+    data[0] = 0x40;
+    while(*str) {
+        data[1] = *str;
+        i2c.write(LCD_ADDRESS, data, 2);
+        str++;
+    }
+}
+
+void LCD::cursor(char col, char row)
+{
+    if(row == 0) {
+        col = col | 0x80;
+    } else {
+        col = col | 0xc0;
+    }
+    sendCommand(col);
+}
+
+void LCD::sendCommand(char value)
+{
+    data[0] = 0x80 ; // Co = 1, RS = 0 (Command transmitted)
+    data[1] = value;
+    i2c.write(LCD_ADDRESS, data, 2);
+}
+
+void LCD::init()
+{
+    // Attendre au moins 30 ms après la mise en tension de la carte
+    wait_ms(50);
+    // Choisir le type d'affichage : 2 lignes de 5x8 points /caractère
+    sendCommand(???????????????);
+    // Attendre au moins 39 us
+    wait_us(45);
+    // Allumer l'afficheur, pas de curseur, il ne clignote pas
+    sendCommand(????????????);
+    // Attendre au moins 39 us
+    wait_us(45);
+    // Effacer l'afficheur
+    ???????????????
+    // Curseur se déplace à droite à chaque caractère, pas de "shift" de l'affichage
+    sendCommand(0x06);
+}
diff -r 3dabc22261b1 -r 1342700e4846 LCD.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD.h	Tue Dec 08 15:46:51 2020 +0000
@@ -0,0 +1,17 @@
+#include "mbed.h"
+
+#define LCD_ADDRESS   (0x3E << 1)
+
+class LCD
+{
+public:
+    LCD(PinName sda, PinName scl);// constructor
+    void clear();
+    void print(char *str);
+    void cursor(char col, char row);
+private:
+    char data[2];
+    void init();
+    void sendCommand(char value);
+    I2C i2c;
+};
diff -r 3dabc22261b1 -r 1342700e4846 main.cpp
--- a/main.cpp	Thu Oct 22 11:49:39 2020 +0000
+++ b/main.cpp	Tue Dec 08 15:46:51 2020 +0000
@@ -1,28 +1,22 @@
 #include "mbed.h"
- 
-Serial pc(USBTX, USBRX);
+#include "LCD.h"
 
-AnalogIn potentiometre(PC_3); // A2 connecteur Arduino
-AnalogIn luminosite(PC_0); // A1 connecteur Arduino
-
-DigitalOut led(PF_12); //D8 Connecteur Arduino
+LCD lcd(PB_9,PB_8);
+// PB_9 : I2C broche SDA platine Grove
+// PB_8 : I2C broche SCL platine Grove
+AnalogIn vsense(ADC_TEMP); // Capteur de température interne
 
-int main() {
-    float val;
-    
-    pc.printf("\nExemple de conversion analogique-numerique\n");
-    
+int main()
+{
+    char chaine[17] ;
+    float T ;
+    lcd.cursor(3,0);
+    lcd.print("T interne");
     while(1) {
-        val = potentiometre.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
-        val = val* 3300; // Change the value to be in the 0 to 3300 range
-        pc.printf("Tension = %6.f mV\n", val);
-        pc.printf("\033[1A");
-        if (val > 1000) { // If the value is greater than 1V then switch the LED on
-          led = 1;
-        }
-        else {
-          led = 0;
-        }
-        wait(0.2); // 200 ms
+        T = (vsense.read()*3.3f -0.76f)/2.5e-3f + 25 ;
+        sprintf(chaine, "%.2f C", T);
+        lcd.cursor(4,1);
+        lcd.print(chaine);
+        wait(1);
     }
 }