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 support@ccsinfo.com

PIC hangs when enabling global interrupts

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







PIC hangs when enabling global interrupts
PostPosted: Thu Jul 10, 2008 9:27 pm     Reply with quote

Hi all,

I'm in the processing of learning CCS C on a PIC16F688 and just started to play around with interrupts. I started out with a simple test, but for some reason the pic hangs when processing the enable_interrupts(GLOBAL) command. I've determined this by making an led flash after each command, and it always stops when it gets to that line. Here's a somewhat barebones test I tried:

Code:

#include <16F688.h>
#FUSES NOWDT, INTRC_IO, NOPROTECT, NOMCLR
#use delay(clock=4000000)

#define led  PIN_C2
int changed=0;

#int_RA
void  RA_isr()
{
   changed=1;
   clear_interrupt(int_RA);  //Added incase the interrupt was constantly enabled
}

void main()
{
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RA);
   output_high(led);   //flash an LED once the interrupts are enabled
   delay_ms(100);
   output_low(led);

   while (1){
      if (changed){    //The interrupt's been triggered!
         output_high(led);
         delay_ms(300);
         output_low(led);
      }
   }
}


Any suggestions on what I'm doing wrong?

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 10, 2008 10:55 pm     Reply with quote

Read the 16F688 data sheet. It tells you what to do.
Quote:
4.2.3 INTERRUPT-ON-CHANGE

The user, in the Interrupt Service Routine, clears
the interrupt by:
a) Any read or write of PORTA. This will end the
mismatch condition, then
b) Clear the flag bit RAIF.

A mismatch condition will continue to set flag bit RAIF.
Reading PORTA will end the mismatch condition and
allow flag bit RAIF to be cleared.

Note that the compiler inserts code to do item (b).
You don't have to do it.
fredgilman
Guest







PostPosted: Fri Jul 11, 2008 12:12 pm     Reply with quote

PCM programmer wrote:

Note that the compiler inserts code to do item (b).
You don't have to do it.


Ah ha! Reading the pin in the interrupt function worked! I had read the datasheet before, but it never occurred to me that item (a) was the culprit, as the problem seemed to be with another command. Thanks!
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