Continue to Site

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.

  • 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

  • interrupt.png
    interrupt.png
    26.9 KB · Views: 164
Last edited:
him
Your INTCON bits appear to be incorrect, no INTR on B change.
 
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
 
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.
 
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

  • AAesp01.gif
    AAesp01.gif
    30.4 KB · Views: 200
Sorry ericgibbs if my post was not clear and has introduced confusion, I have modified the original post #1.
 
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:
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.

Latest threads

New Articles From Microcontroller Tips

Back
Top