Simon Liebelt / Mbed 2 deprecated BewaesserungsanlageTCGensingen_sicher

Dependencies:   mbed

Committer:
SimonLie
Date:
Tue Mar 28 09:07:49 2017 +0000
Revision:
0:34f429428d45
inital version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SimonLie 0:34f429428d45 1 #include "mbed.h"
SimonLie 0:34f429428d45 2 #include "RTC.h"
SimonLie 0:34f429428d45 3
SimonLie 0:34f429428d45 4 /* Pinfunktionen */
SimonLie 0:34f429428d45 5 I2C i2cRTC(PB_9,PB_8);
SimonLie 0:34f429428d45 6
SimonLie 0:34f429428d45 7 /* Funktionen */
SimonLie 0:34f429428d45 8 void vfStopRTCOszi(){
SimonLie 0:34f429428d45 9 char data[2];
SimonLie 0:34f429428d45 10 data[0] = 0x00;
SimonLie 0:34f429428d45 11 data[1] = 0x80;
SimonLie 0:34f429428d45 12 i2cRTC.write(nRTCADRESS_W, data, 2);
SimonLie 0:34f429428d45 13 }
SimonLie 0:34f429428d45 14
SimonLie 0:34f429428d45 15 void vfStartAndInitRTC(unsigned char bSeconds,
SimonLie 0:34f429428d45 16 unsigned char bMinutes,
SimonLie 0:34f429428d45 17 unsigned char bHours,
SimonLie 0:34f429428d45 18 unsigned char bDay,
SimonLie 0:34f429428d45 19 unsigned char bDate,
SimonLie 0:34f429428d45 20 unsigned char bMonth,
SimonLie 0:34f429428d45 21 unsigned char bYear,
SimonLie 0:34f429428d45 22 unsigned char bControl){
SimonLie 0:34f429428d45 23 char acCalendar[9];
SimonLie 0:34f429428d45 24 acCalendar[0] = 0x00;
SimonLie 0:34f429428d45 25 acCalendar[1] = cfDezToBcd(bSeconds);
SimonLie 0:34f429428d45 26 acCalendar[2] = cfDezToBcd(bMinutes);
SimonLie 0:34f429428d45 27 acCalendar[3] = cfDezToBcd(bHours);
SimonLie 0:34f429428d45 28 acCalendar[4] = cfDezToBcd(bDay);
SimonLie 0:34f429428d45 29 acCalendar[5] = cfDezToBcd(bDate);
SimonLie 0:34f429428d45 30 acCalendar[6] = cfDezToBcd(bMonth);
SimonLie 0:34f429428d45 31 acCalendar[7] = cfDezToBcd(bYear);
SimonLie 0:34f429428d45 32 acCalendar[8] = cfDezToBcd(bControl);
SimonLie 0:34f429428d45 33 i2cRTC.write(nRTCADRESS_W, acCalendar, 9);
SimonLie 0:34f429428d45 34 }
SimonLie 0:34f429428d45 35 void vfSetTime(unsigned char bSeconds,
SimonLie 0:34f429428d45 36 unsigned char bMinutes,
SimonLie 0:34f429428d45 37 unsigned char bHours){
SimonLie 0:34f429428d45 38 char acTime[4];
SimonLie 0:34f429428d45 39 acTime[0] = 0x00;
SimonLie 0:34f429428d45 40 acTime[1] = cfDezToBcd(bSeconds);
SimonLie 0:34f429428d45 41 acTime[2] = cfDezToBcd(bMinutes);
SimonLie 0:34f429428d45 42 acTime[3] = cfDezToBcd(bHours);
SimonLie 0:34f429428d45 43 i2cRTC.write(nRTCADRESS_W, acTime, 4);
SimonLie 0:34f429428d45 44 }
SimonLie 0:34f429428d45 45
SimonLie 0:34f429428d45 46
SimonLie 0:34f429428d45 47 void vfGetTime(unsigned char *bSeconds,
SimonLie 0:34f429428d45 48 unsigned char *bMinutes,
SimonLie 0:34f429428d45 49 unsigned char *bHours){
SimonLie 0:34f429428d45 50 char time[1];
SimonLie 0:34f429428d45 51 char data[3];
SimonLie 0:34f429428d45 52 time[0] = 0x00; //Adresse des Sekunden-Registers
SimonLie 0:34f429428d45 53 i2cRTC.write(nRTCADRESS_W, time, 1);
SimonLie 0:34f429428d45 54 i2cRTC.read(nRTCADRESS_R, data, 3);
SimonLie 0:34f429428d45 55 *bSeconds = bfBcdToDez((unsigned char)data[0]);
SimonLie 0:34f429428d45 56 *bMinutes = bfBcdToDez((unsigned char)data[1]);
SimonLie 0:34f429428d45 57 *bHours = bfBcdToDez((unsigned char)data[2]);
SimonLie 0:34f429428d45 58 }
SimonLie 0:34f429428d45 59
SimonLie 0:34f429428d45 60 unsigned char bfBcdToDez(unsigned char bBcdValue){
SimonLie 0:34f429428d45 61 unsigned char bDezValue = 0;
SimonLie 0:34f429428d45 62 bDezValue = bBcdValue & 0x0F;
SimonLie 0:34f429428d45 63 bDezValue = bDezValue + ((bBcdValue >> 4) * 10);
SimonLie 0:34f429428d45 64 return bDezValue;
SimonLie 0:34f429428d45 65 }
SimonLie 0:34f429428d45 66
SimonLie 0:34f429428d45 67 char cfDezToBcd(unsigned char bDezValue){
SimonLie 0:34f429428d45 68 char cBcdValue = 0;
SimonLie 0:34f429428d45 69 cBcdValue = bDezValue % 10;
SimonLie 0:34f429428d45 70 cBcdValue = cBcdValue | (((bDezValue - (bDezValue%10)) / 10) << 4);
SimonLie 0:34f429428d45 71 return cBcdValue;
SimonLie 0:34f429428d45 72 }