Plymouth ELEC351 Group T / Mbed 2 deprecated 2017_12_271329_LCDTrial

Dependencies:   mbed

Committer:
chills
Date:
Wed Dec 27 16:03:31 2017 +0000
Revision:
2:ed06e716cca2
Parent:
1:23bf1845cc2f
Child:
3:6ee7c8ce0b7a
2017_12_27 16:00; Initialise is within it's own function.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chills 0:87888ca85258 1 #include "mbed.h"
chills 1:23bf1845cc2f 2 #include <string>
chills 0:87888ca85258 3
chills 0:87888ca85258 4 DigitalOut myled(LED1);
chills 0:87888ca85258 5
chills 0:87888ca85258 6 DigitalOut RS(D9);
chills 0:87888ca85258 7 DigitalOut RW(D4);
chills 0:87888ca85258 8 DigitalOut E(D8);
chills 0:87888ca85258 9 BusInOut DB(A0, A1, A2, A3, D7, D6, D3, D1); //LSB First
chills 0:87888ca85258 10
chills 0:87888ca85258 11 void clock_in();
chills 0:87888ca85258 12 void Function_Set();
chills 0:87888ca85258 13 void Display_Off();
chills 0:87888ca85258 14 void Display_Clear();
chills 0:87888ca85258 15 void Entry_Mode_Set();
chills 0:87888ca85258 16 void Display_On();
chills 0:87888ca85258 17 void DDRAM_Address(int Address);
chills 1:23bf1845cc2f 18 void Write_Data(string Letter);
chills 1:23bf1845cc2f 19 void Write_String(string Word);
chills 2:ed06e716cca2 20 void Initialise();
chills 0:87888ca85258 21
chills 0:87888ca85258 22 int main() {
chills 0:87888ca85258 23
chills 0:87888ca85258 24 DB.output();
chills 2:ed06e716cca2 25 Initialise();
chills 2:ed06e716cca2 26
chills 2:ed06e716cca2 27 Write_String("Hello");
chills 0:87888ca85258 28
chills 0:87888ca85258 29 }
chills 0:87888ca85258 30
chills 0:87888ca85258 31 void clock_in(){
chills 2:ed06e716cca2 32 E = 1; wait(0.001); E = 0; wait(0.001); E = 1;
chills 0:87888ca85258 33 }
chills 0:87888ca85258 34
chills 0:87888ca85258 35 void Function_Set(){
chills 0:87888ca85258 36 RS = 0; RW = 0; DB = 0x3C; clock_in();
chills 0:87888ca85258 37 }
chills 0:87888ca85258 38
chills 0:87888ca85258 39 void Display_Off(){
chills 0:87888ca85258 40 RS = 0; RW = 0; DB = 0x08; clock_in();
chills 0:87888ca85258 41 }
chills 0:87888ca85258 42
chills 0:87888ca85258 43 void Display_Clear(){
chills 0:87888ca85258 44 RS = 0; RW = 0; DB = 0x01; clock_in();
chills 0:87888ca85258 45 }
chills 0:87888ca85258 46
chills 0:87888ca85258 47 void Entry_Mode_Set(){
chills 0:87888ca85258 48 RS = 0; RW = 0; DB = 0x06; clock_in();
chills 0:87888ca85258 49 }
chills 0:87888ca85258 50
chills 0:87888ca85258 51 void Display_On(){
chills 2:ed06e716cca2 52 RS = 0; RW = 0; DB = 0x0F; clock_in();
chills 2:ed06e716cca2 53 }
chills 2:ed06e716cca2 54
chills 2:ed06e716cca2 55 void Initialise(){
chills 2:ed06e716cca2 56 Function_Set();
chills 2:ed06e716cca2 57 wait(0.020);
chills 2:ed06e716cca2 58 Display_Off();
chills 2:ed06e716cca2 59 wait(0.020);
chills 2:ed06e716cca2 60 Display_Clear();
chills 2:ed06e716cca2 61 wait(0.020);
chills 2:ed06e716cca2 62 Entry_Mode_Set();
chills 2:ed06e716cca2 63 wait(0.020);
chills 2:ed06e716cca2 64 Display_On();
chills 2:ed06e716cca2 65 wait(0.020);
chills 2:ed06e716cca2 66 DDRAM_Address(0);
chills 2:ed06e716cca2 67 wait(0.020);
chills 0:87888ca85258 68 }
chills 0:87888ca85258 69
chills 0:87888ca85258 70 void DDRAM_Address(int Address){
chills 0:87888ca85258 71 RS = 0; RW = 0; DB = 0x80 + Address; clock_in();
chills 0:87888ca85258 72 }
chills 0:87888ca85258 73
chills 1:23bf1845cc2f 74 void Write_Data(string Letter){
chills 1:23bf1845cc2f 75
chills 1:23bf1845cc2f 76 int ASCII_Converted[32];
chills 1:23bf1845cc2f 77
chills 1:23bf1845cc2f 78 for (int i = 0; i < Letter.length(); i++)
chills 1:23bf1845cc2f 79 {
chills 1:23bf1845cc2f 80 ASCII_Converted[i] = Letter.at(i);
chills 1:23bf1845cc2f 81
chills 1:23bf1845cc2f 82 }
chills 1:23bf1845cc2f 83
chills 1:23bf1845cc2f 84 RS = 1; RW = 0; DB = ASCII_Converted[0]; clock_in();
chills 1:23bf1845cc2f 85
chills 0:87888ca85258 86 }
chills 1:23bf1845cc2f 87
chills 1:23bf1845cc2f 88 void Write_String(string Word){
chills 1:23bf1845cc2f 89
chills 1:23bf1845cc2f 90 int ASCII_Converted;
chills 1:23bf1845cc2f 91 for (int i = 0; i < Word.length(); i++)
chills 1:23bf1845cc2f 92 {
chills 1:23bf1845cc2f 93 ASCII_Converted = Word.at(i);
chills 1:23bf1845cc2f 94 RS = 1; RW = 0; DB = ASCII_Converted; clock_in();
chills 2:ed06e716cca2 95 }
chills 1:23bf1845cc2f 96 }