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 CCS Technical Support

Problem in INT_RB

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
electronx.x.2



Joined: 25 Nov 2011
Posts: 17
Location: Pakistan

View user's profile Send private message AIM Address MSN Messenger

Problem in INT_RB
PostPosted: Mon Dec 05, 2011 12:30 am     Reply with quote

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: 19496

View user's profile Send private message

PostPosted: Mon Dec 05, 2011 3:00 am     Reply with quote

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

View user's profile Send private message AIM Address MSN Messenger

PostPosted: Mon Dec 05, 2011 3:10 am     Reply with quote

Thnx i got the key,,., Very Happy
electronx.x.2



Joined: 25 Nov 2011
Posts: 17
Location: Pakistan

View user's profile Send private message AIM Address MSN Messenger

PostPosted: Mon Dec 05, 2011 3:45 am     Reply with quote

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: 19496

View user's profile Send private message

PostPosted: Mon Dec 05, 2011 4:58 am     Reply with quote

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

View user's profile Send private message AIM Address MSN Messenger

PostPosted: Mon Dec 05, 2011 5:02 am     Reply with quote

link please.
electronx.x.2



Joined: 25 Nov 2011
Posts: 17
Location: Pakistan

View user's profile Send private message AIM Address MSN Messenger

PostPosted: Fri Dec 09, 2011 4:37 am     Reply with quote

thnx , the program is runnig, thnx
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