Librairie nécessaire pour utiliser le Lcd de l'IOGS

Committer:
Thur
Date:
Tue Jun 06 09:30:19 2017 +0000
Revision:
3:f5877d3dcc0f
Parent:
2:bcb0d1541b67
correction Str Affichage;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Thur 0:8487a7d2a20e 1 #include "Lcd.h"
Thur 0:8487a7d2a20e 2 #include "mbed.h"
Thur 0:8487a7d2a20e 3
Thur 0:8487a7d2a20e 4 Lcd::Lcd(PinName rs, PinName sck, PinName miso, PinName mosi,PinName cs) : RS_LCD(rs),spi(mosi,miso,sck),CS(cs) {};
Thur 0:8487a7d2a20e 5
Thur 0:8487a7d2a20e 6
Thur 0:8487a7d2a20e 7 void Lcd::write_LCD(char c)
Thur 0:8487a7d2a20e 8 {
Thur 0:8487a7d2a20e 9 CS = 0;
Thur 0:8487a7d2a20e 10 RS_LCD = 1;
Thur 0:8487a7d2a20e 11 spi.write(c);
Thur 0:8487a7d2a20e 12 // wait_ms(1);
Thur 0:8487a7d2a20e 13 RS_LCD = 1;
Thur 0:8487a7d2a20e 14 CS = 1;
Thur 0:8487a7d2a20e 15 return;
Thur 0:8487a7d2a20e 16 }
Thur 0:8487a7d2a20e 17
Thur 0:8487a7d2a20e 18 void Lcd::writeStr_LCD(char c[], char ligne, char colonne)
Thur 0:8487a7d2a20e 19 {
Thur 0:8487a7d2a20e 20 char i=0;
Thur 0:8487a7d2a20e 21 setPosition(ligne,colonne);
Thur 0:8487a7d2a20e 22 while(c[i] != '\0') {
Thur 0:8487a7d2a20e 23 write_LCD(c[i]);
Thur 0:8487a7d2a20e 24 i++;
Thur 0:8487a7d2a20e 25 }
Thur 0:8487a7d2a20e 26 char lig = i/16 + 1;
Thur 0:8487a7d2a20e 27 char col = i%16 + 1;
Thur 0:8487a7d2a20e 28 setPosition(lig,col);
Thur 0:8487a7d2a20e 29 }
Thur 0:8487a7d2a20e 30
Thur 0:8487a7d2a20e 31 void Lcd::writeCmd_LCD(char c)
Thur 0:8487a7d2a20e 32 {
Thur 0:8487a7d2a20e 33 CS =0;
Thur 0:8487a7d2a20e 34 RS_LCD =0;
Thur 0:8487a7d2a20e 35 spi.write(c);
Thur 0:8487a7d2a20e 36 RS_LCD = 1;
Thur 0:8487a7d2a20e 37 CS = 1;
Thur 0:8487a7d2a20e 38 return;
Thur 0:8487a7d2a20e 39 }
Thur 0:8487a7d2a20e 40
Thur 0:8487a7d2a20e 41 void Lcd::setPosition(char ligne, char colonne)
Thur 0:8487a7d2a20e 42 {
Thur 0:8487a7d2a20e 43 char adress = 0x80 + ((ligne-1)*16) + (colonne -1);
Thur 0:8487a7d2a20e 44 writeCmd_LCD(adress);
Thur 0:8487a7d2a20e 45 wait_ms(1);
Thur 0:8487a7d2a20e 46 return;
Thur 0:8487a7d2a20e 47 }
Thur 2:bcb0d1541b67 48 void Lcd::clear_LCD(void){
Thur 2:bcb0d1541b67 49 CS = 0;
Thur 2:bcb0d1541b67 50 RS_LCD=0;
Thur 2:bcb0d1541b67 51 writeCmd_LCD(0x01); //Clear Display
Thur 2:bcb0d1541b67 52 wait_ms(2); //delay 2 ms
Thur 2:bcb0d1541b67 53 RS_LCD =1;
Thur 2:bcb0d1541b67 54 CS=1;
Thur 2:bcb0d1541b67 55 return;
Thur 2:bcb0d1541b67 56 }
Thur 2:bcb0d1541b67 57
Thur 0:8487a7d2a20e 58 void Lcd::init_SPI(void)
Thur 0:8487a7d2a20e 59 {
Thur 0:8487a7d2a20e 60 // Chip must be deselected
Thur 0:8487a7d2a20e 61 CS = 1;
Thur 0:8487a7d2a20e 62 // Setup the spi for 8 bit data, high steady state clock,
Thur 0:8487a7d2a20e 63 // second edge capture, with a 1MHz clock rate
Thur 0:8487a7d2a20e 64 spi.format(8,3);
Thur 0:8487a7d2a20e 65 spi.frequency(10000);
Thur 0:8487a7d2a20e 66 // Select the device by seting chip select low
Thur 0:8487a7d2a20e 67 }
Thur 0:8487a7d2a20e 68
Thur 0:8487a7d2a20e 69 void Lcd::init_LCD(void)
Thur 0:8487a7d2a20e 70 {
Thur 0:8487a7d2a20e 71 init_SPI();
Thur 0:8487a7d2a20e 72 wait_ms(10);
Thur 0:8487a7d2a20e 73 CS = 0;
Thur 0:8487a7d2a20e 74 RS_LCD = 0;
Thur 0:8487a7d2a20e 75 spi.write(0x29); // Function Set - Table 1
Thur 0:8487a7d2a20e 76 spi.write(0x1D); // Bias Set
Thur 0:8487a7d2a20e 77 spi.write(0x50); // Power Control
Thur 0:8487a7d2a20e 78 spi.write(0x6C); // Follower Control
Thur 0:8487a7d2a20e 79 spi.write(0x7C); // Contrast Set
Thur 0:8487a7d2a20e 80 spi.write(0x03); // Function Set - Table 0
Thur 0:8487a7d2a20e 81 spi.write(0x0F);
Thur 0:8487a7d2a20e 82 spi.write(0x01); // Clear Display
Thur 0:8487a7d2a20e 83 wait_ms(2);
Thur 0:8487a7d2a20e 84 spi.write(0x06); // Display On
Thur 0:8487a7d2a20e 85 wait_ms(10);
Thur 0:8487a7d2a20e 86 RS_LCD=1;
Thur 0:8487a7d2a20e 87 CS=1;
Thur 0:8487a7d2a20e 88 wait_ms(10);
Thur 0:8487a7d2a20e 89 return;
Thur 0:8487a7d2a20e 90 }