MSP430G2452按键(P1.3)操控P1.0(LED)灯亮灭C言语程序,P1.3为带上拉电阻的输入状况,P1.0为输出状况,当P1.3按下,P1.0口LED灯则亮,松开按键,LED灯则平息,无限循环的下去!程序如下:
#include “msp430g2452.h”
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR = 0x01; // P1.0 output, else input
P1OUT = 0x08; // P1.3 set, else reset
P1REN |= 0x08; // P1.3 pullup
while (1) // Test P1.3
{
if(0x08 & P1IN)
{
P1OUT |= 0x01; // if P1.3 set, set P1.0
}
else P1OUT &= ~0x01; // else reset
}
}