Plymouth ELEC351 Group T / Mbed 2 deprecated 2017_12_271329_LCDTrial

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
chills
Date:
Wed Dec 27 18:26:50 2017 +0000
Parent:
3:6ee7c8ce0b7a
Commit message:
2017_12_27 18:23; Working LCD Class!!!

Changed in this revision

LCD.cpp Show annotated file Show diff for this revision Revisions of this file
LCD.hpp 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD.cpp	Wed Dec 27 18:26:50 2017 +0000
@@ -0,0 +1,52 @@
+#include "mbed.h"           //Include the mbed libraries
+#include "LCD.hpp"          //Include the header file, this acts like a series of forward declarations
+ 
+//Constructor
+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)
+{}
+
+LCD::~LCD(){}   //Destructor
+
+void LCD::clock_in(){_E = 1; wait(0.001); _E = 0; wait(0.001); _E = 1;}
+
+void LCD::Binary_Convert(int Integer){
+
+}
+
+
+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();}
+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();}
+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();}
+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();}
+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();}
+
+void LCD::Initialise(){
+        Function_Set();     wait(0.020);
+        Display_Off();      wait(0.020);
+        Display_Clear();    wait(0.020);
+        Entry_Mode_Set();   wait(0.020);
+        Display_On();       wait(0.020);
+        DDRAM_Address(0);   wait(0.020);
+}
+
+void LCD::DDRAM_Address(int Address){
+    _RS = 0; 
+    _RW = 0; 
+    _DB7 = 1; 
+    _DB6 = (Address & 0b1000000) >> 6; _DB5 = (Address & 0b0100000) >> 5; _DB4 = (Address & 0b0010000) >> 4; 
+    _DB3 = (Address & 0b0001000) >> 3; _DB2 = (Address & 0b0000100) >> 2; _DB1 = (Address & 0b0000010) >> 1; _DB0 = (Address & 0b0000001) >> 0;
+    clock_in();
+    }
+
+void LCD::Write_String(string Word){
+    int ASCII_Converted;
+    for (int i = 0; i < Word.length(); i++)
+    {
+        ASCII_Converted = Word.at(i);
+        _RS = 1; _RW = 0; 
+        _DB7 = (ASCII_Converted & 0b10000000) >> 7; _DB6 = (ASCII_Converted & 0b01000000) >> 6; _DB5 = (ASCII_Converted & 0b00100000) >> 5; _DB4 = (ASCII_Converted & 0b00010000) >> 4;
+        _DB3 = (ASCII_Converted & 0b00001000) >> 3; _DB2 = (ASCII_Converted & 0b00000100) >> 2; _DB1 = (ASCII_Converted & 0b00000010) >> 1; _DB0 = (ASCII_Converted & 0b00000001) >> 0;
+        clock_in();
+    }      
+}
+ 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD.hpp	Wed Dec 27 18:26:50 2017 +0000
@@ -0,0 +1,42 @@
+#ifndef _LCD_HPP_ //Known as header guards
+#define _LCD_HPP_
+
+#include <string>
+ 
+class LCD //This creates a class called Led
+{
+    
+public: 
+ 
+    LCD(PinName E, PinName RS, PinName RW, PinName DB0, PinName DB1, PinName DB2, PinName DB3, PinName DB4, PinName DB5, PinName DB6, PinName DB7);
+    ~LCD();
+    void Binary_Convert(int Integer);
+    void clock_in();
+    void Function_Set();
+    void Display_Off();
+    void Display_Clear();
+    void Entry_Mode_Set();
+    void Display_On();
+    void DDRAM_Address(int Address);
+    void Write_String(string Word);
+    void Initialise();
+    
+private:    
+ 
+    DigitalOut _RW;
+    DigitalOut _RS;
+    DigitalOut _E;
+    
+    DigitalOut _DB0;
+    DigitalOut _DB1;
+    DigitalOut _DB2;
+    DigitalOut _DB3;
+    DigitalOut _DB4;
+    DigitalOut _DB5;
+    DigitalOut _DB6;
+    DigitalOut _DB7;
+    
+};
+ 
+ 
+#endif
\ No newline at end of file
--- a/main.cpp	Wed Dec 27 16:12:38 2017 +0000
+++ b/main.cpp	Wed Dec 27 18:26:50 2017 +0000
@@ -1,78 +1,23 @@
 #include "mbed.h"
 #include <string>
+#include "LCD.hpp"
 
 DigitalOut myled(LED1);
 
-DigitalOut RS(D9);
+/*DigitalOut RS(D9);
 DigitalOut RW(D4);
 DigitalOut E(D8);
-BusInOut DB(A0, A1, A2, A3, D7, D6, D3, D1);        //LSB First
+BusInOut   DB(A0, A1, A2, A3, D7, D6, D3, D1);        //LSB First*/
 
-void clock_in();
-void Function_Set();
-void Display_Off();
-void Display_Clear();
-void Entry_Mode_Set();
-void Display_On();
-void DDRAM_Address(int Address);
-void Write_Data(string Letter);
-void Write_String(string Word);
-void Initialise();
+LCD lcd(D8,D9,D4,A0,A1,A2,A3,D7,D6,D3,D1); 
 
 int main() {
     
-    DB.output();
-    Initialise();
+    lcd.Initialise();
     
-    DDRAM_Address(0x40);
-    Write_String("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
+    lcd.DDRAM_Address(0x00);
+    lcd.Write_String("2017_12_27 18:22");
     
 }
 
-void clock_in(){E = 1; wait(0.001); E = 0; wait(0.001); E = 1;}
 
-void Function_Set(){RS = 0; RW = 0; DB = 0x3C; clock_in();}
-
-void Display_Off(){RS = 0; RW = 0; DB = 0x08; clock_in();}
-
-void Display_Clear(){RS = 0; RW = 0; DB = 0x01; clock_in();}
-
-void Entry_Mode_Set(){RS = 0; RW = 0; DB = 0x06; clock_in();}
-
-void Display_On(){RS = 0; RW = 0; DB = 0x0F; clock_in();}
-
-void Initialise(){
-    Function_Set();
-    wait(0.020);
-    Display_Off();
-    wait(0.020);
-    Display_Clear();
-    wait(0.020);
-    Entry_Mode_Set();
-    wait(0.020);
-    Display_On();
-    wait(0.020);
-    DDRAM_Address(0);
-    wait(0.020);
-}
-
-void DDRAM_Address(int Address){RS = 0; RW = 0; DB = 0x80 + Address; clock_in();}
-
-void Write_Data(string Letter){
-    int ASCII_Converted[32];
-    for (int i = 0; i < Letter.length(); i++)
-    {
-        ASCII_Converted[i] = Letter.at(i);   
-    }    
-     RS = 1; RW = 0; DB = ASCII_Converted[0]; clock_in();
-}
-
-void Write_String(string Word){
-    
-    int ASCII_Converted;
-    for (int i = 0; i < Word.length(); i++)
-    {
-        ASCII_Converted = Word.at(i);
-        RS = 1; RW = 0; DB = ASCII_Converted; clock_in();
-    }      
-}