Time: 17:33 Date: 10/12/2017 Description: Task 1,7,8 Currently Functioning

Dependencies:   BME280 BMP280 TextLCD

Working Repository

Committer:
chills
Date:
Wed Dec 27 21:46:31 2017 +0000
Revision:
20:cbb71f84cff9
Child:
47:6d128e500875
2017_12_27 21:43; LCD Class Implemented;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chills 20:cbb71f84cff9 1 #include "mbed.h" //Include the mbed libraries
chills 20:cbb71f84cff9 2 #include "LCD.hpp" //Include the header file, this acts like a series of forward declarations
chills 20:cbb71f84cff9 3
chills 20:cbb71f84cff9 4 //Constructor
chills 20:cbb71f84cff9 5 LCD::LCD(PinName E,PinName RS,PinName RW,PinName DB0,PinName DB1,PinName DB2,PinName DB3,PinName DB4,PinName DB5,PinName DB6,PinName DB7) : _E(E),_RS(RS),_RW(RW),_DB0(DB0),_DB1(DB1),_DB2(DB2),_DB3(DB3),_DB4(DB4),_DB5(DB5),_DB6(DB6),_DB7(DB7)
chills 20:cbb71f84cff9 6 {}
chills 20:cbb71f84cff9 7
chills 20:cbb71f84cff9 8 LCD::~LCD(){} //Destructor
chills 20:cbb71f84cff9 9
chills 20:cbb71f84cff9 10 void LCD::clock_in(){_E = 1; wait(0.001); _E = 0; wait(0.001); _E = 1;}
chills 20:cbb71f84cff9 11
chills 20:cbb71f84cff9 12 void LCD::Function_Set() {_RS = 0; _RW = 0; _DB7 = 0; _DB6 = 0; _DB5 = 1; _DB4 = 1; _DB3 = 1; _DB2 = 1; _DB1 = 0; _DB0 = 0; clock_in();} //DB4 sets Data Width. DB3 sets No. Lines. DB2 sets font.
chills 20:cbb71f84cff9 13 void LCD::Display_Off() {_RS = 0; _RW = 0; _DB7 = 0; _DB6 = 0; _DB5 = 0; _DB4 = 0; _DB3 = 1; _DB2 = 0; _DB1 = 0; _DB0 = 0; clock_in();} //Turns the display off.
chills 20:cbb71f84cff9 14 void LCD::Display_Clear() {_RS = 0; _RW = 0; _DB7 = 0; _DB6 = 0; _DB5 = 0; _DB4 = 0; _DB3 = 0; _DB2 = 0; _DB1 = 0; _DB0 = 1; clock_in();} //Clears display sets position to 0.
chills 20:cbb71f84cff9 15 void LCD::Entry_Mode_Set() {_RS = 0; _RW = 0; _DB7 = 0; _DB6 = 0; _DB5 = 0; _DB4 = 0; _DB3 = 0; _DB2 = 1; _DB1 = 1; _DB0 = 0; clock_in();} //DB1 sets increment(1) vs decrement(0). DB0 sets display shift(1) vs cursor shift(0).
chills 20:cbb71f84cff9 16 void LCD::Display_On() {_RS = 0; _RW = 0; _DB7 = 0; _DB6 = 0; _DB5 = 0; _DB4 = 0; _DB3 = 1; _DB2 = 1; _DB1 = 1; _DB0 = 1; clock_in();} //DB1 sets cursor on(1) vs off(0). DB0 sets blink(1) vs not(0).
chills 20:cbb71f84cff9 17
chills 20:cbb71f84cff9 18 void LCD::Initialise(){ //Use previous functions to initialise LCD
chills 20:cbb71f84cff9 19 Function_Set(); wait(0.020); //Function set followed by wait.
chills 20:cbb71f84cff9 20 Display_Off(); wait(0.020); //Display off followed by wait.
chills 20:cbb71f84cff9 21 Display_Clear(); wait(0.020); //Display clear followed by wait.
chills 20:cbb71f84cff9 22 Entry_Mode_Set(); wait(0.020); //Entry Mode Set followed by wait.
chills 20:cbb71f84cff9 23 Display_On(); wait(0.020); //Turn the display on.
chills 20:cbb71f84cff9 24 DDRAM_Address(0); wait(0.020); //Set the address to 0.
chills 20:cbb71f84cff9 25 }
chills 20:cbb71f84cff9 26
chills 20:cbb71f84cff9 27 void LCD::DDRAM_Address(int Address){ //Sets the address to integer address
chills 20:cbb71f84cff9 28 _RS = 0;
chills 20:cbb71f84cff9 29 _RW = 0;
chills 20:cbb71f84cff9 30 _DB7 = 1;
chills 20:cbb71f84cff9 31 _DB6 = (Address & 0b1000000) >> 6; _DB5 = (Address & 0b0100000) >> 5; _DB4 = (Address & 0b0010000) >> 4; //Use bit shifting to convert integer to binary.
chills 20:cbb71f84cff9 32 _DB3 = (Address & 0b0001000) >> 3; _DB2 = (Address & 0b0000100) >> 2; _DB1 = (Address & 0b0000010) >> 1; _DB0 = (Address & 0b0000001) >> 0; //Use bit shifting to convert integer to binary.
chills 20:cbb71f84cff9 33 clock_in(); //Clock the data into the LCD.
chills 20:cbb71f84cff9 34 }
chills 20:cbb71f84cff9 35
chills 20:cbb71f84cff9 36 void LCD::Write_String(string Word){ //Writes the string Word to the LCD starting at the current address
chills 20:cbb71f84cff9 37 int ASCII_Converted; //Temporary values
chills 20:cbb71f84cff9 38 for (int i = 0; i < Word.length(); i++) //For loop running between 0 and length of string Word
chills 20:cbb71f84cff9 39 {
chills 20:cbb71f84cff9 40 ASCII_Converted = Word.at(i); //Set ASCII_Converted to current character value
chills 20:cbb71f84cff9 41 _RS = 1; _RW = 0; //Set RS and RW
chills 20:cbb71f84cff9 42 _DB7 = (ASCII_Converted & 0b10000000) >> 7; _DB6 = (ASCII_Converted & 0b01000000) >> 6; _DB5 = (ASCII_Converted & 0b00100000) >> 5; _DB4 = (ASCII_Converted & 0b00010000) >> 4; //Use bit shifting to convert hex to binary.
chills 20:cbb71f84cff9 43 _DB3 = (ASCII_Converted & 0b00001000) >> 3; _DB2 = (ASCII_Converted & 0b00000100) >> 2; _DB1 = (ASCII_Converted & 0b00000010) >> 1; _DB0 = (ASCII_Converted & 0b00000001) >> 0; //Use bit shifting to convert hex to binary.
chills 20:cbb71f84cff9 44 clock_in(); //Clock the data into the LCD.
chills 20:cbb71f84cff9 45 }
chills 20:cbb71f84cff9 46 }
chills 20:cbb71f84cff9 47