EA Dog LCD screen library

Committer:
Thur
Date:
Thu Jun 01 14:04:41 2017 +0000
Revision:
0:23354c86eed6
IOGS lcd

Who changed what in which revision?

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