ajshah23
Joined: 16 Jun 2006 Posts: 3
|
External interrupt on PIN_B0 |
Posted: Tue Jul 11, 2006 3:59 pm |
|
|
I am trying to use a simple pushbutton switch to toggle between two modes, one is to display to the LCD, and the other is to use an RFID reader. Both work perfectly even together, but when I try to use an external interrupt, the PIC only responds when the button is pressed from high to low. There is a clean signal from the button and I have used a delay function to account for the debouncing. The complete interrupt does not work. Can someone please help me?
Code: |
#include <16F877>
#fuses HS,NOWDT,NOPROTECT,NOLVP, NOBROWNOUT
#use delay(clock=20000000)
#USE RS232(BAUD=9600, XMIT=PIN_C6,RCV=PIN_C7, bits=8, PARITY=N)
#include <lcd>
#include <input>
#rom 0x2100={1,2,3,4}
//#use fast_io(B)
//#define IRX_B_TRIS 0b10000010
//#define DOOR_BUTTON PIN_B0
//#byte PORTD = 8
//#define ALL_OUT 0
// global flag to send processor into sleep mode
short sleep_mode;
short lcdon;
//char got_interrupt;
#bit INTF_BIT = 0x0B.1
// external interrupt when button pushed and released
#INT_EXT
void ext_isr() {
if(lcdon){
sleep_mode=TRUE;
disable_interrupts(INT_EXT);
ext_int_edge(H_TO_L);
}
else if(!lcdon){
sleep_mode=FALSE;
disable_interrupts(INT_EXT);
ext_int_edge(L_TO_H);
}
}
int checkid();
void main() {
output_float(PIN_B0);
// Enable pullups on all port B pins.
port_b_pullups(TRUE);
// Wait for them to pull up.
delay_us(10);
lcdon=TRUE;
ext_int_edge(L_TO_H); // init interrupt triggering for button press
INTF_BIT = 0;
enable_interrupts(INT_EXT);// turn on interrupts
enable_interrupts(GLOBAL);
do{
int m;
int startaddr;
int milkaddr = 0001;
int breadaddr = 0002;
int juiceaddr = 0003;
int endaddr = 0003;
int freq = 0001;
//sleep_mode=TRUE;
set_tris_b(IRX_B_TRIS);//QUESTIONABLE!!!!!!!!
if(sleep_mode==FALSE){
lcdon=TRUE;
delay_ms(50);
INTF_BIT = 0;
enable_interrupts(INT_EXT);
while(sleep_mode==FALSE){
**CODE**
}
}
else if(sleep_mode==TRUE){
lcdon=FALSE;
delay_ms(50);
INTF_BIT = 0;
enable_interrupts(INT_EXT);
lcd_init();
while(sleep_mode==TRUE){
delay_ms(500);
lcd_putc(" Need to Buy: ");
delay_ms(500);
lcd_putc('\f');
for(startaddr=0001;startaddr<endaddr+1;startaddr++){
**CODE**
}
delay_ms(1000);
}
}while(TRUE);//end of huge do while loop right after main begins
} |
|
|