Command Real Time Clock RTC
 
Description The real time clock requires a battery to be fitted to the rear of the module or a 3VDC supply applied via a connector fitted to the rear of the PCB. The default format is 14 Sep 2010 09:50:06 which can be modified to suit the application which is achieved by loading the RTC into a variable having the required format. Another method is to use predefined variables of individual RTC values.
 
Syntax/Parameters SET RTC
The RTC is set using 24 hour time with LOAD( RTC, "YYYY:MM:DD:hh:mm:ss" );
  with fixed format where:
  - YYYY is year 1900-2099
  - MM   is month 01-12
  - DD   is day of month 01-31
  - hh   is hours 00-23
  - mm   is minutes 00-59
  - ss   is seconds 00-59
 
Style READ RTC
You can LOAD the RTC into a variable where the format is specified in a style as follows:
STYLE( myRtcStyle, Data )
  {
  type = text;            // Setup a text variable
  length = 64;            // with max length of 64 chars
  format = "jS F Y g:ia"; // RTC format string
  }

The RTC date/time can be displayed as a formatted string using special characters
 > Day:
    d      Day of month with leading zeros                                    01-31
     j      Day of month without leading zeros                                1-31
    S      Ordinal suffix for day of month                                      st, nd, rd, th

 > Month:
    F      Full textual representation of month                                January-December
    m      Numeric representation of month with leading zeros         01-12
    M      Short textual representation of month, three letters          Jan-Dec
    n      Numeric representation of month without leading zeros      1-12

 > Year:
    Y      Full numeric representation of year, 4 digits                    1900-2099
    y      Two digit representation of year                                     00-99

 > Time:
    a      Lowercase Ante meridiem and Post meridiem                 am, pm
    A      Uppercase Ante meridiem and Post meridiem                AM, PM
    g      12-hour format of hour without leading zeros                  1-12
    G      24-hour format of hour without leading zeros                 0-23
    h      12-hour format of hour with leading zeros                      01-12
    H      24-hour format of hour with leading zeros                      00-23
    i       Minutes with leading zeros                                             00-59
    s      Seconds with leading zeros                                           00-59
 > other characters not in list will be shown as is

Format examples:
 "d M Y H:i:s" will display as: 14 Sep 2010 09:50:06 (default format)
 "d/m/y" will display as: 14/09/10
 "jS F Y g:ia" will display as: 14th September 2010 9:50am
 
Options

Predefined variables below can be read, but not set.

 RTCSECS - numeric variable containing seconds (0-59) which can be tested or loaded into a text.
 RTCMINS - numeric variable containing minutes (0-59) which can be tested or loaded into a text.
 RTCHOURS - numeric variable containing hours (0-23) which can be tested or loaded into a text.
 RTCDAYS - numeric variable containing days (1-31) which can be tested or loaded into a text.
 RTCMONTHS - numeric variable containing month (1-12) which can be tested or loaded into a text.
 RTCYEARS - numeric variable containing year (1900-2099) which can be tested or loaded into a text.

 
Example Use vars to setup the time in a user page
VAR(years,2010,U16);
VAR(months,11,U8);
VAR(days,2,U8);
VAR(hours,10,U8);
VAR(mins,30,U8);

User changes the vars via buttons then a SAVE button would load the RTC
LOAD(RTC,years,":",months,":",days,":",hours,":",mins,":00");

VAR( RtcVar, "", myRtcStyle );  // Create a var to store formatted string
LOAD( RtcVar, RTC );        // Grab the formatted RTC time and date
TEXT( Txt1, RtcVar );;      // Show the formatted time on display in Txt1 and refresh screen
LOAD( RS2, RtcVar );      // Send formatted time on RS232 port
 

Command RTC Day Of Week
 
Description Added day of week support to RTC.
 
Options Built in variable RTCWEEKDAY reports day of week where 1=Monday, 2=Tuesday,... 7=Sunday.
Formatting parameters added for RTC
 D   Short textual representation of day, three letters: Mon-Sun
 L   Full textual representation of the day of the week: Monday-Sunday
 N   ISO-8601 numeric representation of the day of the week: 1 (for Monday) - 7 (for Sunday)
Note RTC day of week is indeterminate if RTC has not been set.
The RTC Alarm does not support day of week.
For an alarm that triggers every Thursday at 16:00, the following example can be used:
 
 
Example INT( RTA, fnc_Alarm );
LOAD( RTA, ":::16:00:00" );
FUNC( fnc_Alarm )
  {
   IF( RTCWEEKDAY != 4 ? [ EXIT( fnc_Alarm ); ] );
      // Do Thursday alarm code here...
  }
 
Command Real Time Clock Alarm (RTA)
 
Description

Support for an RTC Alarm is provided using RTA. This can be set for duration,  time or time and date.
You can set an alarm for every minute, at 17.45 every day or on the 15th March at 12.52 each year.
   To setup the interrupt which is triggered at the alarm point:
          
          
  
To load the alarm time, use same format as setting RTC.
   Only populated values are used to set the alarm, therefore alarms can be set to go off every
   minute, hour, hour:minute:second, day or month etc..
   Note, the alarm does not support the years parameter, and is ignored when setting the alarm.
   

 
Syntax/Parameters INT(name,RTA,function);
 
Style Read RTA
STYLE( myRtaStyle, Data )
  {
  type = text;            // Setup a text variable
  length = 64;            // with max length of 64 chars
  format = "jS F Y g:ia"; // RTC format string
  }
 
Options Settings can be read by accessing the built in variables
RTAMONTHS, RTADAYS, RTAHOURS, RTAMINS, RTASECS
If a value has not been set then -1 is returned.
 
Example

 Setting the alarm:
      
LOAD(RTA,":5:26:14:7:03"); // Alarm will occur every year on 26th May at 14:07:03
       LOAD(RTA,":::13:15:");   // Alarm will occur every day at 13:15:00
       LOAD(RTA,":::",hours,":",mins,":",secs); // Alarm will occur every day at hours:mins:secs
       LOAD(RTA,":::::20"); // Alarm will occur every 20 seconds past the minute.

To clear alarm:
 LOAD(RTA,0); // Clear Alarm
 LOAD(RTA,":::::"); // Clear Alarm   

VAR( RtaVar, "", myRtaStyle );  // Create a var to store formatted string
LOAD( RtaVar, RTA );        // Grab the formatted RTC time and date
TEXT( Txt1, RtaVar );;      // Show the formatted time on display in Txt1 and refresh screen
LOAD( RS2, RtaVar );      // Send formatted time on RS232 port

 

 
Update Information

 Version

 Title

Date  

 Details

00.13.00

 RTC Interrupts

25 Sep 15 

Show

Added interrupts (INT) for the real time clock: RTCSEC, RTCMIN, RTCHOUR, RTCDAY, RTCDAY, RTCMONTH, RTCYEAR.

Use: INT( name, RTCSEC, func [, priority] );

RTCSEC interrupts every second
RTCMIN interrupts every minute
RTCHOUR interrupts every hour
RTCDAY interrupts every day
RTCMONTH interrupts every month
RTCYEAR interrupts every year

Example:

// -------------------------------------------
// RTC Interrupt Test

VAR( EOL, "\\0d\\0a", TXT2 );

FUNC( fnRtcSec ) { LOAD( RS2, "RTCSECS = ", RTCSECS, EOL ); }
FUNC( fnRtcMin ) { LOAD( RS2, "RTCMINS = ", RTCMINS, EOL ); }
FUNC( fnRtcHour ) { LOAD( RS2, "RTCHOURS = ", RTCHOURS, EOL ); }
FUNC( fnRtcDay ) { LOAD( RS2, "RTCDAYS = ", RTCDAYS, EOL ); }
FUNC( fnRtcMonth ) { LOAD( RS2, "RTCMONTHS = ", RTCMONTHS, EOL ); }
FUNC( fnRtcYear ) { LOAD( RS2, "RTCYEARS = ", RTCYEARS, EOL ); }

INT( intRtcSec, RTCSEC, fnRtcSec, 1 );
INT( intRtcMin, RTCMIN, fnRtcMin, 2 );
INT( intRtcHour, RTCHOUR, fnRtcHour );
INT( intRtcDay, RTCDAY, fnRtcDay );
INT( intRtcMonth, RTCMONTH, fnRtcMonth, 4 );
INT( intRtcYear, RTCYEAR, fnRtcYear, 3 );

49.59

 RTC Interrupts

25 Sep 15 

Show

Added interrupts (INT) for the real time clock: RTCSEC, RTCMIN, RTCHOUR, RTCDAY, RTCDAY, RTCMONTH, RTCYEAR.

Use: INT( name, RTCSEC, func [, priority] );

RTCSEC interrupts every second
RTCMIN interrupts every minute
RTCHOUR interrupts every hour
RTCDAY interrupts every day
RTCMONTH interrupts every month
RTCYEAR interrupts every year

Example:

// -------------------------------------------
// RTC Interrupt Test

VAR( EOL, "\\0d\\0a", TXT2 );

FUNC( fnRtcSec ) { LOAD( RS2, "RTCSECS = ", RTCSECS, EOL ); }
FUNC( fnRtcMin ) { LOAD( RS2, "RTCMINS = ", RTCMINS, EOL ); }
FUNC( fnRtcHour ) { LOAD( RS2, "RTCHOURS = ", RTCHOURS, EOL ); }
FUNC( fnRtcDay ) { LOAD( RS2, "RTCDAYS = ", RTCDAYS, EOL ); }
FUNC( fnRtcMonth ) { LOAD( RS2, "RTCMONTHS = ", RTCMONTHS, EOL ); }
FUNC( fnRtcYear ) { LOAD( RS2, "RTCYEARS = ", RTCYEARS, EOL ); }

INT( intRtcSec, RTCSEC, fnRtcSec, 1 );
INT( intRtcMin, RTCMIN, fnRtcMin, 2 );
INT( intRtcHour, RTCHOUR, fnRtcHour );
INT( intRtcDay, RTCDAY, fnRtcDay );
INT( intRtcMonth, RTCMONTH, fnRtcMonth, 4 );
INT( intRtcYear, RTCYEAR, fnRtcYear, 3 );

49.51

 RTC Full Text Month %F% Gives Short Text

07 Feb 14 

Show

Found problem was the default values were being set to the short string by default.

// Previously
LOAD(RS2,%F%RTC); // Incorrectly Output "Feb"
LOAD(RS2,%M%RTC); // Correct

// Now
LOAD(RS2,%F%RTC); // Now Outputs "February"
LOAD(RS2,%M%RTC); // Correct

49.44

 Problem with reset affecting modules with battery fitted

10 Oct 13 

Show

A problem can occur that results in the module being unable to power up correctly. This is related to the RTC and only affects modules with a battery (or external VBATT supply).

If a battery is attached and power down occurs when a Real Time Clock interrupt is pending, the outstanding interrupt is retained in battery backed RAM.
When re-powering the module, the pending RTC interrupt is triggered before initialisation of the RTC registers causing a lock up.

The solution was to add code to clear any pending RTC interrupts during initialisation.

Fixed in
boot.bin V00.24
nandboot.bin V00.30

49.44

 Nesting of priority INT()s

09 Oct 13 

Show

New functionality has been added to support nesting of priority INT()s, ie a priority interrupt can be interrupted by another priority interrupt with a higher priority (this is now the default behaviour).

A system setup variable has been added to disable this functionality.
SETUP(SYSTEM){ intNest = y | n; } // default = y;

For 'y', priority INT()s can be interrupted by higher priority INT()s
For 'n', priority INT()s run to completion, then the highest pending priority INT() is processed next.

49.44

 Real Time (Priority) Interrupts

09 Oct 13 

Show

This issue has been resolved. A problem was found with the operating systems' nested interrupt handler. New functionality has been implemented and tested.
Nesting of priority INT()s has also been added - see TFT Improvement

49.00

 RTC Day Of Week - Added day of week support to RTC.

22 Mar 12 

Show

Added day of week support to RTC.
Built in variable RTCWEEKDAY reports day of week where 1=Monday, 2=Tuesday,... 7=Sunday.
Formatting parameters added for RTC
D Short textual representation of day, three letters: Mon-Sun
L Full textual representation of the day of the week: Monday-Sunday
N ISO-8601 numeric representation of the day of the week: 1 (for Monday) - 7 (for Sunday)
Note RTC day of week is indeterminate if RTC has not been set.
The RTC Alarm does not support day of week.
For an alarm that triggers every Thursday at 16:00, the following example can be used:

INT( RTA, fnc_Alarm );
LOAD( RTA, ":::16:00:00" );
FUNC( fnc_Alarm )
{
IF( RTCWEEKDAY != 4 ? [ EXIT( fnc_Alarm ); ] );
// Do Thursday alarm code here...
}

49.00

 RTC Alarm - Fixed problem with RTC alarm event handler running when alarm is turned off.

22 Mar 12 

Show

Fixed problem with RTC alarm event handler running when alarm is turned off.

48.24

 RTC - Special case for formatting RTC into a string.

10 Mar 12 

Show

Special case for formatting RTC into a string. The format can be passed in the %% in front of the RTC parameter:
> LOAD( txtVar, %jS F Y g:ia%RTC ); -> 18th November 2011 8:44am
This overrides the format assigned to a variable, if set.

47.12

 Fast RTC Read and Update - LOAD(RTC,...); speed significantly increased by using RTC interrupt rather than polling.

09 Sep 11 

Show

LOAD(RTC,...); speed significantly increased by using RTC interrupt rather than polling. <1ms now rather than 300-500ms and although time updated correctly in RTC, the first 1sec change after writing new value can be missed when reading the RTC values and a 2sec jump occurred which has now been resolved.

45.00

 Real Time Clock Alarm (RTA) - Added support for a RTC Alarm.

10 Jun 11 

Show

Added support for a RTC Alarm.
To setup the interrupt:
INT(name,RTA,function);

To load alarm, use same format as setting RTC.
Only populated values are used to set the alarm, therefore alarms can be set to go off every
minute, hour, hour:minute:second, day or month etc..
Note, the alarm does not support the years parameter, and is ignored when setting the alarm.

Setting the alarm:
LOAD(RTA,":5:26:14:7:03"); // Alarm will occur every year on 26th May at 14:07:03
LOAD(RTA,":::13:15:"); // Alarm will occur every day at 13:15:00
LOAD(RTA,":::",hours,":",mins,":",secs); // Alarm will occur every day at hours:mins:secs
LOAD(RTA,":::::20"); // Alarm will occur every 20 seconds past the minute.

To clear alarm:
LOAD(RTA,0); // Clear Alarm
LOAD(RTA,":::::"); // Clear Alarm

Settings can be read by accessing the built in variables
RTAYEARS, RTAMONTHS, RTADAYS, RTAHOURS, RTAMINS, RTASECS
If a value has not been set then -1 is returned.

44.00

 RTC - Fixed problem with initialisation of RTC using text string and problem with formatting RTC output.

20 May 11 

Show

Fixed problem with initialisation of RTC using text string
Fixed problem with formatting RTC output.
Fixed ordinal suffix for day of month: 11th, 12th and 13th.
RTC loading improved.
Zero padding of numbers no longer required.
Only populate parameters passed to the RTC using the LOAD() that are to be
changed.
eg LOAD(RTC,"2011:5:19:15:20:4"); will set date to 19th May 2011, time to
15:20:04
eg LOAD(RTC,":::15:20:"); will leave date as is, set hours to 15 and mins to
20, secs unchanged
eg LOAD(RTC,"11:5:19:::"); will set date to 19th May 2011, and leave time
unchanged
eg LOAD(RTC,":::",hours,":",mins,":",secs); will just set the time using vars
hours, mins, secs

35.00

 RTC - RTC can now be set by a text strings and VARs using concatenation.

12 Nov 10 

Show

RTC can now be set by a text strings and VARs using concatenation. Examples:
LOAD(RTC,"2010:12:11:10:19:26");
or
VAR(years,2010,U16);
VAR(months,11,U8);
VAR(days,2,U8);
VAR(time,"00:00",TXT);
LOAD(RTC,years,":",months,":",days,":",hours,":",time,":00");
(This will give "2010:11:02:00:00:00")
You must supply the complete string…ie you cannot just load years.

34.00

 UNICODE - Outputting of RTC and VAR’s has been fixed for Unicode.

19 Oct 10 

Show

Outputting of RTC and VAR’s has been fixed for Unicode