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.
RTC Methodendefinition
An dieser Stelle erfolgt das Kopieren der Funktionen aus der main-Datei, außer printTime() in main wird ersetzt durch den Code aus der Funktion printTime():
// // @ Project : RTC Date Time Clock // @ File Name : RTC8563.cpp // @ Date : 06.04.2015 // @ Author : Franz Pucher // @ Copyright : pe@bulme.at // #include "mbed.h" #include "const.h" #include "RTC8563.h" RTC8563::RTC8563() : i2c(p28, p27) // delete void and add call to base constructor { // Initialise I2C i2c.frequency(40000); char init1[2] = {0x6, 0x00}; char init2[2] = {0x7, 0xff}; i2c.write(0x40, init1, 2); i2c.write(0x40, init2, 2); } RTC8563::RTC8563(PinName sda, PinName scl) : i2c(sda, scl) { // Initialise I2C i2c.frequency(40000); char init1[2] = {0x6, 0x00}; char init2[2] = {0x7, 0xff}; i2c.write(0x40, init1, 2); i2c.write(0x40, init2, 2); } char RTC8563::rtc_read(char address) { char value; i2c.start(); i2c.write(RTC8563_ADR); i2c.write(address); i2c.start(); i2c.write(RTC8563_ADR | _READ); value = i2c.read(0); i2c.stop(); return value; } void RTC8563::rtc_write(char address, char value) { i2c.start(); i2c.write(RTC8563_ADR); i2c.write(address); i2c.write(value); i2c.stop(); } void RTC8563::rtc_init() { } void RTC8563::rtc_alarm() { }
Die Main-Funktion hat somit folgendes aussehen:
#include "mbed.h" #include "const.h" #include "RTC8563.h" #include "string" Serial pc(USBTX, USBRX); //I2C i2c(p28, p27); uint8_t year, month, day, week; uint8_t hour, minute, sec; char week_chr[7][4] = {"MON","TUE","WED","THU","FRI","SAT","SUN"}; int main() { RTC8563 rtc; // instanziieren des Objektes rtc pc.printf("Setting up RTC\n"); //rtc.rtc_init(); while(1) { //printTime(); year = rtc.rtc_read(YEARS); // Aufruf der Methode rtc_read der Instanz (Objekt) rtc month = rtc.rtc_read(MONTHS); day = rtc.rtc_read(DAYS); week = rtc.rtc_read(WEEKDAYS); hour = rtc.rtc_read(HOURS); minute = rtc.rtc_read(MINUTES); sec = rtc.rtc_read(SECONDS); //Datum Ausgabe pc.printf("20%x%x/%x%x/%x%x %s\n", ((year >> 4) & 0x03) , (year & 0x0F) , ((month >> 4) & 0x01), (month & 0x0F) , ((day >> 4) & 0x03), (day & 0x0F) , week_chr[week & 0x07]); //Zeit Ausgabe pc.printf("%x%x:%x%x:%x%x\n", ((hour >> 4) & 0x03), (hour & 0x0F), (minute >> 4), (minute & 0x0F) , (sec >> 4), (sec & 0x0F) ); wait(1); } }
Teste das Programm mit HIMBED M0 Board.