rtc function

Dependencies:   Date RTC8563 mbed

Committer:
wolpra98
Date:
Thu Apr 30 10:49:32 2015 +0000
Revision:
1:b04939291414
Parent:
0:8a695c71f11b
rtc_func

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolpra98 0:8a695c71f11b 1 #include "mbed.h"
wolpra98 0:8a695c71f11b 2 #include "const.h"
wolpra98 0:8a695c71f11b 3 #include "RTC8563.h"
wolpra98 0:8a695c71f11b 4 #include "string"
wolpra98 1:b04939291414 5 #include "Date.h"
wolpra98 0:8a695c71f11b 6
wolpra98 0:8a695c71f11b 7 Serial pc(USBTX, USBRX);
wolpra98 0:8a695c71f11b 8 //I2C i2c(p28, p27);
wolpra98 0:8a695c71f11b 9
wolpra98 0:8a695c71f11b 10 uint8_t year, month, day, week;
wolpra98 0:8a695c71f11b 11 uint8_t hour, minute, sec;
wolpra98 0:8a695c71f11b 12 char week_chr[7][4] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
wolpra98 0:8a695c71f11b 13
wolpra98 0:8a695c71f11b 14 int main()
wolpra98 0:8a695c71f11b 15 {
wolpra98 1:b04939291414 16 Date rtc; // instanziieren des Objektes rtc
wolpra98 0:8a695c71f11b 17
wolpra98 0:8a695c71f11b 18 pc.printf("Setting up RTC\n");
wolpra98 0:8a695c71f11b 19 //rtc.rtc_init();
wolpra98 0:8a695c71f11b 20
wolpra98 0:8a695c71f11b 21 while(1) {
wolpra98 1:b04939291414 22
wolpra98 1:b04939291414 23 pc.printf("20%x/%x/%x Data %i",rtc.GetYear(),rtc.GetMonth(),rtc.GetDay());
wolpra98 0:8a695c71f11b 24 //printTime();
wolpra98 0:8a695c71f11b 25 year = rtc.rtc_read(YEARS); // Aufruf der Methode rtc_read der Instanz (Objekt) rtc
wolpra98 0:8a695c71f11b 26 month = rtc.rtc_read(MONTHS);
wolpra98 0:8a695c71f11b 27 day = rtc.rtc_read(DAYS);
wolpra98 0:8a695c71f11b 28 week = rtc.rtc_read(WEEKDAYS);
wolpra98 0:8a695c71f11b 29 hour = rtc.rtc_read(HOURS);
wolpra98 0:8a695c71f11b 30 minute = rtc.rtc_read(MINUTES);
wolpra98 0:8a695c71f11b 31 sec = rtc.rtc_read(SECONDS);
wolpra98 0:8a695c71f11b 32
wolpra98 0:8a695c71f11b 33 //Datum Ausgabe
wolpra98 0:8a695c71f11b 34 pc.printf("20%x%x/%x%x/%x%x %s\n",
wolpra98 0:8a695c71f11b 35 ((year >> 4) & 0x03) , (year & 0x0F) ,
wolpra98 0:8a695c71f11b 36 ((month >> 4) & 0x01), (month & 0x0F) ,
wolpra98 0:8a695c71f11b 37 ((day >> 4) & 0x03), (day & 0x0F) ,
wolpra98 0:8a695c71f11b 38 week_chr[week & 0x07]);
wolpra98 0:8a695c71f11b 39
wolpra98 0:8a695c71f11b 40 //Zeit Ausgabe
wolpra98 0:8a695c71f11b 41 pc.printf("%x%x:%x%x:%x%x\n",
wolpra98 0:8a695c71f11b 42 ((hour >> 4) & 0x03), (hour & 0x0F),
wolpra98 0:8a695c71f11b 43 (minute >> 4), (minute & 0x0F) ,
wolpra98 0:8a695c71f11b 44 (sec >> 4), (sec & 0x0F) );
wolpra98 1:b04939291414 45
wolpra98 1:b04939291414 46
wolpra98 0:8a695c71f11b 47 wait(1);
wolpra98 0:8a695c71f11b 48 }
wolpra98 0:8a695c71f11b 49 }