|
|
View previous topic :: View next topic |
Author |
Message |
newb
Joined: 28 Sep 2007 Posts: 1
|
interrupts 16f877a |
Posted: Fri Sep 28, 2007 11:40 am |
|
|
hai.. i'm newb... i have problem regarding with interrupts... here are my coding...after compilation, there is a warning "interrupts disabled during call to prevent re-entrancy. [timed_getc]" how should i do to solve this problem??
#include <16F877A.h> //Depends on the PIC you're using
#USE DELAY( CLOCK=20000000 )
#use rs232(baud=38400,xmit=PIN_C6,rcv=PIN_C7) /* for Square Box */
#FUSES HS,NOWDT,NOPROTECT,NOPUT,NOLVP
#use standard_io(D)
#byte PORT_B=6
#INT_EXT
char timed_getc() {
static short timeout_error=FALSE;
long timeout;
//timeout_error=FALSE;
timeout=0;
while(!kbhit()&&(++timeout<500)) // 1/2 second
delay_us(5);
if(kbhit())
return(getc());
else {
timeout_error=TRUE;
return(0);
}
}
void main()
{
char answer;
long counter;
enable_interrupts(GLOBAL); //Turn on interrupts
enable_interrupts(INT_EXT); //Enable INT_EXT
set_tris_b(0); /* set port_b to be outputs */
port_b = 0; /* initialize All port_b outp/uts to be zero */
printf("Welcome to World of Smart Home\n\r");
printf("-------------------------------\n\r");
DELAY_MS (500);
counter=0;
while(TRUE){
//bulb lights up
answer=timed_getc();
printf("Which window would you like to be light up (A,B,C) ?");
if (answer == 'A')
port_b |= 0x80;
printf("Window %c is lit up\n", answer);
if (answer == 'B')
port_b |= 0x40;
printf("Window %c is lit up\n", answer);
if (answer == 'C')
port_b |= 0x20;
printf("Window %c is lit up\n", answer);
DELAY_MS (500);
}
}
hope eveybody can help me overcome this problem...tq |
|
|
Ttelmah Guest
|
|
Posted: Fri Sep 28, 2007 11:48 am |
|
|
There are techniques to avoid the error, but you have it, because you are not using the interrupt properly. The interrupt routine itself, _must not, and cannot be called from anywhere except by the hardware interrupt event_. You cannot use the 'timed_getc' event as the interrupt handler routine, and then also use it in the main code. If you want to trigger a timed_getc, when an external line changes, then have a flag set in the interrupt, and call the routine in the main, when this happens. However in the code as shown, thre is no reason at all, to enable interrupts, or declare an interrupt handler at all!...
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 28, 2007 11:48 am |
|
|
Why are you using the External interrupt ? |
|
|
|
|
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
|