home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_12 / 8n12038a < prev    next >
Text File  |  1990-10-17  |  2KB  |  43 lines

  1.  
  2.  
  3.         /* delay for number of seconds requested */
  4.  
  5.         /* 2 MHz clock input                            */
  6.         /*      divided by 100  (countdown value)       */
  7.         /*      divided by 200  (prescaler value)       */
  8.         /*      divided by 100  (time value multiplier) */
  9.         /* yields counter in increments of one second ! */
  10.  
  11.  
  12. #include "mfp_defs.h"           /* MFP address definitions */
  13. #include "mfp_macs.h"           /* MFP macro definitions */
  14.  
  15. #define COUNTDOWN     100       /* countdown value */
  16. #define DIV_200         7       /* prescaler 200 indicator */
  17. #define TIME_MULT     100       /* input time multiplier */
  18. #define TIMER_B         0       /* timer B en/disable, bit 0 */
  19.  
  20.  
  21. delay(seconds)
  22. int seconds;
  23. {
  24.         extern long stimer;             /* global counter */
  25.  
  26.         stimer = (long)0;               /* zero the counter */
  27.  
  28.         REGVAL(TBDR) = COUNTDOWN;       /* init the down counter */
  29.         REGVAL(TBCR) = DIV_200;         /* prescaler div 200 */
  30.         BIT_SET(IERA,TIMER_B);          /* enable timer B interrupt */
  31.         seconds = seconds * TIME_MULT;  /* scale the time value */
  32.  
  33.                                         /* loop until time expired */
  34.         while (stimer < seconds)        /* (stimer is incremented by */
  35.                 ;                       /*    an interrupt handler) */
  36.  
  37.         BIT_CLR(IERA,TIMER_B);          /* disable timer B interrupt */
  38.         REGVAL(TBCR) = 0;               /* stop the timer */
  39. }
  40.  
  41.  
  42.  
  43.