Jump to content
Sign in to follow this  
touch

Need some help with interrupts

Recommended Posts

I've been messing around with interrupts to get better acquainted with them and have ran into a big of a snag that I cannot figure out.

 

I'm trying to use two momentary switches on ports 1.4 and 1.5 to toggle the state of the two debug LED's using interrupts, however whats actually happening is one button is toggling both and the other toggles just one LED.

 

Anyways, here is my code:

#include  

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;  

P1DIR = BIT0 + BIT6; //led 1 and 2 as outputs

P1IES |= 0x01;
P1IFG &= BIT4 + BIT5;
P1IE |= BIT4 + BIT5;                   

_BIS_SR(LPM4_bits + GIE);                
}


#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
if(P1IN & BIT4){
	P1OUT ^= BIT0;
	P1IFG = BIT4;
}
if(P1IN & BIT5){
	P1OUT ^= BIT6;
	P1IFG = BIT5;
}
}

 

I've been pulling my hair out trying different things to get it to work without success, figured I'd ask here, thanks!

Share this post


Link to post
Share on other sites

It works as expected if I use the example code provided by TI for toggling a single LED with an interrupt, I'm just trying to expand upon that to the two LED's based upon the falling state of each switch.

 

After reading a bit more, I've figured out that the flags actually tell you what port caused the interrupt, and changed my code accordingly, but now either switch toggles both LED's.

 

#include  

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;  

P1DIR = BIT0 + BIT6; //led 1 and 2 as outputs

P1IES |= 0x01;
P1IFG = 0x00;
P1IE |= BIT4 + BIT5;                     

_BIS_SR(LPM4_bits + GIE);                
}


#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
if(P1IFG & BIT4){
	P1OUT ^= BIT0;
}
if(P1IFG & BIT5){
	P1OUT ^= BIT6;
}
P1IFG = 0x00;
}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...