Page 187 - Programming Microcontrollers in C
P. 187
172 Chapter 4 Small 8-Bit Systems
int count;
main(void)
{
count=0; /* start count at zero */
TCST.RT0=OFF; /* 57.3 ms cop timer */
TCST.RT1=OFF; /* 8.192 ms RTI */
TCST.RTIE=ON; /* Turn on the RTI */
TCST.RTIF=OFF; /* Reset interrupt */
TCST.TOF=ON; /* flags */
CLI(); /* turn on interrupt */
FOREVER
{
if(sec>MAX_SECONDS) /* do clock things */
{
sec=0;
if(++mts>MAX_MINUTES)
{
mts=0;
if(++hrs>MAX_HOURS)
hrs=1;
}
}
/* here is where any applications program should
be placed. */
}
}
void __TIMER(void) /* routine executed every
RTI (8.192 ms) */
{
TCST.RTIF=OFF; /* reset interrupt flag */
if (++count>MAX_COUNT)
{
sec++; /* increment seconds */
count=0;/* reset the count each second */
}
}
Listing 4-4: A Time-of-Day Program Based On The 15-bit Timer.