Page 202 - Programming Microcontrollers in C
P. 202
Timers 187
union both /* and union */
{
long l;
struct bothbytes b;
};
union both time_count;
registera ac;
main()
{
TCR.OCIE=1; /* enable output compare interrupt */
CLI(); /* enable all interrupts */
FOREVER
{
if(sec>59) /* do clock things each minute */
{
sec=0;
if(++mts>59)
{
mts=0;
if(++hrs>12)
hrs=1;
}
}
WAIT();
}
}
void __TIMER_OC(void) /* time interrupt service
routine */
{
if(TSR.OCF2==1) /* is this interrupt due to OC2?*/
{
ac=OCLO2; /* Yes. read OCLO2 to disable */
return; /* the interrupt and exit */
} /* the routine */