View previous topic :: View next topic |
Author |
Message |
ch_dupre
Joined: 22 Aug 2006 Posts: 18
|
Interrupt on change constantly triggering. |
Posted: Thu Mar 08, 2007 10:05 am |
|
|
Hello,
I'm trying to detect a change on PIN_B4 but the interrupt is constantly triggering.
Can someone point out what I'm doing wrong?
Here is the code:
Code: |
#include <18F4550.h>
#device adc=10
#IF getenv("VERSION")>4.001
#device ANSI
#ENDIF
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL1 //No PLL PreScaler
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_D0,rcv=PIN_D1,bits=8, invert, STREAM=COM2)
void main(void)
{
set_tris_b(0b00010000);
//output_b(0x10) ;
enable_interrupts( INT_RB );
enable_interrupts( GLOBAL );
while (1)
;
}
#INT_RB
void PortBChange_isr( void )
{
set_tris_b(0x10);
input_b();
fprintf(COM2, "INTERRUPT\n");
}
|
I'm using V4.026.
Thanks for your help.
Christophe D. |
|
![](templates/subSilver/images/spacer.gif) |
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Thu Mar 08, 2007 10:22 am |
|
|
Try this way:
Code: |
int interrupt_RB;
#INT_RB
void PortBChange_isr( void )
{
input_b();
interrupt_RB = TRUE;
}
void main(void)
{
set_tris_b(0x10);
enable_interrupts( INT_RB );
enable_interrupts( GLOBAL );
while (1)
{
if( interrutp_RB )
{
fprintf(COM2, "INTERRUPT\n");
interrupt_RB = FALSE;
}
}
}
|
Humberto |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 08, 2007 10:35 am |
|
|
Quote: | #INT_RB
void PortBChange_isr( void )
{
set_tris_b(0x10);
input_b();
fprintf(COM2, "INTERRUPT\n");
} |
The input_b() function won't actually read the port unless you load
it into a variable. You can see this in the .LST file.
Declare a local variable in that function and do this:
Code: |
int8 c;
c = input_b();
|
|
|
![](templates/subSilver/images/spacer.gif) |
ch_dupre
Joined: 22 Aug 2006 Posts: 18
|
|
Posted: Thu Mar 08, 2007 10:37 am |
|
|
Thanks Humberto and PCM programmer. Both solutions work.
Christophe D. |
|
![](templates/subSilver/images/spacer.gif) |
|