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.
Diff: RTC.cpp
- Revision:
- 0:34f429428d45
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/RTC.cpp Tue Mar 28 09:07:49 2017 +0000
@@ -0,0 +1,72 @@
+#include "mbed.h"
+#include "RTC.h"
+
+/* Pinfunktionen */
+I2C i2cRTC(PB_9,PB_8);
+
+/* Funktionen */
+void vfStopRTCOszi(){
+ char data[2];
+ data[0] = 0x00;
+ data[1] = 0x80;
+ i2cRTC.write(nRTCADRESS_W, data, 2);
+ }
+
+void vfStartAndInitRTC(unsigned char bSeconds,
+ unsigned char bMinutes,
+ unsigned char bHours,
+ unsigned char bDay,
+ unsigned char bDate,
+ unsigned char bMonth,
+ unsigned char bYear,
+ unsigned char bControl){
+ char acCalendar[9];
+ acCalendar[0] = 0x00;
+ acCalendar[1] = cfDezToBcd(bSeconds);
+ acCalendar[2] = cfDezToBcd(bMinutes);
+ acCalendar[3] = cfDezToBcd(bHours);
+ acCalendar[4] = cfDezToBcd(bDay);
+ acCalendar[5] = cfDezToBcd(bDate);
+ acCalendar[6] = cfDezToBcd(bMonth);
+ acCalendar[7] = cfDezToBcd(bYear);
+ acCalendar[8] = cfDezToBcd(bControl);
+ i2cRTC.write(nRTCADRESS_W, acCalendar, 9);
+ }
+void vfSetTime(unsigned char bSeconds,
+ unsigned char bMinutes,
+ unsigned char bHours){
+ char acTime[4];
+ acTime[0] = 0x00;
+ acTime[1] = cfDezToBcd(bSeconds);
+ acTime[2] = cfDezToBcd(bMinutes);
+ acTime[3] = cfDezToBcd(bHours);
+ i2cRTC.write(nRTCADRESS_W, acTime, 4);
+ }
+
+
+void vfGetTime(unsigned char *bSeconds,
+ unsigned char *bMinutes,
+ unsigned char *bHours){
+ char time[1];
+ char data[3];
+ time[0] = 0x00; //Adresse des Sekunden-Registers
+ i2cRTC.write(nRTCADRESS_W, time, 1);
+ i2cRTC.read(nRTCADRESS_R, data, 3);
+ *bSeconds = bfBcdToDez((unsigned char)data[0]);
+ *bMinutes = bfBcdToDez((unsigned char)data[1]);
+ *bHours = bfBcdToDez((unsigned char)data[2]);
+ }
+
+unsigned char bfBcdToDez(unsigned char bBcdValue){
+ unsigned char bDezValue = 0;
+ bDezValue = bBcdValue & 0x0F;
+ bDezValue = bDezValue + ((bBcdValue >> 4) * 10);
+ return bDezValue;
+ }
+
+char cfDezToBcd(unsigned char bDezValue){
+ char cBcdValue = 0;
+ cBcdValue = bDezValue % 10;
+ cBcdValue = cBcdValue | (((bDezValue - (bDezValue%10)) / 10) << 4);
+ return cBcdValue;
+ }
\ No newline at end of file