I'm Lorenz Gandalf a 18 year old programmer from Austria. I love humans ,Dyrus,Bjergsen and Santorin. GG WP
Fork of rtc_class by
Revision 2:f75062350241, committed 2015-04-16
- Comitter:
- bulmecisco
- Date:
- Thu Apr 16 10:25:33 2015 +0000
- Parent:
- 1:554eb6675279
- Commit message:
- rtc functions in class RTC8563 transferred
Changed in this revision
diff -r 554eb6675279 -r f75062350241 RTC8563.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RTC8563.cpp Thu Apr 16 10:25:33 2015 +0000 @@ -0,0 +1,63 @@ +// +// @ 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() +{ +} \ No newline at end of file
diff -r 554eb6675279 -r f75062350241 RTC8563.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RTC8563.h Thu Apr 16 10:25:33 2015 +0000 @@ -0,0 +1,26 @@ +// +// @ Project : RTC8563 +// @ File Name : RTC8563.h +// @ Date : 06.04.2015 +// @ Author : Franz Pucher +// @ Copyright : pe@bulme.at +// +#include "mbed.h" +#include "const.h" + +#if !defined(_RTC8563_H) +#define _RTC8563_H + +class RTC8563 +{ +public: + RTC8563(); // delete void + RTC8563(PinName sda, PinName scl); + char rtc_read(char address); + void rtc_write(char address, char value); + void rtc_init(); + void rtc_alarm(); +protected: + I2C i2c; +}; +#endif //_RTC8563_H \ No newline at end of file
diff -r 554eb6675279 -r f75062350241 const.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/const.h Thu Apr 16 10:25:33 2015 +0000 @@ -0,0 +1,36 @@ +/*********************************** +name: const.h Version: 0.1 +author: PE HTL BULME +email: pe@bulme.at +description: + Named constants definitions for registers + PCF8563 RTC on HIMBED M0 - LPC11U24 +***********************************/ + +#ifndef CONST_H +#define CONST_H + +// Address of RTC +const int RTC8563_ADR = 0xA2; +// Control and status +const int CONTROL1 = 0x00; +const int CONTROL2 = 0x01; +// Time and date +const int SECONDS = 0x02; +const int MINUTES = 0x03; +const int HOURS = 0x04; +const int DAYS = 0x05; +const int WEEKDAYS = 0x06; +const int MONTHS = 0x07; +const int YEARS = 0x08; +// Alarm +const int MINUTE_ALARM = 0x09; +const int HOUR_ALARM = 0x0A; +const int DAY_ALARM = 0x0B; +const int WEEKDAY_ALARM = 0x0C; +// Clock and timer +const int CLOCKOUT_FREQ = 0x0D; +const int TIMER_CINTROL = 0x0E; +const int _READ = 0x01; + +#endif \ No newline at end of file
diff -r 554eb6675279 -r f75062350241 main.cpp --- a/main.cpp Wed Apr 15 07:15:25 2015 +0000 +++ b/main.cpp Thu Apr 16 10:25:33 2015 +0000 @@ -9,153 +9,46 @@ programed by Franz Wolf (wf@bulme.at) ***********************************/ #include "mbed.h" - -// Symbolic constants -#define RTC8563_ADR 0xA2 -#define CONTROL1 0x00 -#define CONTROL2 0x01 -#define SECONDS 0x02 -#define MINUTES 0x03 -#define HOURS 0x04 -#define DAYS 0x05 -#define WEEKDAYS 0x06 -#define MONTHS 0x07 -#define YEARS 0x08 -#define MINUTE_ALARM 0x09 -#define HOUR_ALARM 0x0A -#define DAY_ALARM 0x0B -#define WEEKDAY_ALARM 0x0C -#define CLOCKOUT_FREQ 0x0D -#define TIMER_CINTROL 0x0E -#define TIMER 0x0F -#define _READ 0x01 - -// Wiring +#include "const.h" +#include "RTC8563.h" +#include "string" + Serial pc(USBTX, USBRX); -I2C i2c(p28, p27); - -InterruptIn alarm(P1_28); - -DigitalOut myled1(LED1); -DigitalOut myled2(LED2); - -// Function prototyping -void printTime(); -void rtc_init(); -char rtc_read(char address); -void rtc_write(char address, char value); - -// Global variables -char year, month, day, week; -char hour, minute, sec; - -char week_val; +//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"}; - -// Functiondefinitions -void printTime() -{ - year = rtc_read(YEARS); - month = rtc_read(MONTHS); - day = rtc_read(DAYS); - week = rtc_read(WEEKDAYS); - hour = rtc_read(HOURS); - minute = rtc_read(MINUTES); - sec = 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) ); -} - -void rtc_init() -{ - pc.printf("Setting up RTC\n"); - - // Formatierung - // 2015/01/24 - // 10:32:00 - - week_val = 0x04; // SAT - rtc_write(CONTROL1, 0x20); //stop - rtc_write(CONTROL2, 0x00); - rtc_write(YEARS, (0x15)); - rtc_write(MONTHS, (0x03)); - rtc_write(DAYS, (0x13)); - rtc_write(HOURS, (0x14)); - rtc_write(MINUTES, (0x47)); - rtc_write(SECONDS, (0x00)); - rtc_write(WEEKDAYS, week_val); - rtc_write(CLOCKOUT_FREQ, 0x00); // 0x83 = TE on & 1Hz - rtc_write(TIMER_CINTROL, 0x00); - rtc_write(CONTROL1, 0x00); //start -} - -char 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 rtc_write(char address, char value) -{ - i2c.start(); - i2c.write(RTC8563_ADR); - i2c.write(address); - i2c.write(value); - i2c.stop(); -} - -void rtc_alarm() -{ - pc.printf("Setting up RTC\n"); - // Formatierung - // 2015/01/24 - // 17:02:00 MON - - // week_val = 0x05; // SAT - rtc_write(CONTROL1, 0x20); //stop - rtc_write(CONTROL2, 0x02); // alarm AF alarm flag bit - rtc_write(DAY_ALARM, (0x80) ); - rtc_write(HOUR_ALARM, (0x97)); - rtc_write(MINUTE_ALARM, (0x02)); - rtc_write(WEEKDAY_ALARM, (0x80)); - rtc_write(CONTROL1, 0x00); //start -} -//************************************ -void push1() // Interruptfunktion alarm -{ - pc.printf("********\n" ); - pc.printf("ALARM\n" ); - pc.printf("********\n" ); - myled1= 1; -} - - -// main program + int main() { - rtc_init(); - alarm.fall(&push1); - rtc_alarm(); + RTC8563 rtc; // instanziieren des Objektes rtc + + pc.printf("Setting up RTC\n"); + //rtc.rtc_init(); + while(1) { - printTime(); + //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); } -} +} \ No newline at end of file