Test code for the LCD display, should output sample date and time.

Dependencies:   TextLCD mbed

Fork of TextLCD_HelloWorld2 by Wim Huiskamp

Committer:
JHutchinson
Date:
Thu May 25 10:04:11 2017 +0000
Revision:
9:2bc040a7e842
Parent:
8:5a3ea713ec88
Child:
10:72aef0816fc1
Full code for testing the LCD display.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JHutchinson 8:5a3ea713ec88 1
JHutchinson 8:5a3ea713ec88 2 #include "mbed.h"
JHutchinson 8:5a3ea713ec88 3 #include "TextLCD.h"
JHutchinson 8:5a3ea713ec88 4
JHutchinson 8:5a3ea713ec88 5 // Host PC Communication channels
JHutchinson 9:2bc040a7e842 6
JHutchinson 8:5a3ea713ec88 7 Serial pc(USBTX, USBRX); // tx, rx
JHutchinson 8:5a3ea713ec88 8
JHutchinson 9:2bc040a7e842 9 // LCD instantiation
JHutchinson 8:5a3ea713ec88 10
JHutchinson 9:2bc040a7e842 11 TextLCD lcd(PTC7, PTC0, PTC3, PTC4, PTC5, PTC6); // 4bit bus: rs, e, d4-d7
JHutchinson 9:2bc040a7e842 12
JHutchinson 9:2bc040a7e842 13 int main() {
JHutchinson 9:2bc040a7e842 14
JHutchinson 9:2bc040a7e842 15 // Initialise sample date and time
JHutchinson 8:5a3ea713ec88 16
JHutchinson 9:2bc040a7e842 17 int time = 1234;
JHutchinson 9:2bc040a7e842 18 int date = 220517;
JHutchinson 8:5a3ea713ec88 19
JHutchinson 8:5a3ea713ec88 20 // Adjust format of time to reflect hours and minutes
JHutchinson 9:2bc040a7e842 21
JHutchinson 9:2bc040a7e842 22 int hours = time/100;
JHutchinson 9:2bc040a7e842 23 int minutes = time - hours*100;
JHutchinson 8:5a3ea713ec88 24
JHutchinson 8:5a3ea713ec88 25 // Adjust format of date to reflect days and minutes
JHutchinson 9:2bc040a7e842 26
JHutchinson 9:2bc040a7e842 27 int day = date/10000;
JHutchinson 9:2bc040a7e842 28 int month = (date - day*10000)/100;
JHutchinson 9:2bc040a7e842 29 int year = date - month*100 - day*10000;
JHutchinson 8:5a3ea713ec88 30
JHutchinson 8:5a3ea713ec88 31 // Print correctly spaced values on the display
JHutchinson 8:5a3ea713ec88 32
JHutchinson 8:5a3ea713ec88 33 lcd.printf("Time %d:%d", hours, minutes);
JHutchinson 8:5a3ea713ec88 34
JHutchinson 9:2bc040a7e842 35 // Locate cursor to start of second line
JHutchinson 8:5a3ea713ec88 36
JHutchinson 8:5a3ea713ec88 37 lcd.setAddress(0, 1);
JHutchinson 8:5a3ea713ec88 38
JHutchinson 8:5a3ea713ec88 39 lcd.printf("Date %d/%d/%d", day, month, year);
JHutchinson 8:5a3ea713ec88 40
JHutchinson 9:2bc040a7e842 41 }
JHutchinson 8:5a3ea713ec88 42