Functions and formatted printing of time and date for RTC8563

Dependencies:   mbed

Inhalt

I2C RTC on HIMBED

/media/uploads/bulmecisco/rtc.jpg

Definition der benannten Konstanten für die Register des PCF8563 (Tabelle 4)
Praeprozessor-Direktiven #define werden durch benannte Konstante ersetzt

const.h

/***********************************
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

Register organisation

/media/uploads/bulmecisco/register.jpg

Terminal program

Mit einem Terminal Programm (z.B. HTERM) können die Werte von der seriellen Schnittstelle (COM-Port) angezeigt werden:

/media/uploads/bulmecisco/hterm.jpg

Next

main.cpp

Committer:
bulmecisco
Date:
2015-04-16
Revision:
2:f75062350241
Parent:
1:554eb6675279

File content as of revision 2:f75062350241:

/***********************************
name:   main.cpp    Version: 0.1
author: PE HTL BULME
email:  pe@bulme.at
description:
    Real Time Clock (RTC8563) 
    on HIMBED M0 - LPC11U24 
    prints formatted time and date values to serial port
    programed by Franz Wolf (wf@bulme.at) 
***********************************/
#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);
    }
}