View previous topic :: View next topic |
Author |
Message |
charlestrep91
Joined: 13 Jun 2012 Posts: 2
|
Stuck in gpio interrupt |
Posted: Thu Jun 14, 2012 11:18 am |
|
|
Hi everyone,
I have this really simple code that won't work. I'm using a PIC16F1824 with MPLAB IDE 8.60 and CCS compiler v2.0.0.13. Basically when I press a push button on port A the blink delay should be set to 50ms by the interrupt and return to main and make the LED on PIN_C2 blink. Instead, it gets stuck in the interrupt and never go back to the main. I've tried to disable interrupts, clear INT_RA and the enable interrupts in the interrupt routine but the program still gets stuck there. For some reason, everything works fine if I use only one pin on port A and I enable INT_RA5 and clear it in the interrupt routine.
Thanks for your help!
Code: |
#include <16F1824.h>
#include <stdio.h>
#include <stdlib.h>
#use delay (internal=16000000)
#fuses noput,nowdt,noprotect,debug
int blink=200;
#INT_RA
RAinterrupt(void)
{
delay_ms(20);
blink=50;
}
void main()
{
enable_interrupts(global);
enable_interrupts(INT_RA);
ext_int_edge(H_TO_L);
while(1)
{
output_toggle(PIN_C2);
delay_ms(blink);
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Jun 14, 2012 11:27 am |
|
|
For any of the pin change interrupts, you _must_ read the pin/pins in the handler. This clears the hardware latch that is setting the interrupt. Unless this is done the interrupt will trigger for ever. It is in the chip's data sheet.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 14, 2012 1:00 pm |
|
|
On this series of PICs, it's the IOCAF register bits that have to be cleared
in the interrupt routine.
Quote: | CCS compiler v2.0.0.13
|
That's not the compiler version. That's what you see when you right-click
on the CCSC.exe icon and go Properties/Version.
The real version is given at the top of the .LST file in your project directory
after a successful compile. Or, open a Command Prompt window and
navigate to the c:\Program Files\Picc directory and run: CCSC +v
Example of version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo |
|
|
charlestrep91
Joined: 13 Jun 2012 Posts: 2
|
|
Posted: Thu Jun 14, 2012 2:53 pm |
|
|
@Ttelmah: I already tried that but it didn't solve the problem. Thanks for your reply!
@PCM programmer: Now I clear the IOCAF register and it works! I guess I'll write directly to the registers to clear interrupts from now on instead of using CCS functions. Thanks a lot for your help! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 14, 2012 3:55 pm |
|
|
CCS functions work fine. It's just that they don't have a function to clear
the IOCAF and IOCBF registers. In this particular case, it's necessary to
do it manually. |
|
|
|