Display the date and time on text LCD using RTC DS1307.

Dependencies:   DS1307 TextLCD mbed

Committer:
ertech_pl
Date:
Fri Dec 26 11:22:36 2014 +0000
Revision:
1:1f723a262eeb
Parent:
0:bad75bd13618
compilation of txt lcd & RTC DS1307 demo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:bad75bd13618 1 #include "mbed.h"
ertech_pl 1:1f723a262eeb 2 #include "ds1307.h"
ertech_pl 1:1f723a262eeb 3 #include "TextLCD.h"
bcostm 0:bad75bd13618 4
ertech_pl 1:1f723a262eeb 5 TextLCD lcd(D8, D9, D4, D5, D6, D7); // rs, e, d4-d7
ertech_pl 1:1f723a262eeb 6 DS1307 my_tm(D14, D15); //sda, scl
ertech_pl 1:1f723a262eeb 7 DigitalOut myled(LED1); // blinking LED
ertech_pl 1:1f723a262eeb 8 InterruptIn mybutton(USER_BUTTON); // user button (blue)
bcostm 0:bad75bd13618 9
ertech_pl 1:1f723a262eeb 10 int year, month, day, hour, min, sec, dw; // dw - day of week
ertech_pl 1:1f723a262eeb 11 float delay=1.0; // delay time
ertech_pl 1:1f723a262eeb 12 float showtime=0.0;
bcostm 0:bad75bd13618 13
ertech_pl 1:1f723a262eeb 14 void lcdPrintDate(int row)
ertech_pl 1:1f723a262eeb 15 {
ertech_pl 1:1f723a262eeb 16 lcd.locate(0, row);
ertech_pl 1:1f723a262eeb 17 lcd.printf("Data :");
ertech_pl 1:1f723a262eeb 18 lcd.locate(6, row);
ertech_pl 1:1f723a262eeb 19 lcd.printf("%02d", day);
ertech_pl 1:1f723a262eeb 20 lcd.printf("-");
ertech_pl 1:1f723a262eeb 21 lcd.printf("%02d", month);
ertech_pl 1:1f723a262eeb 22 lcd.printf("-");
ertech_pl 1:1f723a262eeb 23 lcd.printf("%04d", 2000+year);
ertech_pl 1:1f723a262eeb 24 }
bcostm 0:bad75bd13618 25
ertech_pl 1:1f723a262eeb 26 void lcdPrintTime(int row)
ertech_pl 1:1f723a262eeb 27 {
ertech_pl 1:1f723a262eeb 28 lcd.locate(0, row);
ertech_pl 1:1f723a262eeb 29 lcd.printf("Czas :");
ertech_pl 1:1f723a262eeb 30 lcd.locate(6, row);
ertech_pl 1:1f723a262eeb 31 lcd.printf("%02d", hour);
ertech_pl 1:1f723a262eeb 32 lcd.printf(":");
ertech_pl 1:1f723a262eeb 33 lcd.printf("%02d", min);
ertech_pl 1:1f723a262eeb 34 lcd.printf(":");
ertech_pl 1:1f723a262eeb 35 lcd.printf("%02d", sec);
ertech_pl 1:1f723a262eeb 36 }
bcostm 0:bad75bd13618 37
ertech_pl 1:1f723a262eeb 38 void pressed()
ertech_pl 1:1f723a262eeb 39 {
ertech_pl 1:1f723a262eeb 40 if (delay == 1.0)
ertech_pl 1:1f723a262eeb 41 {
ertech_pl 1:1f723a262eeb 42 delay = 0.5; // 500 ms
ertech_pl 1:1f723a262eeb 43 }
ertech_pl 1:1f723a262eeb 44 else
ertech_pl 1:1f723a262eeb 45 {
ertech_pl 1:1f723a262eeb 46 delay = 1.0; // 1 sec
ertech_pl 1:1f723a262eeb 47 lcd.cls();
bcostm 0:bad75bd13618 48 }
bcostm 0:bad75bd13618 49 }
ertech_pl 1:1f723a262eeb 50
ertech_pl 1:1f723a262eeb 51
ertech_pl 1:1f723a262eeb 52
ertech_pl 1:1f723a262eeb 53 int main()
ertech_pl 1:1f723a262eeb 54 {
ertech_pl 1:1f723a262eeb 55 lcd.cls();
ertech_pl 1:1f723a262eeb 56 my_tm.twentyfour_hour();
ertech_pl 1:1f723a262eeb 57 mybutton.fall(&pressed);
ertech_pl 1:1f723a262eeb 58 while (1)
ertech_pl 1:1f723a262eeb 59 {
ertech_pl 1:1f723a262eeb 60 myled = !myled;
ertech_pl 1:1f723a262eeb 61 if (delay == 0.5)
ertech_pl 1:1f723a262eeb 62 {
ertech_pl 1:1f723a262eeb 63 my_tm.gettime(&sec, &min, &hour, &dw, &day, &month, &year);
ertech_pl 1:1f723a262eeb 64 lcdPrintDate(0);
ertech_pl 1:1f723a262eeb 65 lcdPrintTime(1);
ertech_pl 1:1f723a262eeb 66 showtime = showtime + delay;
ertech_pl 1:1f723a262eeb 67 if (showtime > 10) // after 10 s sleep
ertech_pl 1:1f723a262eeb 68 {
ertech_pl 1:1f723a262eeb 69 showtime = 0.0;
ertech_pl 1:1f723a262eeb 70 delay = 1.0;
ertech_pl 1:1f723a262eeb 71 lcd.cls();
ertech_pl 1:1f723a262eeb 72 }
ertech_pl 1:1f723a262eeb 73 }
ertech_pl 1:1f723a262eeb 74 wait(delay);
ertech_pl 1:1f723a262eeb 75 }
ertech_pl 1:1f723a262eeb 76
ertech_pl 1:1f723a262eeb 77 }