AdamkT1
Joined: 21 Apr 2007 Posts: 44
|
Interrupt by RB0 |
Posted: Thu Jul 12, 2007 7:17 am |
|
|
I am having problem in dealing with the interrupt.
I wish to activate an interrupt on a switch press. This seemingly easy task has consumed my 0NE whole day and I am still no where.
The code is:
Code: | #include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
int8 INT0_Flg;
#INT_EXT
void ext_RB0()
{
INT0_Flg=0x01; // Turn the flag on to go for receiving the LAT/LON
}
void main()
{
SET_TRIS_B(0x01); // Direction of pin as input.
INT0_Flg=0;
enable_interrupts(INT_EXT);// turn on interrupts on RB0
enable_interrupts(GLOBAL); // turn on global interrupts
delay_ms(500); //let the system to stabilize
while (TRUE)
{
IF (PORTB==1)
PORTB=0xff;
else
PORTB=0;
delay_ms(200);
if (INT0_Flg)
{
IF (PORTA==0)
PORTA=0xff;
else
PORTA=0;
delay_ms(200);
}//end if
}//end while
} |
I have hardwired Pin_B0 to ground using a 10K resistor (normally off position) and am using a Normally open switch to connect the Pin to VCC.
The problem is that at the program start, there is no activity on any of the ports(A or B) but for as long as the switch is closed, the PortB keeps on flashing with no activity on PortA.
The program seems to get stuck some where (may be in the ISR).
. |
|