home *** CD-ROM | disk | FTP | other *** search
- #include "hc05c8.h"
- #include "general.h"
-
- int hrs, mts, sec; /* global variables */
- long count=1000;
-
- struct bothbytes /* 16 bit int structure */
- {
- int hi;
- int lo;
- };
-
- union isboth /* and union */
- {
- long l;
- struct bothbytes b;
- };
-
- union isboth time_comp_count;
- registera ac;
-
- void main(void)
- {
- int key;
-
- TCR.OCIE = 1; /* enable output compare interrupt */
- CLI(); /* enable all interrupts */
-
- FOREVER
- {
- if(sec==60) /* do clock things each minute */
- {
- sec=0;
- if(++mts==60)
- {
- mts=0;
- if(++hrs==13)
- hrs=1;
- }
- }
- WAIT(); /* wait here to save the energy */
- }
- }
-
- void __TIMER(void) /* time interrupt service routine */
- {
- /* the program gets here every millisecond */
- time_comp_count.b.hi = TCHI;
- ac =TSR; /* Clear the tof bit */
- time_comp_count.b.lo = TCLO;
- time_comp_count.l += 500; /* 500 counts per millisecond */
- OCHI = time_comp_count.b.hi;
- ac = TSR; /* Clear ocf bit */
- OCLO = time_comp_count.b.lo;
-
- if(--count)
- return ;
- else
- {
- sec++; /* here every second */
- count=1000;/* reset count to 1 second */
- }
- }
-