• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

External Interrupt Issue

Status
Not open for further replies.

motif

New Member
Hi All,

I am trying to get single switch of my key-pad working, but not getting any success.

The single test-switch uses pins RB3 and RB0 and an external interrupt on RB0. RB3 is output and RB0 is input.

When I push the test-switch, the INTF flag in INTCON register is getting set, but some how the ISR is not getting called. Number of times I have checked whole code and the GIE and INTE bits but not getting any clue.

Also checked that RB0 value changes when switch is pressed.

Attached is reduced code and schematic..

Kindly suggest any direction to trouble-shoot this issue..

Here are more details..
Vcc : 3.30 V
micro-controller : PIC 16LF727
clock : Internal oscillator.
compiler : CCS C version is V4.0

Thanks,
Sandy


Code:
#include <16LF727.h>

#FUSES NOWDT                 	//No Watch Dog Timer
#FUSES INTRC_IO              	//Internal RC Osc, no CLKOUT
#FUSES NOPUT                 	//No Power Up Timer
#FUSES NOPROTECT             	//Code not protected from reading
#FUSES NOBROWNOUT            	//No brownout reset
          
#define delay_val 5          
#use delay(clock=8000000)


#define mydelay1 5
#byte ANSELA = 0x185
#byte ANSELB = 0x186
#byte TRISB  = 0x86
#byte IOCB   = 0x96
#byte WPUB   = 0x95
#byte INTCON = 0xB
#byte T2CON  = 0x12
#byte PortB  = 0x06
#byte OPTION_REGISTER = 0x181

//### Debug LEDs
#define GREEN_LED PIN_A6
#define RED_LED   PIN_A7

//### ISR method
#int_ext
void int_ext_isr(void)
{
//### glow red led to check if isr executed.
output_bit(RED_LED, 0);
INTCON = 0b10010000;
}


void main()
{
// ### turn off debug LEDs
output_bit (GREEN_LED, 1);
output_bit (RED_LED, 1);

//### Port A Digital-IO
ANSELA = 0x00;

//### Port B Digital-IO
ANSELB = 0x00;

//### port B input/output configuration, port B3 output, rest input.
TRISB = 0b11110111;

//### option register, Week pull up enabled
OPTION_REGISTER = 0b01111111;

//### weak pull-up for RB0 enabled
WPUB =  0b00000001;

//### Drive B3 to low
output_bit(PIN_B3,0);

//### interrupt control, set Global GIE and INTE
INTCON = 0b10010000;

delay_ms(50);


while(1)
{
output_bit (GREEN_LED, 0);
delay_ms(500);
} 

} //main ends
 

Attachments

Last edited:

ericgibbs

Well-Known Member
Most Helpful Member
him
Your INTCON bits appear to be incorrect, no INTR on B change.
 

motif

New Member
Initially I was trying get all keys working with INTERRUPT-ON-CNAHGE, but when that did not work, I reduced the scope of debug to 1 switch and the external interrupt on RB0.

With one switch, I have checked that INTF flag is getting set properly when switch is pressed, but ISR is not getting called.

when GIE, INTE are set and INTF is also getting set, what else might be gating ISR call?

I am not getting any idea what I have missed

Regards,
Sandy
 

georgetwo

Member
void int_ext_isr(void)
{
//### glow red led to check if isr executed.
output_bit(RED_LED, 0); INTCON = 0b10010000;
}

i think , for you to be able to see the interrupt it would be better to involve a little delay inside the interrupt routine. And clearing the flag should be done by clearing the interrupt flag bit only. If you have a simulator, test the code on it and see if you are not running into stack overflow.
 

ericgibbs

Well-Known Member
Most Helpful Member
Initially I was trying get all keys working with INTERRUPT-ON-CNAHGE, but when that did not work, I reduced the scope of debug to 1 switch and the external interrupt on RB0.

With one switch, I have checked that INTF flag is getting set properly when switch is pressed, but ISR is not getting called.

when GIE, INTE are set and INTF is also getting set, what else might be gating ISR call?

I am not getting any idea what I have missed

Regards,
Sandy
hi,
I dont use C, but it appears you have not Set this bit.

Look at this clip from the d/s.
You have
INTCON = 0b10010000

Should it be:
INTCON = 0b10011000
 

Attachments

motif

New Member
Sorry ericgibbs if my post was not clear and has introduced confusion, I have modified the original post #1.
 

ericgibbs

Well-Known Member
Most Helpful Member
Sorry ericgibbs if my post was not clear and has introduced confusion, I have modified the original post #1.
I see your edit and if I understand correctly, you want RB0 to Interrupt.??
 
Last edited:

motif

New Member
I see your edit and if I understand correctly, you want RB0 to Interrupt.??
Yes, correct!

I just tried my code with MPLAB simulator and found ISR is called as I set INTF flag.

Regards,
Sandy
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top