Allows easy usage of the LPC1768 RTC interrupts

Dependents:   Mini_DK_clk MakerBotServer GT-ACQUAPLUS_Consumo GT-ACQUAPLUS_Eficiencia ... more

Embed: (wiki syntax)

« Back to documentation index

RTC Class Reference

Library to get access to the interrupt functionality of the LPC1768's RTC. More...

#include <RTC.h>

Public Types

enum  TimeUnit
 

Available time units for interrupts.

More...

Static Public Member Functions

static void attach (void(*function)(void), TimeUnit interval)
 Call a function when the specified time unit increases.
static void detach (TimeUnit interval)
 Detach an interrupt function.
static void alarm (void(*function)(void), tm alarmTime)
 Call a function when a specified time is reached.
static void alarmOff (void)
 Disable the alarm.
static tm getDefaultTM (void)
 Returns a default tm structure where each field is initialized to -1, so it is ignored by the alarm function.

Detailed Description

Library to get access to the interrupt functionality of the LPC1768's RTC.

This class is completely static: which means you don't have to create an RTC object, there is always one object automatically created when you include this class. Since there is only one RTC, more than one would make no sense.

 #include "mbed.h"
 #include "RTC.h"

 DigitalOut led(LED1);

 void ledFunction( void )
 {
     led = 1;
     RTC::detach(RTC::Second);
 }
 
 void displayFunction( void )
 {
     time_t seconds = time(NULL);
     printf("%s", ctime(&seconds));
 }
 
 void alarmFunction( void )
 {
     error("Not most useful alarm function");
 }
 
 int main()
 {
     set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37
 
     tm t = RTC::getDefaultTM();
     t.tm_sec = 5;
     t.tm_min = 36;
 
     RTC::alarm(&alarmFunction, t);
     RTC::attach(&displayFunction, RTC::Second);
     RTC::attach(&ledFunction, RTC::Minute);
 
     while(1);
 }

Definition at line 52 of file RTC.h.


Member Enumeration Documentation

enum TimeUnit

Available time units for interrupts.

RTC::Second, RTC::Minute, RTC::Hour, RTC::Day, RTC::Month, RTC::Year

Definition at line 60 of file RTC.h.


Member Function Documentation

void alarm ( void(*)(void)  function,
tm  alarmTime 
) [static]

Call a function when a specified time is reached.

Only one alarm is possible. Make fields of the tm structure -1 for don't care.

Member functions of a class can be attached the normal way (similar to for example Ticker).

Parameters:
function- the function to call
alarmTime- tm structure which specifies when to activate the alarm

Definition at line 95 of file RTC.cpp.

void alarmOff ( void   ) [static]

Disable the alarm.

Definition at line 186 of file RTC.cpp.

void attach ( void(*)(void)  function,
TimeUnit  interval 
) [static]

Call a function when the specified time unit increases.

You can attach one function for each TimeUnit. When several are attached the smalles TimeUnit is called first.

Member functions of a class can be attached the normal way (similar to for example Ticker).

Parameters:
function- the function to call
interval- the TimeUnit which specifies the interval

Definition at line 9 of file RTC.cpp.

void detach ( TimeUnit  interval ) [static]

Detach an interrupt function.

Parameters:
interval- the TimeUnit of the interrupt to detach

Definition at line 69 of file RTC.cpp.

tm getDefaultTM ( void   ) [static]

Returns a default tm structure where each field is initialized to -1, so it is ignored by the alarm function.

Available fields: http://www.cplusplus.com/reference/ctime/tm/ Except tm_isdst all of them can be used for the alarm

Parameters:
return- tm structure initialized to -1

Definition at line 233 of file RTC.cpp.