Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <xc.h>
- #include "config.h"
- void setup();
- void avansar_led();
- void retrocedir_led();
- void interrupt low_priority int_low()
- {
- if (INTCON3bits.INT2IF) {
- INTCON3bits.INT2IF = 0;
- retrocedir_led();
- }
- return;
- }
- void interrupt high_priority int_high()
- {
- if (INTCON3bits.INT1IF) {
- INTCON3bits.INT1IF = 0;
- avansar_led();
- }
- return;
- }
- void main(void)
- {
- setup();
- while (1) ;
- }
- void avansar_led()
- {
- if (PORTD == 0) {
- PORTD = 1;
- } else {
- PORTD <<= 1;
- }
- }
- void retrocedir_led()
- {
- if (PORTD == 0) {
- PORTD = 0x80;
- } else {
- PORTD >>= 1;
- }
- }
- void setup()
- {
- ADCON1 = 0x0F;
- TRISD = 0x00;
- TRISB = 0xFF;
- PORTD = 0;
- RCONbits.IPEN = 1;
- //Enable all unmasked interrupts
- //Enable all high-priority interrupts
- INTCON = 0b11001000;
- //Enable INT1 and INT2
- INTCON3 = 0b01011000;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement