Time: 17:33 Date: 10/12/2017 Description: Task 1,7,8 Currently Functioning
Dependencies: BME280 BMP280 TextLCD
Working Repository
LCD.cpp@47:6d128e500875, 2018-01-08 (annotated)
- Committer:
- thomasmorris
- Date:
- Mon Jan 08 21:53:40 2018 +0000
- Revision:
- 47:6d128e500875
- Parent:
- 20:cbb71f84cff9
- Child:
- 48:244d6d81bb52
FINAL working copy
Who changed what in which revision?
User | Revision | Line number | New 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 | } |
thomasmorris | 47:6d128e500875 | 47 | |
thomasmorris | 47:6d128e500875 | 48 | |
thomasmorris | 47:6d128e500875 | 49 | |
thomasmorris | 47:6d128e500875 | 50 | |
thomasmorris | 47:6d128e500875 | 51 | void LCD_Write_Year() |
thomasmorris | 47:6d128e500875 | 52 | { |
thomasmorris | 47:6d128e500875 | 53 | Time_Lock_Main.lock();//Appling lock for critial section |
thomasmorris | 47:6d128e500875 | 54 | if(Log_Value == 1){pc.printf("In LCD_Write_Year Time lock taken\n");} |
thomasmorris | 47:6d128e500875 | 55 | time_t Time = time(NULL); |
thomasmorris | 47:6d128e500875 | 56 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 47:6d128e500875 | 57 | int Years = 1900 + Time_Pointer->tm_year; |
thomasmorris | 47:6d128e500875 | 58 | Time_Lock_Main.unlock();//Releasing lock for critial section |
thomasmorris | 47:6d128e500875 | 59 | if(Log_Value == 1){pc.printf("In LCD_Write_Year Time lock released\n");} |
thomasmorris | 47:6d128e500875 | 60 | stringstream ss; |
thomasmorris | 47:6d128e500875 | 61 | ss << Years; |
thomasmorris | 47:6d128e500875 | 62 | string Year_String = ss.str(); |
thomasmorris | 47:6d128e500875 | 63 | LCD.DDRAM_Address(0x00); |
thomasmorris | 47:6d128e500875 | 64 | LCD.Write_String("Set Year"); |
thomasmorris | 47:6d128e500875 | 65 | LCD.DDRAM_Address(0x40); |
thomasmorris | 47:6d128e500875 | 66 | LCD.Write_String(Year_String); |
thomasmorris | 47:6d128e500875 | 67 | } |
thomasmorris | 47:6d128e500875 | 68 | void LCD_Write_Month() |
thomasmorris | 47:6d128e500875 | 69 | { |
thomasmorris | 47:6d128e500875 | 70 | Time_Lock_Main.lock();//Appling lock for critial section |
thomasmorris | 47:6d128e500875 | 71 | if(Log_Value == 1){pc.printf("In LCD_Write_Month Time lock taken\n");} |
thomasmorris | 47:6d128e500875 | 72 | time_t Time = time(NULL); |
thomasmorris | 47:6d128e500875 | 73 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 47:6d128e500875 | 74 | int Months = 1 + Time_Pointer->tm_mon; |
thomasmorris | 47:6d128e500875 | 75 | Time_Lock_Main.unlock();//Releasing lock for critial section |
thomasmorris | 47:6d128e500875 | 76 | if(Log_Value == 1){pc.printf("In LCD_Write_Month Time lock released\n");} |
thomasmorris | 47:6d128e500875 | 77 | stringstream ss; |
thomasmorris | 47:6d128e500875 | 78 | ss << Months; |
thomasmorris | 47:6d128e500875 | 79 | string Month_String = ss.str(); |
thomasmorris | 47:6d128e500875 | 80 | LCD.DDRAM_Address(0x00); |
thomasmorris | 47:6d128e500875 | 81 | LCD.Write_String("Set Month"); |
thomasmorris | 47:6d128e500875 | 82 | LCD.DDRAM_Address(0x40); |
thomasmorris | 47:6d128e500875 | 83 | LCD.Write_String(Month_String); |
thomasmorris | 47:6d128e500875 | 84 | } |
thomasmorris | 47:6d128e500875 | 85 | void LCD_Write_Day() |
thomasmorris | 47:6d128e500875 | 86 | { |
thomasmorris | 47:6d128e500875 | 87 | Time_Lock_Main.lock();//Appling lock for critial section |
thomasmorris | 47:6d128e500875 | 88 | if(Log_Value == 1){pc.printf("In LCD_Write_Day Time lock taken\n");} |
thomasmorris | 47:6d128e500875 | 89 | time_t Time = time(NULL); |
thomasmorris | 47:6d128e500875 | 90 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 47:6d128e500875 | 91 | int Days = Time_Pointer->tm_mday; |
thomasmorris | 47:6d128e500875 | 92 | Time_Lock_Main.unlock();//Releasing lock for critial section |
thomasmorris | 47:6d128e500875 | 93 | if(Log_Value == 1){pc.printf("In LCD_Write_Day Time lock released\n");} |
thomasmorris | 47:6d128e500875 | 94 | stringstream ss; |
thomasmorris | 47:6d128e500875 | 95 | ss << Days; |
thomasmorris | 47:6d128e500875 | 96 | string Day_String = ss.str(); |
thomasmorris | 47:6d128e500875 | 97 | LCD.DDRAM_Address(0x00); |
thomasmorris | 47:6d128e500875 | 98 | LCD.Write_String("Set Day"); |
thomasmorris | 47:6d128e500875 | 99 | LCD.DDRAM_Address(0x40); |
thomasmorris | 47:6d128e500875 | 100 | LCD.Write_String(Day_String); |
thomasmorris | 47:6d128e500875 | 101 | } |
thomasmorris | 47:6d128e500875 | 102 | void LCD_Write_Hour() |
thomasmorris | 47:6d128e500875 | 103 | { |
thomasmorris | 47:6d128e500875 | 104 | Time_Lock_Main.lock();//Appling lock for critial section |
thomasmorris | 47:6d128e500875 | 105 | if(Log_Value == 1){pc.printf("In LCD_Write_Hour Time lock taken\n");} |
thomasmorris | 47:6d128e500875 | 106 | time_t Time = time(NULL); |
thomasmorris | 47:6d128e500875 | 107 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 47:6d128e500875 | 108 | int Hours = Time_Pointer->tm_hour; |
thomasmorris | 47:6d128e500875 | 109 | Time_Lock_Main.unlock();//Releasing lock for critial section |
thomasmorris | 47:6d128e500875 | 110 | if(Log_Value == 1){pc.printf("In LCD_Write_Hour Time lock released\n");} |
thomasmorris | 47:6d128e500875 | 111 | stringstream ss; |
thomasmorris | 47:6d128e500875 | 112 | ss << Hours; |
thomasmorris | 47:6d128e500875 | 113 | string Hour_String = ss.str(); |
thomasmorris | 47:6d128e500875 | 114 | LCD.DDRAM_Address(0x00); |
thomasmorris | 47:6d128e500875 | 115 | LCD.Write_String("Set Hour"); |
thomasmorris | 47:6d128e500875 | 116 | LCD.DDRAM_Address(0x40); |
thomasmorris | 47:6d128e500875 | 117 | LCD.Write_String(Hour_String); |
thomasmorris | 47:6d128e500875 | 118 | } |
thomasmorris | 47:6d128e500875 | 119 | void LCD_Write_Minute() |
thomasmorris | 47:6d128e500875 | 120 | { |
thomasmorris | 47:6d128e500875 | 121 | Time_Lock_Main.lock();//Appling lock for critial section |
thomasmorris | 47:6d128e500875 | 122 | if(Log_Value == 1){pc.printf("In LCD_Write_Minute Time lock taken\n");} |
thomasmorris | 47:6d128e500875 | 123 | time_t Time = time(NULL); |
thomasmorris | 47:6d128e500875 | 124 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 47:6d128e500875 | 125 | int Minutes = Time_Pointer->tm_min; |
thomasmorris | 47:6d128e500875 | 126 | Time_Lock_Main.unlock();//Releasing lock for critial section |
thomasmorris | 47:6d128e500875 | 127 | if(Log_Value == 1){pc.printf("In LCD_Write_Minute Time lock released\n");} |
thomasmorris | 47:6d128e500875 | 128 | stringstream ss; |
thomasmorris | 47:6d128e500875 | 129 | ss << Minutes; |
thomasmorris | 47:6d128e500875 | 130 | string Minute_String = ss.str(); |
thomasmorris | 47:6d128e500875 | 131 | LCD.DDRAM_Address(0x00); |
thomasmorris | 47:6d128e500875 | 132 | LCD.Write_String("Set Minute"); |
thomasmorris | 47:6d128e500875 | 133 | LCD.DDRAM_Address(0x40); |
thomasmorris | 47:6d128e500875 | 134 | LCD.Write_String(Minute_String); |
thomasmorris | 47:6d128e500875 | 135 | } |
thomasmorris | 47:6d128e500875 | 136 | void LCD_Write_Seconds() |
thomasmorris | 47:6d128e500875 | 137 | { |
thomasmorris | 47:6d128e500875 | 138 | Time_Lock_Main.lock();//Appling lock for critial section |
thomasmorris | 47:6d128e500875 | 139 | if(Log_Value == 1){pc.printf("In LCD_Write_Seconds Time lock taken\n");} |
thomasmorris | 47:6d128e500875 | 140 | time_t Time = time(NULL); |
thomasmorris | 47:6d128e500875 | 141 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 47:6d128e500875 | 142 | int Seconds = Time_Pointer->tm_sec; |
thomasmorris | 47:6d128e500875 | 143 | Time_Lock_Main.unlock();//Releasing lock for critial section |
thomasmorris | 47:6d128e500875 | 144 | if(Log_Value == 1){pc.printf("In LCD_Write_Seconds Time lock released\n");} |
thomasmorris | 47:6d128e500875 | 145 | stringstream ss; |
thomasmorris | 47:6d128e500875 | 146 | ss << Seconds; |
thomasmorris | 47:6d128e500875 | 147 | string Second_String = ss.str(); |
thomasmorris | 47:6d128e500875 | 148 | LCD.DDRAM_Address(0x00); |
thomasmorris | 47:6d128e500875 | 149 | LCD.Write_String("Set Second"); |
thomasmorris | 47:6d128e500875 | 150 | LCD.DDRAM_Address(0x40); |
thomasmorris | 47:6d128e500875 | 151 | LCD.Write_String(Second_String); |
thomasmorris | 47:6d128e500875 | 152 | } |
thomasmorris | 47:6d128e500875 | 153 | |
thomasmorris | 47:6d128e500875 | 154 | |
thomasmorris | 47:6d128e500875 | 155 | void LCD_Print_Output() |
thomasmorris | 47:6d128e500875 | 156 | { |
thomasmorris | 47:6d128e500875 | 157 | |
thomasmorris | 47:6d128e500875 | 158 | if(mode == 0)//Default mode |
thomasmorris | 47:6d128e500875 | 159 | { |
thomasmorris | 47:6d128e500875 | 160 | if(Log_Value == 1){pc.printf("In mode 0 \n");} |
thomasmorris | 47:6d128e500875 | 161 | |
thomasmorris | 47:6d128e500875 | 162 | Thread::wait(Default_Mode_Toggle_Time);//Wait for this amount of time |
thomasmorris | 47:6d128e500875 | 163 | if(Log_Value == 1){pc.printf("Writing Data to LCD\n");} |
thomasmorris | 47:6d128e500875 | 164 | sprintf (LCD_buffer, "%1.1f %1.0f %1.2f",Data_Active.get_temperature(),Data_Active.get_pressure(),Data_Active.get_light());//Used for converting to a sting |
thomasmorris | 47:6d128e500875 | 165 | |
thomasmorris | 47:6d128e500875 | 166 | LCD.DDRAM_Address(0x00); |
thomasmorris | 47:6d128e500875 | 167 | LCD.Write_String("Temp Pres Lite"); |
thomasmorris | 47:6d128e500875 | 168 | LCD.DDRAM_Address(0x40); |
thomasmorris | 47:6d128e500875 | 169 | LCD.Write_String(LCD_buffer);//Print out current data values to the LCD |
thomasmorris | 47:6d128e500875 | 170 | |
thomasmorris | 47:6d128e500875 | 171 | Thread::wait(Default_Mode_Toggle_Time); //Wait for this amount of time |
thomasmorris | 47:6d128e500875 | 172 | if(Log_Value == 1){pc.printf("Writing Time and Date to LCD\n");} |
thomasmorris | 47:6d128e500875 | 173 | Time_Lock_Main.lock();//lock Time_lock for critial section |
thomasmorris | 47:6d128e500875 | 174 | time_t Time = Data_Active.get_time(); |
thomasmorris | 47:6d128e500875 | 175 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 47:6d128e500875 | 176 | LCD.Display_Clear(); |
thomasmorris | 47:6d128e500875 | 177 | sprintf (LCD_buffer, "%02d:%02d %02d,%d",Time_Pointer->tm_hour,Time_Pointer->tm_min,(Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900));//Used for converting to a sting |
thomasmorris | 47:6d128e500875 | 178 | Time_Lock_Main.unlock();//unlock Time_lock for critial section |
thomasmorris | 47:6d128e500875 | 179 | |
thomasmorris | 47:6d128e500875 | 180 | LCD.DDRAM_Address(0x00); |
thomasmorris | 47:6d128e500875 | 181 | LCD.Write_String("Current Time:"); |
thomasmorris | 47:6d128e500875 | 182 | LCD.DDRAM_Address(0x40); |
thomasmorris | 47:6d128e500875 | 183 | LCD.Write_String(LCD_buffer);//Print the current time to the LCD |
thomasmorris | 47:6d128e500875 | 184 | |
thomasmorris | 47:6d128e500875 | 185 | if(Log_Value == 1){pc.printf("Checking Switches for next mode\n");} |
thomasmorris | 47:6d128e500875 | 186 | if(SW1.read() & SW2.read() == 1) |
thomasmorris | 47:6d128e500875 | 187 | { |
thomasmorris | 47:6d128e500875 | 188 | mode = 1; |
thomasmorris | 47:6d128e500875 | 189 | } |
thomasmorris | 47:6d128e500875 | 190 | } |
thomasmorris | 47:6d128e500875 | 191 | else if(mode == 1)//Choose either date setting or time setting |
thomasmorris | 47:6d128e500875 | 192 | { |
thomasmorris | 47:6d128e500875 | 193 | if(Log_Value == 1){pc.printf("In Mode 1\n");} |
thomasmorris | 47:6d128e500875 | 194 | LCD.Display_Clear(); |
thomasmorris | 47:6d128e500875 | 195 | while(1) |
thomasmorris | 47:6d128e500875 | 196 | { |
thomasmorris | 47:6d128e500875 | 197 | LCD.DDRAM_Address(0x00); |
thomasmorris | 47:6d128e500875 | 198 | LCD.Write_String("Date Time"); |
thomasmorris | 47:6d128e500875 | 199 | LCD.DDRAM_Address(0x40); |
thomasmorris | 47:6d128e500875 | 200 | LCD.Write_String("< >"); |
thomasmorris | 47:6d128e500875 | 201 | Thread::wait(1000); |
thomasmorris | 47:6d128e500875 | 202 | if(Log_Value == 1){pc.printf("Checking SW1 to go to Date setting\n");} |
thomasmorris | 47:6d128e500875 | 203 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 47:6d128e500875 | 204 | { |
thomasmorris | 47:6d128e500875 | 205 | mode = 2;//Date Setting |
thomasmorris | 47:6d128e500875 | 206 | break; |
thomasmorris | 47:6d128e500875 | 207 | } |
thomasmorris | 47:6d128e500875 | 208 | if(Log_Value == 1){pc.printf("Checking SW2 to go to Time setting\n");} |
thomasmorris | 47:6d128e500875 | 209 | if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 47:6d128e500875 | 210 | { |
thomasmorris | 47:6d128e500875 | 211 | mode = 5;//Time Setting |
thomasmorris | 47:6d128e500875 | 212 | break; |
thomasmorris | 47:6d128e500875 | 213 | } |
thomasmorris | 47:6d128e500875 | 214 | } |
thomasmorris | 47:6d128e500875 | 215 | } |
thomasmorris | 47:6d128e500875 | 216 | else if(mode == 2)//Set the Year |
thomasmorris | 47:6d128e500875 | 217 | { |
thomasmorris | 47:6d128e500875 | 218 | if(Log_Value == 1){pc.printf("In Mode 2\n");} |
thomasmorris | 47:6d128e500875 | 219 | LCD.Display_Clear(); |
thomasmorris | 47:6d128e500875 | 220 | while(1) |
thomasmorris | 47:6d128e500875 | 221 | { |
thomasmorris | 47:6d128e500875 | 222 | LCD_Write_Year(); |
thomasmorris | 47:6d128e500875 | 223 | Thread::wait(1000); |
thomasmorris | 47:6d128e500875 | 224 | if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go to Month setting\n");} |
thomasmorris | 47:6d128e500875 | 225 | if(SW1.read() & SW2.read() == 1) |
thomasmorris | 47:6d128e500875 | 226 | { |
thomasmorris | 47:6d128e500875 | 227 | mode = 3; |
thomasmorris | 47:6d128e500875 | 228 | break; |
thomasmorris | 47:6d128e500875 | 229 | } |
thomasmorris | 47:6d128e500875 | 230 | if(Log_Value == 1){pc.printf("Checking SW1 to add Year\n");} |
thomasmorris | 47:6d128e500875 | 231 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 47:6d128e500875 | 232 | { |
thomasmorris | 47:6d128e500875 | 233 | Add_Year(); |
thomasmorris | 47:6d128e500875 | 234 | } |
thomasmorris | 47:6d128e500875 | 235 | if(Log_Value == 1){pc.printf("Checking SW2 to subtract Year\n");} |
thomasmorris | 47:6d128e500875 | 236 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 47:6d128e500875 | 237 | { |
thomasmorris | 47:6d128e500875 | 238 | Subtract_Year(); |
thomasmorris | 47:6d128e500875 | 239 | } |
thomasmorris | 47:6d128e500875 | 240 | LCD_Write_Year(); |
thomasmorris | 47:6d128e500875 | 241 | } |
thomasmorris | 47:6d128e500875 | 242 | } |
thomasmorris | 47:6d128e500875 | 243 | else if(mode == 3)//Set the Month |
thomasmorris | 47:6d128e500875 | 244 | { |
thomasmorris | 47:6d128e500875 | 245 | if(Log_Value == 1){pc.printf("In Mode 3\n");} |
thomasmorris | 47:6d128e500875 | 246 | LCD.Display_Clear(); |
thomasmorris | 47:6d128e500875 | 247 | while(1) |
thomasmorris | 47:6d128e500875 | 248 | { |
thomasmorris | 47:6d128e500875 | 249 | LCD_Write_Month(); |
thomasmorris | 47:6d128e500875 | 250 | Thread::wait(1000); |
thomasmorris | 47:6d128e500875 | 251 | if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go to Day setting\n");} |
thomasmorris | 47:6d128e500875 | 252 | if(SW1.read() & SW2.read() == 1) |
thomasmorris | 47:6d128e500875 | 253 | { |
thomasmorris | 47:6d128e500875 | 254 | mode = 4; |
thomasmorris | 47:6d128e500875 | 255 | break; |
thomasmorris | 47:6d128e500875 | 256 | } |
thomasmorris | 47:6d128e500875 | 257 | if(Log_Value == 1){pc.printf("Checking SW1 to add Month\n");} |
thomasmorris | 47:6d128e500875 | 258 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 47:6d128e500875 | 259 | { |
thomasmorris | 47:6d128e500875 | 260 | Add_Month(); |
thomasmorris | 47:6d128e500875 | 261 | } |
thomasmorris | 47:6d128e500875 | 262 | if(Log_Value == 1){pc.printf("Checking SW2 to subtract Month\n");} |
thomasmorris | 47:6d128e500875 | 263 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 47:6d128e500875 | 264 | { |
thomasmorris | 47:6d128e500875 | 265 | Subtract_Month(); |
thomasmorris | 47:6d128e500875 | 266 | } |
thomasmorris | 47:6d128e500875 | 267 | |
thomasmorris | 47:6d128e500875 | 268 | } |
thomasmorris | 47:6d128e500875 | 269 | } |
thomasmorris | 47:6d128e500875 | 270 | else if(mode == 4)//Set the Day |
thomasmorris | 47:6d128e500875 | 271 | { |
thomasmorris | 47:6d128e500875 | 272 | if(Log_Value == 1){pc.printf("In Mode 4\n");} |
thomasmorris | 47:6d128e500875 | 273 | LCD.Display_Clear(); |
thomasmorris | 47:6d128e500875 | 274 | while(1) |
thomasmorris | 47:6d128e500875 | 275 | { |
thomasmorris | 47:6d128e500875 | 276 | LCD_Write_Day(); |
thomasmorris | 47:6d128e500875 | 277 | Thread::wait(1000); |
thomasmorris | 47:6d128e500875 | 278 | if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Default setting\n");} |
thomasmorris | 47:6d128e500875 | 279 | if(SW1.read() & SW2.read() == 1) |
thomasmorris | 47:6d128e500875 | 280 | { |
thomasmorris | 47:6d128e500875 | 281 | mode = 0; |
thomasmorris | 47:6d128e500875 | 282 | break; |
thomasmorris | 47:6d128e500875 | 283 | } |
thomasmorris | 47:6d128e500875 | 284 | if(Log_Value == 1){pc.printf("Checking SW1 to add Day\n");} |
thomasmorris | 47:6d128e500875 | 285 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 47:6d128e500875 | 286 | { |
thomasmorris | 47:6d128e500875 | 287 | Add_Day(); |
thomasmorris | 47:6d128e500875 | 288 | } |
thomasmorris | 47:6d128e500875 | 289 | if(Log_Value == 1){pc.printf("Checking SW2 to subtract Day\n");} |
thomasmorris | 47:6d128e500875 | 290 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 47:6d128e500875 | 291 | { |
thomasmorris | 47:6d128e500875 | 292 | Subtract_Day(); |
thomasmorris | 47:6d128e500875 | 293 | } |
thomasmorris | 47:6d128e500875 | 294 | } |
thomasmorris | 47:6d128e500875 | 295 | } |
thomasmorris | 47:6d128e500875 | 296 | else if(mode == 5)//Set the Hour |
thomasmorris | 47:6d128e500875 | 297 | { |
thomasmorris | 47:6d128e500875 | 298 | if(Log_Value == 1){pc.printf("In Mode 5\n");} |
thomasmorris | 47:6d128e500875 | 299 | LCD.Display_Clear(); |
thomasmorris | 47:6d128e500875 | 300 | while(1) |
thomasmorris | 47:6d128e500875 | 301 | { |
thomasmorris | 47:6d128e500875 | 302 | LCD_Write_Hour(); |
thomasmorris | 47:6d128e500875 | 303 | Thread::wait(1000); |
thomasmorris | 47:6d128e500875 | 304 | if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Minute setting\n");} |
thomasmorris | 47:6d128e500875 | 305 | if(SW1.read() & SW2.read() == 1) |
thomasmorris | 47:6d128e500875 | 306 | { |
thomasmorris | 47:6d128e500875 | 307 | mode = 6; |
thomasmorris | 47:6d128e500875 | 308 | break; |
thomasmorris | 47:6d128e500875 | 309 | } |
thomasmorris | 47:6d128e500875 | 310 | if(Log_Value == 1){pc.printf("Checking SW1 to add Hour\n");} |
thomasmorris | 47:6d128e500875 | 311 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 47:6d128e500875 | 312 | { |
thomasmorris | 47:6d128e500875 | 313 | Add_Hour(); |
thomasmorris | 47:6d128e500875 | 314 | } |
thomasmorris | 47:6d128e500875 | 315 | if(Log_Value == 1){pc.printf("Checking SW2 to subtract Hour\n");} |
thomasmorris | 47:6d128e500875 | 316 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 47:6d128e500875 | 317 | { |
thomasmorris | 47:6d128e500875 | 318 | Subtract_Hour(); |
thomasmorris | 47:6d128e500875 | 319 | } |
thomasmorris | 47:6d128e500875 | 320 | } |
thomasmorris | 47:6d128e500875 | 321 | } |
thomasmorris | 47:6d128e500875 | 322 | else if(mode == 6)//Set the Minute |
thomasmorris | 47:6d128e500875 | 323 | { |
thomasmorris | 47:6d128e500875 | 324 | if(Log_Value == 1){pc.printf("In Mode 6\n");} |
thomasmorris | 47:6d128e500875 | 325 | LCD.Display_Clear(); |
thomasmorris | 47:6d128e500875 | 326 | while(1) |
thomasmorris | 47:6d128e500875 | 327 | { |
thomasmorris | 47:6d128e500875 | 328 | LCD_Write_Minute(); |
thomasmorris | 47:6d128e500875 | 329 | Thread::wait(1000); |
thomasmorris | 47:6d128e500875 | 330 | if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Seconds setting\n");} |
thomasmorris | 47:6d128e500875 | 331 | if(SW1.read() & SW2.read() == 1) |
thomasmorris | 47:6d128e500875 | 332 | { |
thomasmorris | 47:6d128e500875 | 333 | mode = 7; |
thomasmorris | 47:6d128e500875 | 334 | break; |
thomasmorris | 47:6d128e500875 | 335 | } |
thomasmorris | 47:6d128e500875 | 336 | if(Log_Value == 1){pc.printf("Checking SW1 to add Minute\n");} |
thomasmorris | 47:6d128e500875 | 337 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 47:6d128e500875 | 338 | { |
thomasmorris | 47:6d128e500875 | 339 | Add_Minute(); |
thomasmorris | 47:6d128e500875 | 340 | } |
thomasmorris | 47:6d128e500875 | 341 | if(Log_Value == 1){pc.printf("Checking SW2 to subtract Minute\n");} |
thomasmorris | 47:6d128e500875 | 342 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 47:6d128e500875 | 343 | { |
thomasmorris | 47:6d128e500875 | 344 | Subtract_Minute(); |
thomasmorris | 47:6d128e500875 | 345 | } |
thomasmorris | 47:6d128e500875 | 346 | } |
thomasmorris | 47:6d128e500875 | 347 | } |
thomasmorris | 47:6d128e500875 | 348 | else if(mode == 7)//Set the Seconds |
thomasmorris | 47:6d128e500875 | 349 | { |
thomasmorris | 47:6d128e500875 | 350 | if(Log_Value == 1){pc.printf("In Mode 7\n");} |
thomasmorris | 47:6d128e500875 | 351 | LCD.Display_Clear(); |
thomasmorris | 47:6d128e500875 | 352 | while(1) |
thomasmorris | 47:6d128e500875 | 353 | { |
thomasmorris | 47:6d128e500875 | 354 | LCD_Write_Seconds(); |
thomasmorris | 47:6d128e500875 | 355 | Thread::wait(1000); |
thomasmorris | 47:6d128e500875 | 356 | if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Default setting\n");} |
thomasmorris | 47:6d128e500875 | 357 | if(SW1.read() & SW2.read() == 1) |
thomasmorris | 47:6d128e500875 | 358 | { |
thomasmorris | 47:6d128e500875 | 359 | mode = 0; |
thomasmorris | 47:6d128e500875 | 360 | break; |
thomasmorris | 47:6d128e500875 | 361 | } |
thomasmorris | 47:6d128e500875 | 362 | if(Log_Value == 1){pc.printf("Checking SW1 to add Second\n");} |
thomasmorris | 47:6d128e500875 | 363 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 47:6d128e500875 | 364 | { |
thomasmorris | 47:6d128e500875 | 365 | Add_Second(); |
thomasmorris | 47:6d128e500875 | 366 | } |
thomasmorris | 47:6d128e500875 | 367 | if(Log_Value == 1){pc.printf("Checking SW1 to subtract Second\n");} |
thomasmorris | 47:6d128e500875 | 368 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 47:6d128e500875 | 369 | { |
thomasmorris | 47:6d128e500875 | 370 | Subtract_Second(); |
thomasmorris | 47:6d128e500875 | 371 | } |
thomasmorris | 47:6d128e500875 | 372 | } |
thomasmorris | 47:6d128e500875 | 373 | } |
thomasmorris | 47:6d128e500875 | 374 | else |
thomasmorris | 47:6d128e500875 | 375 | { |
thomasmorris | 47:6d128e500875 | 376 | if(Log_Value == 1){pc.printf("Mode Error occured mode now set to 0\n");} |
thomasmorris | 47:6d128e500875 | 377 | mode = 0; |
thomasmorris | 47:6d128e500875 | 378 | } |
thomasmorris | 47:6d128e500875 | 379 | } |