Advertisement
Guest User

interrupts.c

a guest
Mar 11th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.66 KB | None | 0 0
  1. /******************************************************************************/
  2. /*Files to Include                                                            */
  3. /******************************************************************************/
  4.  
  5. #if defined(__XC)
  6.     #include <xc.h>         /* XC8 General Include File */
  7. #elif defined(HI_TECH_C)
  8.     #include <htc.h>        /* HiTech General Include File */
  9. #endif
  10.  
  11. #include <stdint.h>         /* For uint8_t definition */
  12. #include <stdbool.h>        /* For true/false definition */
  13.  
  14. #include "globals.h"
  15. #include "delay.h"
  16.  
  17. /******************************************************************************/
  18. /* Interrupt Routines                                                         */
  19. /******************************************************************************/
  20.  
  21. /* Baseline devices don't have interrupts. Note that some PIC16's
  22.  * are baseline devices.  Unfortunately the baseline detection macro is
  23.  * _PIC12 */
  24. #ifndef _PIC12
  25.  
  26. void interrupt isr(void)
  27. {
  28.     //if it's the AD interrupt
  29.     if(ADIF==1)
  30.     {
  31.         //delay for some number of NOPs
  32.         do_delay((ADRESH << 8) + ADRESL);
  33.  
  34.         //reset AD int flag
  35.         ADIF = 0;
  36.  
  37.         //
  38.         GO_DONE = 0;
  39.     }
  40. }
  41. #endif
  42.  
  43. void do_delay(unsigned short int AVAL)
  44. {
  45.         //iterate between 0 and 1023 times
  46.         for(unsigned short int i=0; i<AVAL; i++)
  47.         {
  48.             asm("NOP");
  49.         }
  50.  
  51.         //toggle portb (make square wave)
  52.         if(RB0==0)
  53.         {
  54.             RB0=1; //ternary operator
  55.             RB1=1;
  56.         }
  57.         else
  58.         {
  59.             RB0=0;
  60.             RB1=0;
  61.         }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement