|
|
View previous topic :: View next topic |
Author |
Message |
Py Guest
|
RB interrupts on PIC16F84A |
Posted: Tue May 04, 2004 9:35 am |
|
|
Hello,
I'm trying to get a very simple program to work: I have a bicolor led with its serail resistor connected between A2 and A3. I want to swap its color each time an rb intrrupt occurs. I tested the color swapping without interrupts using delay_ms(), and it works fine.
Now, I've added interrupts code, and led is in an unstable state, eg it swaps colors without any reason at any time, and don't when I want it to.
Here is the code:
Code: |
#include <16f84a.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay(clock=4000000)
SHORT INT flag = 0;
#int_rb
rb_isr()
{
if (flag) {
flag = 0;
}
else {
flag = 1;
}
}
void main()
{
//PORT_B_PULLUPS(TRUE);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RB);
while (TRUE) {
if (flag) {
output_high(PIN_A2);
output_low(PIN_A3);
}
else {
output_high(PIN_A3);
output_low(PIN_A2);
}
}
}
|
I tried with and without the "PORT_B_PULLUPS(TRUE);" line, and it didn't change much. My opinion is that I'm missing something about PORTB configuration for the use I want to make of it.
My testing circuitry is simple: apart the quartz, and the 2 27pF capacitors, I only have the bicolor led and it resistor between A2 and A3, and a jumper between B4 and the ground to simulate button actions.
Thanks in adavnce for any hint!
Pierre-Yves Paulus |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 04, 2004 11:22 am |
|
|
Quote: | My opinion is that I'm missing something about PORTB
configuration for the use I want to make of it. |
You need to clear the "mismatch" condition by reading Port B.
This is mentioned in Section 3.2 (i/o ports) of the 16F84A data sheet,
which you should read.
Example:
#byte port_b = 6
#int_rb
void int_rb_isr(void)
{
char c;
// Clear the mismatch condition by reading Port B.
c = port_b;
// Put the rest of your isr code here.
} |
|
|
|
|
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
|