Fujitsu FR81S User Manual

Page of 2342
CHAPTER 28: REAL-TIME CLOCK(RTC) 
 
 
8. Sample Program 
 
FUJITSU SEMICONDUCTOR LIMITED 
CHAPTER
 : REAL-TIME CLOCK(RTC) 
FUJITSU SEMICONDUCTOR CONFIDENTIAL 
30 
8.  Sample Program 
This section explains the sample program of the real-time clock(RTC). 
Setting Procedure Example 1 
 
Start to count the real-time clock from 10 days 10 hours 10 minutes 00 
second, enable the external interrupt (INT0) for "H" level detection, and 
move to the watch mode. 
Restore from the watch mode in case of external interrupt detection, and 
read the time of the real-time clock. 
RTC initialization 
RTC startup, interrupt level setting 
External interrupt settings 
Move to the watch mode 
Reading RTC 
after restoration from the watch mode 
 
<RTC Initialization Settings> 
-RTC                                                                Register name. bit name 
Register initialization 
WTCR.ST 
Setting of interval time (1second) 
WTBR 
Setting of the time initialization 
values 
WTSR 
WTMR 
WTHR 
WTDR 
Initialization setting for RTC 
interrupts 
WTCRM,WTCRL 
WTCRH 
 
 
 
<RTC startup, interrupt level setting> 
                                                                            Register name. bit name 
RTC startup 
WTCR.ST 
Setting of interrupt level (RTC) 
ICR21 
Setting of interrupt level (INT0) 
ICR00 
Setting of the I flag 
(CCR) 
 
 
<RTC time reading preparation (interrupt settings) > 
                                                                            Register name. bit name 
RTC interrupt setting 
WTCR 
.INT0 
.INTE0 
 
<RTC interrupt> 
                                                                            Register name. bit name 
Time reading 
WTHR 
WTMR 
WTSR 
WTDR 
Interrupt disable 
WTCR.INTE0 
 
 
<External interrupt> 
                                                                            Register name. bit name 
Clearing of interrupt request flag 
EIRR.ER0 
 
 
<Interrupt Vector> 
    Setting of the vector table 
 
<Other> 
Note:   
Clock related settings and __set_il (number) setting are required to be 
performed in advance. See “CHAPTER: CLOCK” and ‘CHAPTER: 
INTERRUPT CONTROL (INTERRUPT CONTROLLER)”. 
Program Example 1 
 
void RTC_sample1(void) 
RTC_initial(); 
RTC_start(); 
EX_INT0_initial();
 
/* Subroutine for external interrupt setting*/ 
STOP_Hiz_hold_with_clock();
 
/* Subroutine for moving to the watch mode*/ 
RTC_read(); 

 
 
 
 
 
void RTC_initial(void) 
IO_WTCR.bit.ST = 1;   
/* Initialization preparation*/   
IO_WTCR.bit.ST = 0;
 
/* Stop (register initialization)*/ 
IO_WTBR.word = 0x0F423F;
 
/* Count value setting 4MHz/2 × 0x0F423F=0.5 second */ 
IO_WTSR.byte = 0x00;
 
/* Second setting */ 
IO_WTMR.byte = 0x0A;
 
/* Minute setting */ 
IO_WTHR.byte = 0x0A;   
/* Hour setting */ 
IO_WTDR.hword = 0x000A;   
/* Day setting */ 
IO_WTCRL.hword = IO_WTCRL.hword & 0x0000;   /* Interrupt flag clear, interrupt disable*/ 
IO_WTCRH.byte = 0x00 
/* Interrupt flag clear, interrupt disable*/ 

 
void RTC_start(void) 
IO_WTCR.bit.ST = 1;   
/* RTC startup*/ 
IO_ICR[21].bit.ICR = 18;    /* The value is arbitrary */ 
IO_ICR[00].bit.ICR = 20;    /* The value is arbitrary */ 
__EI(); 
/* Interrupt enable */ 

 
RTC_read(void) 
IO_WTCR.bit.INT0 = 0;   
/* RTC second interrupt request flag clear*/ 
IO_WTCR.bit.INTE0 = 1;    /* RTC second interrupt request enable */ 

 
__interrupt void RTC_read_int(void) /* RTC interrupt */ 
JIKAN(char) = IO_WTHR.byte & 0x1F;    /*Hour*/ 
FUNN(char) = IO_WTMR.byte & 0x3F;    /*Minute*/ 
BYOU(char) = IO_WTSR.byte & 0x3F;    /*Second*/ 
HI(char) = IO_WTDR.hword ;   
/*Day*/ 
 
/*Multiple reads*/ 
IO_WTCR.bit.INTE0 = 0;   
/* RTC interrupt disable */ 

 
__interrupt void INT0_int() /* External interrupt */ 
IO_EIRR0.bit.ER0= 0; /* ER0 second interrupt request flag clear*/ 
}
 
 
 
MB91520 Series
MN705-00010-1v0-E
1069