|
|
View previous topic :: View next topic |
Author |
Message |
electronx.x.2
Joined: 25 Nov 2011 Posts: 17 Location: Pakistan
|
Problem in INT_RB |
Posted: Mon Dec 05, 2011 12:30 am |
|
|
Hello, I just want to use ext_int to do increment, in 7 segment, which is done very easily. The main problem is I want to do decrements in my 7 segment display by using #int_RB, but it is hanging and not working. Below is my code:
Code: |
#include <main.h>
int a=0,b=0;
byte const display_map[10]={0x90,0xb7,0x19,0x15,0x36,0x54,0x50,0xb5,0,0x24};
void pwm_map();
void display_led();
#define seg_1 PIN_b1
#define seg_2 PIN_b2
#int_RB
void RB_isr(void)
{
a--;
if (a<=0){a=0;b--;}
if (b<=0){b=0;a=0;}
}
#int_EXT
void EXT_isr(void)
{
a++;
if (a>9){a=0;b++;}
if (b>9){b=9;a=9;}
}
void main()
{
setup_timer_2(T2_DIV_BY_4,249,1); //200 us overflow, 200 us interrupt
setup_ccp1(CCP_off);
set_pwm1_duty(102);
setup_comparator(NC_NC_NC_NC);
enable_interrupts(INT_RTCC);
enable_interrupts(INT_RB);
enable_interrupts(INT_EXT_h2l);
enable_interrupts(GLOBAL);
while(true)
{
output_d(display_map[a]);
output_high(seg_1);
delay_us(100);
output_low(seg_1);
output_d(display_map[b]);
output_high(seg_2);
delay_us(100);
output_low(seg_2);
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Mon Dec 05, 2011 3:00 am |
|
|
Key thing. The RB interrupt routine, _must_, repeat _must_ read port B.
There is an internal latch, which contains a copy of the bits used for the interrupt, which is set whenever you read the port. The interrupt triggers when this latch differs from what is on the pins. You can't 'clear' the interrupt, till the latch once again matches the input bits, so you must read the port to reset the latch, before you exit the interrupt routine, or it'll trigger for ever.....
Also as posted, the code will hang, since there isn't a handler for the RTCC interrupt. You must never enable an interrupt, without a handler.
Best Wishes |
|
|
electronx.x.2
Joined: 25 Nov 2011 Posts: 17 Location: Pakistan
|
|
Posted: Mon Dec 05, 2011 3:10 am |
|
|
Thnx i got the key,,., |
|
|
electronx.x.2
Joined: 25 Nov 2011 Posts: 17 Location: Pakistan
|
|
Posted: Mon Dec 05, 2011 3:45 am |
|
|
I just want to use INT_RB to interrupt, on -ve voltage, but i cant. When i use push to press, it interrupt and do increment in my required variable. But when i release push button, it again interrupts and do increment.
How can i get rid of this sec interrupt, which automatically happen.
help. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Mon Dec 05, 2011 4:58 am |
|
|
It will.
INT_RB, is an _interrupt on change_. Read the data sheet....
You would just have to program round it. Hold a copy of the bit(s) you want in a _static_ variable, and test which ones have fallen since the last read. Then for these, execute your code. Then update the copy, and exit the routine.
Examples of how to do this have been posted here in the past.
Best Wishes |
|
|
electronx.x.2
Joined: 25 Nov 2011 Posts: 17 Location: Pakistan
|
|
Posted: Mon Dec 05, 2011 5:02 am |
|
|
link please. |
|
|
electronx.x.2
Joined: 25 Nov 2011 Posts: 17 Location: Pakistan
|
|
Posted: Fri Dec 09, 2011 4:37 am |
|
|
thnx , the program is runnig, thnx |
|
|
|
|
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
|