![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
ajshah23
Joined: 16 Jun 2006 Posts: 3
|
Need help with interrupts!! |
Posted: Thu Jul 13, 2006 7:41 pm |
|
|
These interrupts are becoming very frustrating! Can someone PLEASE help??
The function of the circuit is to display characters on an LCD when a pushbutton is pressed and held down, and to turn on an RFID reader antenna when the button is released. The reader and LCD work fine separately. Here is what I have so far, but only the display works :(
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;
// external interrupt when button pushed and released
#INT_EXT
void ext_isr() {
static short button_pressed=FALSE;
if(!button_pressed) // if button action and was not pressed
{
button_pressed=TRUE; // the button is now down
sleep_mode=TRUE; // activate sleep
//printf("The processor is now sleeping.\r\n");
ext_int_edge(L_TO_H); // change so interrupts on release
}
else // if button action and was pressed
{
button_pressed=FALSE; // the button is now up
sleep_mode=FALSE; // reset sleep flag
ext_int_edge(H_TO_L); // change so interrupts on press
}
if(!input(PIN_B0)) // keep button action sychronized wth button flag
button_pressed=TRUE;
delay_ms(100); // debounce button
}
int checkid();
void main() {
do{
int m;
int lcd_on;
int lcd_off;
int startaddr;
int milkaddr = 0001;
int breadaddr = 0002;
int juiceaddr = 0003;
int endaddr = 0003;
int freq = 0001;
//sleep_mode=TRUE;
ext_int_edge(H_TO_L); // init interrupt triggering for button press
enable_interrupts(INT_EXT);// turn on interrupts
enable_interrupts(GLOBAL);
set_tris_b(IRX_B_TRIS);
if(sleep_mode==FALSE){
while(sleep_mode==FALSE){
do{
m = checkid();//this will return an integer m
}while(m==0);
//LCD should be initialzed here to indicate that something was removed/replaced
if(m==1)
{
if(read_eeprom(milkaddr)==0001)
write_eeprom(milkaddr, 0000);
else
write_eeprom(milkaddr, freq);
}
else if(m==2)
{
if(read_eeprom(breadaddr)==0001)
write_eeprom(breadaddr, 0000);
else
write_eeprom(breadaddr, freq);
}
/*
{
delay_ms(300);
lcd_putc(" Bread ");
delay_ms(500);
lcd_putc('\f');
}
*/
else if(m==3)
{
if(read_eeprom(juiceaddr)==0001)
write_eeprom(juiceaddr, 0000);
else
write_eeprom(juiceaddr, freq);
}
}
}
else if(sleep_mode==TRUE){
lcd_init();
while(sleep_mode==TRUE){
//CODE
}
}
}while(TRUE);//end of huge do while loop right after main begins
} |
The check id funciton works fine, it is just the interrupts.
Can someone please look into this??? |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Jul 13, 2006 8:35 pm |
|
|
You shouldn't have this code in the do loop
Code: |
int m;
int lcd_on;
int lcd_off;
int startaddr;
int milkaddr = 0001;
int breadaddr = 0002;
int juiceaddr = 0003;
int endaddr = 0003;
int freq = 0001;
//sleep_mode=TRUE;
ext_int_edge(H_TO_L); // init interrupt triggering for button press
enable_interrupts(INT_EXT);// turn on interrupts
enable_interrupts(GLOBAL);
set_tris_b(IRX_B_TRIS); |
You should initialize this variable
short sleep_mode; |
|
![](templates/subSilver/images/spacer.gif) |
ajshah23
Joined: 16 Jun 2006 Posts: 3
|
Tried it |
Posted: Fri Jul 14, 2006 11:05 am |
|
|
Thank you Mark.
I tried what you said, but there was no change. The interrupt is not being called properly. Would it be a problem with disabling the interrupts??? |
|
![](templates/subSilver/images/spacer.gif) |
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Fri Jul 14, 2006 12:28 pm |
|
|
Probably not stopping your code from running but certainly not good in an interrupt. Don't call delay_ms() in your ISR. Ties up the entire processor doing nothing, including servicing future interrupt events. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|