Advertisement
xerpi

prac6

Nov 3rd, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <xc.h>
  2. #include "config.h"
  3.  
  4. void setup();
  5. void avansar_led();
  6. void retrocedir_led();
  7.  
  8.  
  9. void interrupt low_priority int_low()
  10. {
  11.     if (INTCON3bits.INT2IF) {
  12.         INTCON3bits.INT2IF = 0;
  13.         retrocedir_led();
  14.     }
  15.     return;
  16. }
  17.  
  18. void interrupt high_priority int_high()
  19. {
  20.     if (INTCON3bits.INT1IF) {
  21.         INTCON3bits.INT1IF = 0;
  22.         avansar_led();
  23.     }
  24.     return;
  25. }
  26.  
  27.  
  28. void main(void)
  29. {
  30.     setup();
  31.     while (1) ;
  32. }
  33.  
  34. void avansar_led()
  35. {
  36.     if (PORTD == 0) {
  37.         PORTD = 1;
  38.     } else {
  39.         PORTD <<= 1;
  40.     }
  41. }
  42.  
  43. void retrocedir_led()
  44. {
  45.     if (PORTD == 0) {
  46.         PORTD = 0x80;
  47.     } else {
  48.         PORTD >>= 1;
  49.     }
  50. }
  51.  
  52. void setup()
  53. {
  54.     ADCON1 = 0x0F;
  55.     TRISD = 0x00;
  56.     TRISB = 0xFF;
  57.     PORTD = 0;
  58.     RCONbits.IPEN = 1;
  59.     //Enable all unmasked interrupts
  60.     //Enable all high-priority interrupts
  61.     INTCON = 0b11001000;
  62.     //Enable INT1 and INT2
  63.     INTCON3 = 0b01011000;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement