Geekboy

delay

May 15th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. /*
  2. ####################################################################
  3. ########  MilliSecond Delay Library using the WatchDog Timer #######
  4. ####################################################################
  5.  
  6.  
  7. ####################################################################
  8.  
  9.  
  10. Requires the clock speed to be set at
  11. 8000khz with a divider of 8192
  12.  
  13. ####################################################################
  14.  
  15. */
  16.  
  17. #include <stdbool.h>
  18.  
  19. // initialize functions
  20. boolean InitTimer();
  21. void delay(int);
  22.  
  23. bool DeLaY;       // are we delaying?
  24. long int RunTime; // tabs on how long we have been runnning
  25. int DeLaYCT;      // delay counter
  26. void InitTimer()  
  27. {
  28.  
  29.   If(!(BCSCTL == CALBC1_8MHZ && DCOCTL == CALDCO_8MHZ)){
  30.     return false;
  31.   } // If not at 8mhz quit
  32.  
  33.   // now we set up the wdt
  34.   WDTCTL = WDTPW + WDTTMSEL + WDTIS0;
  35.  
  36.  
  37.   return true;
  38.   // succsess timer is setup
  39.  
  40. }
  41.  
  42. void delay(int DelayMS)
  43. {
  44.   If(DelayMS == 0){
  45.     return}else{
  46.   DeLaYCT = DelayMS;
  47.   }
  48.   while (DeLaY){}
  49.  
  50. }
  51.  
  52.  
  53.  
  54. #pragma vector=WDT_VECTOR
  55. __interrupt void WDT_ISR_HOOK(void)
  56. {
  57.  
  58.   If(DeLaY == true){
  59.    DeLaYCT--;
  60.   }
  61.   If(DeLaYCT = 0)
  62.     DeLaY = false;
  63.  
  64.   RunTime++;
  65.   // keep track of the amount of ms we have been running
  66.  
  67.  
  68. //add anything else we want done on a milisecond count here
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment