#include <msp430g2452.h> #define BUTTON BIT3 #define LED_RED BIT0 #define LED_GREEN BIT6 #define LED_DIR P1DIR #define BUTTON_DIR P1DIR #define BUTTON_OUT P1OUT #define LED_OUT P1OUT #define BUTTON_REN P1REN #define BUTTON_ON (P1IN&BIT3) #define BUTTON_OFF !(P1IN&BIT3) #define BIT_SET(x , y) x |= (y) #define BIT_CLR(x , y) x &=~(y) volatile unsigned char i=0,flag=1; void main(void) { WDTCTL = WDTPW + WDTHOLD;
BIT_CLR(BUTTON_DIR , BUTTON); BIT_SET(LED_DIR , LED_RED+LED_GREEN); BIT_SET(BUTTON_REN , BUTTON); BIT_SET(BUTTON_OUT , BUTTON); /********************************************************/ while(1) { /*通过按键改变选择标志位*/ if(BUTTON_OFF) { flag=!flag; while(BUTTON_OFF); } /*****************************************************/ if(flag) { BIT_SET(LED_OUT , LED_RED); i=10; while(i--) _delay_cycles(50000); BIT_CLR(LED_OUT , LED_RED); /*****************************************************/ BIT_SET(LED_OUT , LED_GREEN); i=10; while(i--) _delay_cycles(50000); BIT_CLR(LED_OUT , LED_GREEN); } /*****************************************************/ else { BIT_SET(LED_OUT ,LED_RED+LED_GREEN); i=10; while(i--) _delay_cycles(50000); /*****************************************************/ BIT_CLR(LED_OUT , LED_RED+LED_GREEN); i=10; while(i--) _delay_cycles(50000); } } }
/***************变化一点点*******************/ |