Hi all,
There is a new PIC24 library: RTCC_P24.mpas. It handles the internal RTCC (Real time clock and calender).
For the unit's code and a usage example, see
http://www.rosseeld.be/DRO/PIC/libraries.htm#RTCC.
Important: at this moment (using mP v5.00) SSA optimisation should be set to OFF.
The library's interface:
Code: Select all
// ------------------- Interface ------------------------
type TTimeDate =
record
Hours, Mins, Secs, WeekDay, Day, Month: byte;
Year: word;
end;
TAlarm =
record
Hours, Mins, Secs, WeekDay, Day, Month: byte;
end;
// ----- General ----
procedure RTCC_Secondary_Oscillator_On(On_: boolean);
// Starts the secondary (32.758 Khz) oscillator. X-tal and C's needed
procedure RTCC_Set_Write_Enable(On_: boolean);
// Makes the RTCC writable (On=true) or ReadOnly (On = false), needed for starting up
procedure RTCC_Init(Enable_SOSC: boolean; Adjustment: Short);
// initialization of the RTCC with optional switch of of secondary oscillator,
// calibration according the Adjustment value (-128..+127).
// ----- Clock ----
procedure RTCC_Set(var TimeDate: TTimeDate);
// Sets the clock values in the RTCC. All values should be delivered in BCD.
procedure RTCC_Get(var TimeDate: TTimeDate);
// Gets the clock values out of the RTCC. All values returned are in BCD.
procedure RTCC_Set_Clock_On_Off(On_: boolean);
// Enables or disables the clock according "On_" (true = on, false = off)
function RTCC_Clock_On: boolean;
// returns true if the RTCC clock is running, else false
procedure RTCC_Output(Val: byte);
// sets the RTCC output pin according Val
procedure RTCC_TimeStr(var TimeDate: TTimeDate; var Ts: string[8]);
// converts TimeDate into a displayable "time" string: hh:mm:ss (24 hr mode) in Ts
procedure RTCC_DateStr(var TimeDate: TTimeDate; var Ds: string[10]);
// converts TimeDate into a displayable "date" string: dd/mm/yyyy in Ds
procedure RTCC_TimeDateStr(var TimeDate: TTimeDate; var Ts: string[8]; var Ds: string[10]);
// converts TimeDate into a displayable "time" string: hh:mm:ss (24 hr mode) in Ts, and
// a displayable "date" string: dd/mm/yyyy in Ds
function RTCC_TimeChanged(var TimeDate: TTimeDate): boolean;
// returns true if the current time (only secs compared) is different than TimeDate
// also returns the current time in TimeDate
procedure RTCC_Fill_TimeDate(var TimeDate: TTimeDate; Hours, Mins, Secs, WeekDay, Day, Month: byte; Year: word);
// Fills TimeDate with the values Hours, .. Year
// ----- Alarm ----
procedure RTCC_Get_Alarm(var Alarm: TAlarm);
// Gets the alarm time out of the RTCC, all values returned are in BCD
procedure RTCC_Set_Alarm(var Alarm: TAlarm);
// Sets the alarm time in the RTCC. All values should be delivered in BCD.
procedure RTCC_Set_Alarm_Config(Mask: byte; Chime: boolean; Repeat_: byte);
// Sets the alarm configuration (see datasheet for the details)
procedure RTCC_Set_Alarm_On_Off(On_: boolean);
// Enables or disables the alarm according "On_" (true = on, false = off)
function RTCC_Alarm_On: boolean;
// returns true if the RTCC alarm is on, else false
// ------ Constants --------
const // values for RTCC_Output
_RTCC_OUTPUT_OFF = 0;
_RTCC_OUTPUT_1HZ = 1;
_RTCC_OUTPUT_ALARM = 2; // the RTCC output will change state on every alarm
// Alarm masks
_RTCC_MASK_HALF_SEC = 0; // Alarm settings do not matter
_RTCC_MASK_ONE_SEC = 1; // "
_RTCC_MASK_TEN_SEC = 2; // Every 10 seconds, on the alarm seconds units
_RTCC_MASK_ONE_MIN = 3; // Every minute, on the alarm seconds
_RTCC_MASK_TEN_MIN = 4; // Every 10 minutes, on the alarm minutes units and the alarm seconds
_RTCC_MASK_ONE_HOUR = 5; // Every hour, on the alarm minutes and alarm seconds
_RTCC_MASK_ONE_DAY = 6; // Every day, on the alarm hours, minutes and seconds
_RTCC_MASK_ONE_WEEK = 7; // Every week, on the alarm weekday, hours, minutes and seconds
_RTCC_MASK_ONE_MONTH = 8; // Every month, on the alarm day, hours, minutes and seconds
_RTCC_MASK_ONE_YEAR = 9; // Every year, on the alarm month, day, hours, minutes and seconds
implementation
Have fun!
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)