|
#include
void key_scan(void);
volatile unsigned char i=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR &= ~BIT3;//输入
P1DIR |=BIT6;//输出
// P1REN |= BIT1;//上拉
P1OUT |=BIT6;
_DINT();
while(1)
{
key_scan();
}
}
void key_scan(void)
{
if((P1IN&0x08)!=0x08)
{
_EINT();
}
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
TACCTL0 = CCIE;
P1DIR |= 0x04; // P1.2 output
P1SEL |= 0x04; // P1.2 TA1/2 options
TACTL = TASSEL_1 + MC_1+TAIE; // ACLK, up mode
CCR0 = 1160-1; // PWM Period
CCTL1 = OUTMOD_7; // CCR1 reset/set
CCR1 = 5; // CCR1 PWM duty cycle
i++;
if(i==12000)
{
P1OUT &=~BIT6;
i=0;
TACTL &=~TAIE;
}
}
|
|