CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Stuck in gpio interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
charlestrep91



Joined: 13 Jun 2012
Posts: 2

View user's profile Send private message

Stuck in gpio interrupt
PostPosted: Thu Jun 14, 2012 11:18 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 14, 2012 11:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 14, 2012 1:00 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 14, 2012 2:53 pm     Reply with quote

@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

View user's profile Send private message

PostPosted: Thu Jun 14, 2012 3:55 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group