Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

External Interrupt Issue

Status
Not open for further replies.

motif

Newbie level 4
Joined
Dec 4, 2011
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,362
Hi All,

I am trying to get my scan key-pad working using RB (interrupt on change) but did not get any success.

Then I reduced the code to test single switch using only two pins RB3 and RB0. Also using external interrupt on RB0 (to get rid of port B reading and other issues with change-on-interrupt).

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 the GIE and INTE bits (expecting if those are not getting set or getting overwritten somehow).

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


interrupt.png


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 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);
}
}
 
Last edited:

I do not use the CCS compiler so not sure of how it works, but you should not have to define the register addresses. They are defined in the 16LF727.h file?
Looking at the data sheet, the INTCON address is 0x0b, but you have defined it as 0x8.
Could this be the problem?
 

Sorry btbass, I was using INTCON = 0xB but while posting here I made typo of 0x8. Extremely sorry for that. The 16LF727 doesn't have all the registers,hence I defined the required ones. Do you suggest any better compiler that supports C with pic16 ?
 

A lot of people use CCS with no problems. I do not have CCS so cant try your code.
I prefer and use Hi-Tech which is a good compiler for Microchip Pic.

If you are using MPLAB, have you tried using Mplab Sim as the debugger without the hardware?
That will allow you to step through the code, and using the Watch window, you can see what is going on.
You can set the interrupt flag in software just before your while loop.
INTF = 1;

I have just noticed that you have the interrupt edge bit in the option register set to interrupt on the rising edge, this bit should be cleared ?
 
Last edited:

Thanks btbass, I was not aware of MPLAB simulator tool. It's cool :cool:

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

Yes, also tried un-setting edge bit, but it didn't help. If a button is pressed and released it should generate both edges.

I am clueless now :-(

Regards,
Sandy
 
Last edited:

Mplab Sim debugger is very good, if it works in Mplab Sim, it normally works on the hardware!

The next thing to do is to use a debugger on the hardware and step through the code. Put a breakpoint in the interrupt function.
What programmer/debugger are you using?

As all interrupts share the same vector, it is normal to write the interrupt like this so the correct interrupt can be serviced.
Code:
void interrupt isr(void)  /* your interrupt function name */
  { 
  if(INTF)
    {
	/* External RB0 Interrupt code */
    
    INTF = 0;
    }

  if(RBIF)
    {
	/* Port B Change Interrupt code */

    RBIF = 0;
    }

  if(T0IF)
    {
	/* Timer 0 overflow Interrupt code */

    T0IF = 0;
    }
  }

I know this wont fix your code but it's something you will need to do later.

output_bit(RED_LED, 0); Does this line set A7 as an output?
Thats why I'm not keen on CCS, I would rather know what all the registers have been set to.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top