Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
You are viewing an older revision! See the latest version
RTC Example Main Program
main.cpp
// ToDo: Alarm in Klasse // 1. String aus int zusammenstellen // 2. String in Komponenten zerlegen und RTC/Alarm setzen // 3. Mehrfachvererbung Date/Time als ganzen String // 4. Mehrfachvererbung Uhr p95 // puer virtual methodes p102 // abstrakte Basisklassen p103 // Tasks: // 1. Klasse Date/Time erweitern day, ... // 2. Vererbung Zeit/Datum --> Deutsch: Setzten, Stellen, Zählen // 3. Drucke // 4. Zu Datum einen Konstruktor um das Datum zu setzen // 5. Methode, die den Wochentag mit ausgibt // 6. Von Datum die Klasse DatumAusgabe ableiten, die das Datum in verschiedenen Versionen ausgibt Do, der 14. Juli 2015 .... // 7. Virtuelle Methode DruckDatum in 6., die den Wochentag ausgibt // 8. aus 7. DruckDatum überschreiben die das Datum in spez. Form ausgibt, wie Do, der 14. Juli 2015 #include "mbed.h" #include "const.h" #include "rtc.h" #include "Date.h" #include "Datestr.h" #include "Time.h" #include "string" #include "Clock.h" Serial pc(USBTX, USBRX); //I2C i2c(p28, p27); char year, month, day, week; char hour, minute, sec; string tag ("Montag"); string week_str[7] = {"MON","TUE","WED","THU","FRI","SAT","SUN"}; char week_chr[7][4] = {"MON","TUE","WED","THU","FRI","SAT","SUN"}; char hour_a, minute_a, week_a, reg_01; #ifdef TARGET_LPC11XX InterruptIn alarm(P1_28); #else InterruptIn alarm(p15); // LPC1768 JoyStick up #endif DigitalOut myled1(LED1); DigitalOut myled2(LED2); void push1() // Interruptfunktion alarm { pc.printf("********\n" ); pc.printf("ALARM\n" ); pc.printf("********\n" ); myled1= 1; } bool state = false; InterruptIn sw1(P0_10); void getNextState() { if(sw1) state = !state; } int main() { sw1.rise(&getNextState); RTC *pRtc; // Zeiger vom Type der Klasse RTC pRtc = new RTC; // Mit new wird Speicher wird auf dem Heap reserviert #ifdef TARGET_LPC11XX pRtc = new RTC(p28, p27); // Speicher mit parametrisierten Konstruktor reserviert #endif pRtc->rtc_init(); // Auf die Memeber (Elemente) wird über den Operator -> zugegriffen delete pRtc; Time rtc; //(p28, p27); Date *pDate; Date date; Datestr datestr; pDate = &date; //pc.printf("%s \n", pDate->Ausgabe()); Clock clock; clock.GetDay(); clock.GetHours(); pc.printf("Setting up RTC\n"); //rtc.rtc_init(); alarm.fall(&push1); pc.printf("Setting up RTC\n"); rtc.rtc_alarm(); myled1 = 0; while(1) { week = rtc.rtc_read(WEEKDAYS); if(state) // change state for virtual methode GetDay p79 pDate = &date; else pDate = &datestr; // Alarm hour_a = rtc.rtc_read(HOUR_ALARM); minute_a = rtc.rtc_read(MINUTE_ALARM); week_a = rtc.rtc_read(WEEKDAY_ALARM); pc.printf("%s \n", pDate->GetDay(date.GetDay())); // Plain Old Data pc.printf("%s", clock.Print()); wait(1); } }