Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ####################################################################
- ######## MilliSecond Delay Library using the WatchDog Timer #######
- ####################################################################
- ####################################################################
- Requires the clock speed to be set at
- 8000khz with a divider of 8192
- ####################################################################
- */
- #include <stdbool.h>
- // initialize functions
- boolean InitTimer();
- void delay(int);
- bool DeLaY; // are we delaying?
- long int RunTime; // tabs on how long we have been runnning
- int DeLaYCT; // delay counter
- void InitTimer()
- {
- If(!(BCSCTL == CALBC1_8MHZ && DCOCTL == CALDCO_8MHZ)){
- return false;
- } // If not at 8mhz quit
- // now we set up the wdt
- WDTCTL = WDTPW + WDTTMSEL + WDTIS0;
- return true;
- // succsess timer is setup
- }
- void delay(int DelayMS)
- {
- If(DelayMS == 0){
- return}else{
- DeLaYCT = DelayMS;
- }
- while (DeLaY){}
- }
- #pragma vector=WDT_VECTOR
- __interrupt void WDT_ISR_HOOK(void)
- {
- If(DeLaY == true){
- DeLaYCT--;
- }
- If(DeLaYCT = 0)
- DeLaY = false;
- RunTime++;
- // keep track of the amount of ms we have been running
- //add anything else we want done on a milisecond count here
- }
Advertisement
Add Comment
Please, Sign In to add comment