|
#include
#define uint unsigned int
#define uchar unsigned char
void PWM_init(uint zkb1,uint zkb2);
void init_clk();
uint count_PWM = 0;
uchar flag = 0;
void main()
{
WDTCTL = WDTPW + WDTHOLD;
init_clk();
PWM_init(200,100);
P1DIR |= BIT4;
P1OUT |= BIT4;
TACCTL0 |= CCIE;
_EINT();
while(1)
{
if(flag == 1)
{
P2OUT |= BIT2;
P2OUT |= BIT3;
flag=0;
TACCTL0 &= ~CCIE;
TACTL |= MC_0 ;
P1OUT |= BIT3;
}
}
}
void init_clk()
{
uint i;
BCSCTL1 &= ~XT2OFF; //打开XT振荡器
BCSCTL2 |= SELM_2+SELS;
do
{
IFG1 &= ~OFIFG; //Reset OFIFG
for(i = 0xff; i > 0; i--);
}
while((IFG1 & OFIFG));
}
void PWM_init(uint zkb1,uint zkb2)
{
P1SEL |= BIT2 + BIT3;
P1DIR |= BIT2 +BIT3;
CCR0 = 1200;
CCTL1 = OUTMOD_7; // CCR1 reset/set
CCR1 = zkb1; // CCR1 PWM duty cycle
CCTL2 = OUTMOD_7; // CCR2 reset/set
CCR2 = zkb2;
TACTL |= TASSEL_2 + ID_0+ MC_1 ;
P2DIR |= BIT2 +BIT3;
}
#pragma vector = TIMERA0_VECTOR
__interrupt void TIMER0 (void)
{
count_PWM = count_PWM + 1;
P2OUT &= ~ BIT3;
P2OUT &= ~ BIT2;
if(count_PWM >= 8000)
{
count_PWM = 0;
flag=1;
}
}
|
|