|
#include
#define TR_1_H P1IN|=BIT1 //P1.1
#define TR_1_L P1IN&=~BIT1 //P1.1
#define TR_2_H P1IN|=BIT2 //P1.2
#define TR_2_L P1IN&=~BIT2 //P1.2
#define TR_3_H P1IN|=BIT3 //P1.3
#define TR_3_L P1IN&=~BIT3 //P1.3
#define TR_4_H P1IN|=BIT4 //P1.4
#define TR_4_L P1IN&=~BIT4 //P1.4
void main()
{
WDTCTL=WDTPW+WDTHOLD;//关闭看门狗定时器
P1DIR&=~(BIT1+BIT2+BIT3+BIT4);
P2DIR=0XFF;
while(1)
{
if(P1IN==0X0C)//((P1IN&=~BIT1)&&(P1IN|=BIT2)&&(P1IN|=BIT3)&&(P1IN&=~BIT4))
{
P2SEL=BIT1+BIT4;
P2OUT&=~BIT0;
P2OUT&=~BIT3;
TA1CTL |= TASSEL1 + MC0;
TA1CCR0 = 511;
TA1CCR1 =500;
TA1CCTL1 =OUTMOD_7;
TA1CCR2 = 500;
TA1CCTL2 =OUTMOD_7;
}
else if(P1IN==0X06)//(P1IN|=BIT1)&&(P1IN|=BIT2)&&(P1IN&=~BIT3)&&(P1IN&=~BIT4))
{
P2SEL=BIT1+BIT4;
P2OUT&=~BIT0;
P2OUT&=~BIT3;
TA1CTL |= TASSEL1 + MC0;
TA1CCR0 = 511;
TA1CCR1 = 385;
TA1CCTL1 =OUTMOD_7;
TA1CCR2 = 138;
TA1CCTL2 =OUTMOD_7;
}
else if(P1IN==0X18)//((P1IN&=~BIT1)&&(P1IN&=~BIT2)&&(P1IN|=BIT3)&&(P1IN|=BIT4))
{
P2SEL=BIT1+BIT4;
P2OUT&=~BIT0;
P2OUT&=~BIT3;
TA1CTL |= TASSEL1 + MC0;
TA1CCR0 = 511;
TA1CCR1 = 128;
TA1CCTL1 =OUTMOD_7;
TA1CCR2 = 385;
TA1CCTL2 =OUTMOD_7;
}
else
{
P2SEL=BIT1+BIT4;
P2OUT&=~BIT0;
P2OUT&=~BIT3;
TA1CTL |= TASSEL1 + MC0;
TA1CCR0 = 511;
TA1CCR1 = 500;
TA1CCTL1 =OUTMOD_7;
TA1CCR2 = 500;
TA1CCTL2 =OUTMOD_7;
}
}
}
与大家分享一下,如有什么问题恳请批评指正
|
|