Unable detect Interrupt on RB0 , 16F887
Discussion in "PIC Microcontroller Discussion" started by toinhatminh Dec 23, 2013.
Mon Dec 23 2013, 04:19 pm
Hi Pro,
I have a Exercise like this : Detect interrupt on RB0 by Press Button.
When button is pressed , the variable is increased , and output port E RE1, RE2, respectively.
The MCU doesn't work as requirement, please help me see the code and advice,
Thanks a lot,
Minh
I have a Exercise like this : Detect interrupt on RB0 by Press Button.
When button is pressed , the variable is increased , and output port E RE1, RE2, respectively.
The MCU doesn't work as requirement, please help me see the code and advice,
Thanks a lot,
Minh
#include <htc.h> // Interrupt on RB0,: __CONFIG(INTIO & WDTDIS & PWRTEN & MCLREN & UNPROTECT & DUNPROTECT & BORDIS & IESODIS & FCMDIS & LVPDIS); unsigned int press_count ; void main() { ANSEL = 0; ANSELH = 0; // Annalog unEnable. TRISB = 0xf1; //RB0 is Input. TRISE=0x00; // Set Port E is out Put RBPU = 0;//PORTB pull up enable. WPUB = 0x01;// RB0 is Weak Pull up. INTEDG = 0;// Edge down INTF = 0;// Clear Interrupt Flag INTE = 1;// Enable external interrupt GIE = 1;// Enable Global Interrupt while(1){ if(INTE && INTF){ void interrupt_isr();// When interrupt is detected on RBO, call fuction interrupt_isr() } } } void interrupt_isr() { press_count ++;// Increase the variable Press_count switch(press_count){ case 1: RE1 = 1;// depent on value of Press_count that MCU will out put on RE1 and RB2. RE2 = 0; break; case 2: RE1 = 0; RE2 = 1; break; case 3: RE1 = 1; RE2 = 1; break; default: RE1 = 0; RE2 = 0; press_count = 0; break; } }
Wed Dec 25 2013, 01:12 am
interrupts does not work this way
Your ISR will be called automatically when interrupt occurs. I think you need to first read about how interrupt works. Incase of PIC microcontroller, when interrupt occurs, CPU jumps from normal execution to ISR vector location and then executes from there. Here is a PPT that might help you get started:
Which compiler are you using for PIC?
while(1){ if(INTE && INTF){ void interrupt_isr();// When interrupt is detected on RBO, call fuction interrupt_isr() } }
Your ISR will be called automatically when interrupt occurs. I think you need to first read about how interrupt works. Incase of PIC microcontroller, when interrupt occurs, CPU jumps from normal execution to ISR vector location and then executes from there. Here is a PPT that might help you get started:
Which compiler are you using for PIC?
Powered by e107 Forum System