1284 views|0 replies

2015

Posts

0

Resources
The OP
 

Learn MSP430F5529 programming routines [Copy link]

Press P2.1, LED1 lights up for 1s, quickly press P2.1 twice, LED2 lights up for 1s
// Press P2.1, LED1 lights up for 1s, quickly press P2.1 twice, LED2 lights up for 1s

#include "msp430f5525.h"

unsigned int n=0;

int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer

P1DIR |= BIT0;
P4DIR |= BIT7;
P2DIR &= ~BIT1;
P2REN |= BIT1;
P2OUT |= BIT1;
P1OUT &= ~BIT0;
P4OUT &= ~BIT7;

P2IE |= BIT1;
P2IES |= BIT1;
P2IFG &= ~BIT1;
_EINT();

while(1)
{
if(n==0)
{
P1OUT &= ~BIT0;
P4OUT &= ~BIT7;
}
else if(n==1)
{
P1OUT |= BIT0;
P4OUT &= ~BIT7;
__delay_cycles(1000000);
n=0;
}
else if(n==2)
{
P1OUT &= ~BIT0;
P4OUT |= BIT7;
__delay_cycles(1000000);
n=0;
}
}
return 0;
}

#pragma vector = PORT2_VECTOR
__interrupt void Port2()
{
unsigned int i=0;
if(!(P2IN & BIT1))
{
__delay_cycles(5000); //Debounceif
(!(P2IN & BIT1))
{
//__delay_cycles(5000); //If it is still in the pressed state, it is regarded as not released, the first presswhile
(!(P2IN & BIT1)){} //First releasen
= 1;
P2IFG &= ~BIT1;
//__delay_cycles(50000); //If a key is pressed after 500ms, it is regarded as the second presswhile
((P2IN & BIT1)) //If it is not pressed within 500ms-1000ms, it is regarded as only pressed once
{
i++;
__delay_cycles(1000);
if(i>1000)
return;
} //The program jumps out here because the key is pressedif
(!(P2IN & BIT1))
{
__delay_cycles(5000); //Debounceif
(!(P2IN & BIT1))
{
while(!(P2IN & BIT1)){} //Second releasen
= 2;
P2IFG &= ~BIT1;
}
}
}
}
}

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list