Transcript
RTCC Operation Setting Date & Time The Alarm Example
Real-Time Clock Calendar Embedded Systems Interfacing
03 November 2011
Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
RTCC Operation
Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
RTCC Operation (cont’d)
Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
Write Enable Write enable is used to prevent new time/date values from being written to the Real-Time Clock Calendar Write enable uses special 0x55 and 0xAA pattern MOV #NVMKEY,W1 MOV.b #0x55,W2 MOV.b #0xAA,W3 MOV.b W2,[W1] MOV.b W3,[W1] BSET RCFGCAL,#13 The RTCWREN bit-set must follow the 0x55-0xAA pattern within one clock cycle; C-30 statements may not guarantee this. Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
Write Enable (cont’d) Another version of the code // RCFGCAL unlock sequence asm volatile(“disi #5”); asm volatile(“mov #0x55,w7”); asm volatile(“mov w7, NVMKEY”); asm volatile(“mov #0xAA,w8”); asm volatile(“mov w8, NVMKEY”); asm volatile(“bset RCFGCAL, #13”);//RTCWREN=1 asm volatile(“nop”); asm volatile(“nop”);
Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
Write Enable (cont’d)
To Lock the RTCC register write after setting the registers Set RTCWREN = 0 No 0x55-0xAA sequence is needed
Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
Adjusting the Date and Time
The RTCPTR < 1 : 0 > register determines which part of the RTCC is accessed When RTCVAL < 15 : 9 > is read or written to, RTCPTR < 1 : 0 > decrements by 1 Once RTCPTR < 1 : 0 > reaches 00, the MINUTES and SECONDS value is accessable until RTCPTR < 1 : 0 > is manually changed Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
Adjusting the Date & Time (cont’d)
Example Assume the unlock sequence has been done RTCEN=0; //disable the module //Set 17 Sep 2009 THURS 12:45:20 RTCPTR=3; RTCVAL=0x2009; //YEAR RTCVAL=0x0816 //MONTH-1:DAY-1 RTCVAL=0x0412; //WEEKDAY:HOURS RTCVAL=0x4520;//MINUTES:SECONDS
Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
Alarm
The alarm reads and writes similarly to RTC registers The alarm also has a mask The alarm has a chime mechanism The alarm has no locking or unlocking mechanism The alamr pointer ( ALRMPRT ) works similarly to the RTC pointer ( RTCPTR)
Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
The Alarm (cont’d)
Alarm enable bit ALRMEN=1; //enables alarm, cleared when chime is done ALRMEN=0; //disables the alarm Chime enable CHIME=1;//enables chime ARPT to rollover CHIME=0; disables chime ARPT to rollover
Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
Alarm Mask Alarm mask AMASK=0; AMASK=1; AMASK=2; AMASK=3; AMASK=4; AMASK=5; AMASK=6; AMASK=7; AMASK=8; AMASK=9;
//every 21 second //every second //every 10 seconds //every minute //every 10 minutes //every hour //once a day //once a week //once a month //once a year except 29 Feb
Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
Alarm Features Alarm repeat count ARPT=0; // no repeat .. . ARPT=255; // repeats 255 more times At every alarm an interrupt is generated RTCC outpuit pin toggle if mapped to an I/O pin
RTCC operates during sleep mode Device reset causes the alarm to be disabled, but the RTCC continues operation Power-on reset causes the alarm to be disabled, and RTCC needs reset Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
An Example
Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
#include
#define EECON2 NVMKEY // RCFGCAL unlock sequence asm volatile(“disi #5”); asm volatile(“mov #0x55,w7”); asm volatile(“mov w7, NVMKEY”); asm volatile(“mov #0xAA,w8”); asm volatile(“mov w8, NVMKEY”); asm volatile(“bset RCFGCAL, #13”);//RTCWREN=1 asm volatile(“nop”); asm volatile(“nop”);
Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
RTCEN=0; //disable the module //Set 17 Sep 2009 THURS 12:45:20 RTCPTR=3; RTCVAL=0x2009; //YEAR RTCVAL=0x0816 //MONTH-1:DAY-1 RTCVAL=0x0412; //WEEKDAY:HOURS RTCVAL=0x4520;//MINUTES:SECONDS //enable and lock RTCEN=1; RTCWREN=0; ALRMEN=0; // diable the alarm
Embedded Systems Interfacing
Real-Time Clock Calendar
RTCC Operation Setting Date & Time The Alarm Example
ALRMPTR=2; ALRMVAL=0x0723;//MONTH-1:DAY-1 RTCVAL=0x0008; //WEEKDAY:HOURS RTCVAL=0x0000;//MINUTES:SECONDS ARPT=0; //once CHIME=1; //set the alarm mask AMASK=0b1001; ALRMEN=1; //enable alarm RTCIF=0; //clear the interrupt flag RTCIE=1; //enable the interrupt
Embedded Systems Interfacing
Real-Time Clock Calendar