home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 08 / vansick / listing4.asc < prev    next >
Text File  |  1990-11-10  |  1KB  |  64 lines

  1. #include "hc05c8.h"
  2. #include "general.h"
  3.  
  4. int hrs, mts, sec;       /* global variables   */
  5. long count=1000;
  6.  
  7. struct bothbytes         /* 16 bit int structure  */
  8. {
  9.       int hi;
  10.       int lo;
  11. };
  12.  
  13. union isboth              /* and union  */
  14. {
  15.       long  l;
  16.       struct bothbytes b;
  17. };
  18.  
  19. union isboth time_comp_count;
  20. registera ac;
  21.  
  22. void main(void)
  23. {
  24.     int key;
  25.  
  26.     TCR.OCIE = 1; /* enable output compare interrupt */
  27.     CLI();   /* enable all interrupts  */
  28.  
  29.     FOREVER
  30.     {
  31.         if(sec==60)  /* do clock things each minute  */
  32.         {
  33.             sec=0;
  34.             if(++mts==60)
  35.             {
  36.                 mts=0;
  37.                 if(++hrs==13)
  38.                     hrs=1;
  39.             }
  40.         }
  41.         WAIT();   /* wait here to save the energy  */
  42.     }
  43. }
  44.  
  45. void __TIMER(void)   /* time interrupt service routine  */
  46. {
  47.      /* the program gets here every millisecond  */
  48.      time_comp_count.b.hi = TCHI;
  49.      ac =TSR;           /* Clear the tof bit  */
  50.      time_comp_count.b.lo = TCLO;
  51.      time_comp_count.l += 500;  /* 500 counts per millisecond */
  52.      OCHI = time_comp_count.b.hi;
  53.      ac = TSR;           /* Clear ocf bit    */
  54.      OCLO = time_comp_count.b.lo;
  55.  
  56.      if(--count)
  57.          return ;
  58.     else
  59.     {
  60.          sec++;    /* here every second  */
  61.          count=1000;/* reset count to 1 second */
  62.     }
  63. }
  64.