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 support@ccsinfo.com

interupt on change porta

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tvnorm
Guest







interupt on change porta
PostPosted: Sun Dec 11, 2005 4:40 pm     Reply with quote

I have been reading up on interrupts on the forum, and based on my findings I have come up with the following code, which is mainly based on newguys keypad routine. I simply want to light an LED on port b for a second whenever a button is pressed on port a. It doesnt' seem to want to work. I checked the.LST file, and it seems to be clearing the interrupt flag after the interrupt routine, but im still new to this and can only just about follow whats going on.
Any Suggestions?

//PIC CONFIGURATION
#include <16F690.H>
#fuses XT, NOWDT, NOPROTECT, NOPUT, NOBROWNOUT, NOMCLR
#use delay(clock = 4000000) //base delay times on a 4MHz Xtal

//FUNCTIONS AND LABELS
void light_led(void);
void PORTA_ISR(void);

//DEFINES
#byte PORTA = 5
#byte PORTB = 6 //PIC b portb (6) replaced by string PORTB

//VARIABLES and CONSTANTS
int1 button;
static int prior_porta_state;

//CODE
void light_led(void)
{
disable_interrupts(INT_RA);
PORTB = 0xFF;
delay_ms(1000);
PORTB=0;
PORTA = prior_porta_state;
enable_interrupts(INT_RA);
}

#INT_RA
void PORTA_ISR(void)
{
if (prior_porta_state != PORTA)
{
prior_porta_state = PORTA;
button = TRUE;
}
}

void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
//setup_timer_0(RTCC_INTERNAL);
//setup_timer_1(T1_DISABLED);
//setup_timer_2(T2_DISABLED,0,1);
//setup_spi(FALSE);
setup_comparator(NC_NC_NC_NC);
setup_oscillator(OSC_4MHZ);

set_tris_a(0xFF);
PORTA=0;
port_a_pullups(TRUE);
delay_us(10);

button = FALSE;

set_tris_b(0x00);
PORTB = 0;

prior_porta_state=PORTA;

enable_interrupts(INT_RA);
enable_interrupts(GLOBAL);

prior_porta_state=PORTA;

while(1) //hangs here until an interrrupt then returns?
{
if(button==TRUE)
{
button = FALSE;
light_led();
}
}
}
tvnorm
Guest







PostPosted: Sun Dec 11, 2005 7:56 pm     Reply with quote

Well, in case anyone is interested, a little more digging cleared it up. Hopefully another beginner can benefit from this, or someone else can laugh at it.
I erroneously thought that

enable_interrupts(INT_RA);

Would register any interrupt on PORTA- it doesn't appear to do anything.
(other than as in #INT_RA)

However,

enable_interrupts(INT_RA0|INT_RA1|INT_RA2|INT_RA3|INT_RA4|INT_RA5);

Works as I wanted it too, with the added bonus being able to mask whatever inputs I want!!
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