View previous topic :: View next topic |
Author |
Message |
fredgilman Guest
|
PIC hangs when enabling global interrupts |
Posted: Thu Jul 10, 2008 9:27 pm |
|
|
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
|
|
Posted: Thu Jul 10, 2008 10:55 pm |
|
|
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
|
|
Posted: Fri Jul 11, 2008 12:12 pm |
|
|
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! |
|
|
|