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 >
Wrap
Text File
|
1990-10-17
|
2KB
|
43 lines
/* delay for number of seconds requested */
/* 2 MHz clock input */
/* divided by 100 (countdown value) */
/* divided by 200 (prescaler value) */
/* divided by 100 (time value multiplier) */
/* yields counter in increments of one second ! */
#include "mfp_defs.h" /* MFP address definitions */
#include "mfp_macs.h" /* MFP macro definitions */
#define COUNTDOWN 100 /* countdown value */
#define DIV_200 7 /* prescaler 200 indicator */
#define TIME_MULT 100 /* input time multiplier */
#define TIMER_B 0 /* timer B en/disable, bit 0 */
delay(seconds)
int seconds;
{
extern long stimer; /* global counter */
stimer = (long)0; /* zero the counter */
REGVAL(TBDR) = COUNTDOWN; /* init the down counter */
REGVAL(TBCR) = DIV_200; /* prescaler div 200 */
BIT_SET(IERA,TIMER_B); /* enable timer B interrupt */
seconds = seconds * TIME_MULT; /* scale the time value */
/* loop until time expired */
while (stimer < seconds) /* (stimer is incremented by */
; /* an interrupt handler) */
BIT_CLR(IERA,TIMER_B); /* disable timer B interrupt */
REGVAL(TBCR) = 0; /* stop the timer */
}