|
|
View previous topic :: View next topic |
Author |
Message |
earroyo Guest
|
interrupt on change |
Posted: Mon Nov 26, 2001 10:39 pm |
|
|
Hi:
I'm getting frustrated..
I'm trying to use the interrupt on change feature in a PIC16f876
It just doesn't work..
for some reason the interruption gets activated ( even if there is no change ).
And after that the PIC is restarted.
I tried disable_interrupts(INT_RB), disable_interrupts(GLOBAL)
inside the interruption handler, but it still doesn't seem to work.
PIC16F876
CCS PCM C Compiler, Version 3.028,
This is the code:
The code is very simple.. All I'm doing is printing on Hyperterminal the value of an increasing integer "i"
If an interruption happens, The "flag" variable is increased by one. And it shoud be printed on hyperterminal, once it changed.
Thi is what happens:
i: 0 flag: 0
i: 1 flag: 0
i: 2 flag: 0
i: 0 flag: 0
i: 1 flag: 0
i: 2 flag: 0
The PIC is restarted when i = 2 for some reason.
The code is at the endof this message..
By the way, another question..
Should pins RB4-RB7 have a pull-up resistor??
Beacuse I tried and it didn't work
I would apreciate if anyone can help. I can not make any progress if I'm stuck in this part.
Thanks
/* #define DEBUG */
/* PREPROCESSOR STUFF */
#include <16F876.H>
#DEVICE ADC=10 // Returns a long 0-FFC0
#case
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
/* no watchdog timer, no code protect, yes power up timer */
#fuses XT, NOPROTECT, PUT, NOLVP
/* clk is 10MHz */
#use Delay(Clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) /
#define LED_1 PIN_C4
#bit ADFM_BIT = 0x9F.7 // This bit controls justification of the ADC result
static int flag;
#int_rb
rb_isr( ) {
disable_interrupts(INT_RB);
flag = flag + 1;
delay_ms(100);
enable_interrupts(INT_RB);
}
void test_LED();
test_LED() {
output_high(LED_1);
output_low(LED_1);
#IFNDEF DEBUG delay_ms(200);
#ENDIF
output_high(LED_1);
#IFNDEF DEBUG delay_ms(200);
#ENDIF
}
void my_delay(int time)
{
#IFNDEF DEBUG delay_ms(time);
#ENDIF
}
main()
{
long value;
float longV;
int i;
/* set direction of ports */
set_tris_a(0b00000000);
set_tris_b(0x11110000);
set_tris_c(0b00000000);
i =0;
flag = 0;
enable_interrupts(INT_RB);// turn on interrupts
enable_interrupts(GLOBAL);
do{
test_LED();
printf("hi.. ");
printf(" i: \%i flag: \%i\r\n",i,flag);
i++;
}while(1);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 1336 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: interrupt on change |
Posted: Tue Nov 27, 2001 1:01 am |
|
|
:=I'm getting frustrated..
:=I'm trying to use the interrupt on change feature in a PIC16f876
:=It just doesn't work..
:=for some reason the interruption gets activated ( even if there is no change ).
You have to clear the change condition by reading Port B.
Otherwise, you will keep getting the interrupt.
Here is some sample code. Look at the first 2 lines of
code in the int_rb isr. You need to add them to your isr.
<a href="http://www.pic-c.com/forum/general/posts/825.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/825.html</a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 1337 |
|
|
Frank Guest
|
Re: interrupt on change |
Posted: Tue Nov 27, 2001 6:54 am |
|
|
Is this a typo?
set_tris_b(0x11110000);
should it be 0xF0?
:=Hi:
:=
:=I'm getting frustrated..
:=I'm trying to use the interrupt on change feature in a PIC16f876
:=It just doesn't work..
:=for some reason the interruption gets activated ( even if there is no change ).
:=And after that the PIC is restarted.
:=
:=I tried disable_interrupts(INT_RB), disable_interrupts(GLOBAL)
:=inside the interruption handler, but it still doesn't seem to work.
:=
:=PIC16F876
:=CCS PCM C Compiler, Version 3.028,
:=
:=This is the code:
:=The code is very simple.. All I'm doing is printing on Hyperterminal the value of an increasing integer "i"
:=If an interruption happens, The "flag" variable is increased by one. And it shoud be printed on hyperterminal, once it changed.
:=
:=Thi is what happens:
:=i: 0 flag: 0
:=i: 1 flag: 0
:=i: 2 flag: 0
:=i: 0 flag: 0
:=i: 1 flag: 0
:=i: 2 flag: 0
:=
:=The PIC is restarted when i = 2 for some reason.
:=The code is at the endof this message..
:=
:=By the way, another question..
:=Should pins RB4-RB7 have a pull-up resistor??
:=Beacuse I tried and it didn't work
:=
:=I would apreciate if anyone can help. I can not make any progress if I'm stuck in this part.
:=
:=Thanks
:=
:=
:=/* #define DEBUG */
:=
:=/* PREPROCESSOR STUFF */
:=#include <16F876.H>
:=#DEVICE ADC=10 // Returns a long 0-FFC0
:=#case
:=#use fast_io(A)
:=#use fast_io(B)
:=#use fast_io(C)
:=
:=
:=/* no watchdog timer, no code protect, yes power up timer */
:=#fuses XT, NOPROTECT, PUT, NOLVP
:=/* clk is 10MHz */
:=#use Delay(Clock=10000000)
:=#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) /
:=
:=#define LED_1 PIN_C4
:=#bit ADFM_BIT = 0x9F.7 // This bit controls justification of the ADC result
:=
:=static int flag;
:=#int_rb
:=rb_isr( ) {
:= disable_interrupts(INT_RB);
:= flag = flag + 1;
:= delay_ms(100);
:= enable_interrupts(INT_RB);
:=}
:=
:=
:=void test_LED();
:=
:=test_LED() {
:= output_high(LED_1);
:= output_low(LED_1);
:=#IFNDEF DEBUG delay_ms(200);
:=#ENDIF
:= output_high(LED_1);
:=#IFNDEF DEBUG delay_ms(200);
:=#ENDIF
:=}
:=
:=void my_delay(int time)
:={
:=#IFNDEF DEBUG delay_ms(time);
:=#ENDIF
:=}
:=
:=
:=main()
:={
:=
:= long value;
:= float longV;
:= int i;
:=
:= /* set direction of ports */
:= set_tris_a(0b00000000);
:= set_tris_b(0x11110000);
:= set_tris_c(0b00000000);
:=
:=i =0;
:=flag = 0;
:=
:= enable_interrupts(INT_RB);// turn on interrupts
:= enable_interrupts(GLOBAL);
:= do{
:= test_LED();
:= printf("hi.. ");
:= printf(" i: \%i flag: \%i\r\n",i,flag);
:= i++;
:= }while(1);
:=
:=}
:=
:=
:=
:=
:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 1338 |
|
|
Felix Althaus
Joined: 09 Sep 2003 Posts: 67 Location: Winterthur, Switzerland
|
Re: interrupt on change |
Posted: Tue Nov 27, 2001 3:29 pm |
|
|
Hi
I do something like PCM programmer, but in assembly:
#int_rb
isr()
{
#asm
movf 6, 1 // This line reloads PortB
#endasm
do_something();
}
It works fine.
I read this in the Microchip Application Note AN566. I would recommend it, but it is in assembly code.
mfg
Felix
___________________________
This message was ported from CCS's old forum
Original Post ID: 1347 |
|
|
|
|
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
|