meche
Junior Member level 2
Can someone please help: I am new to interrupt programming and am using pic16f877a to try my hands on programming external interrupts. I have my push button connected to my RB0/int pin, a red LED connected to RB1 and blue LED connected to RB2. The interrupt doesn't work according to my design. I want the LED connected to RB2 to only come on and flash once the push button is pressed to initiate the interrupt. The other LED connected to RB1 should be flashing until the interrupt.
Instead the two LED's comes ON immediately the simulation is run and the LED on RB2 will only start to flash and behave according to design only after the push button is pressed.
I cant seem to find out why the LED on RB2 should turn ON immediately at the resumption of simulation.
Below is my code written with MPLAB XC8 and I am simulating with proteus.
Instead the two LED's comes ON immediately the simulation is run and the LED on RB2 will only start to flash and behave according to design only after the push button is pressed.
I cant seem to find out why the LED on RB2 should turn ON immediately at the resumption of simulation.
Below is my code written with MPLAB XC8 and I am simulating with proteus.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 main.c * Author: meche1 * * Created on May 4, 2017, 4:20 PM */ #define _XTAL_FREQ 8000000 #include "newxc8_header.h" #define LED1 PORTBbits.RB1 #define LED2 PORTBbits.RB2 #define LED1_TRIS TRISBbits.TRISB1 #define LED2_TRIS TRISBbits.TRISB2 void my_delay (int a) { for(int x =0; x<=a; x++ ) { __delay_ms(500); } } void interrupt isr (void) { INTCONbits.INTF = 0; for(int x=0; x<=10; x++) { LED2 = 1; __delay_ms(500); LED2 = 0; __delay_ms(500); } } void main(void) { LED1_TRIS = 0; LED2_TRIS = 0; INTCONbits.INTF = 0; OPTION_REGbits.INTEDG = 1; INTCONbits.GIE = 1; INTCONbits.INTE = 1; while(1) { LED1 = 1; my_delay(3); LED1 = 0; my_delay(3); } }