|
#include "MSP430x14x.h"
#define uint unsigned int
#define uchar unsigned char
void delayms(uint ms)
{
uchar i;
while(ms--)
for(i=110;i>0;i--);
}
void DSC_Init()
{
BCSCTL1&=~XT2OFF;
BCSCTL2|=SELM_2+DIVM_0;
do
{
IFG1&=~OFIFG;
delayms(8);
}
while(IFG1&OFIFG);
}
void PWMA_TA_Init()
{
TACTL|=TASSEL_1+ID_0+MC_1+TACLR;
TACCTL1|=OUTMOD_7;
TACCTL2|=OUTMOD_7;
TACCR0=10000;
TACCR1=5000;
TACCR2=100;
}
void PWMA_IO_Init()
{
P1DIR|=BIT0+BIT2+BIT3+BIT5+BIT6+BIT7;
P2DIR|=BIT2+BIT3+BIT4;
P1SEL|=BIT1+BIT2+BIT3+BIT5+BIT6+BIT7;
P2SEL|=BIT2+BIT3+BIT4;
}
void PWMB_IO_Init()
{
P4DIR|=BIT1;
P4SEL|=BIT1;
}
void PWMB_TB_Init()
{
TBCTL|=TBCLGRP_3+CNTL_0+TBSSEL_1+ID_0+MC_1+TBCLR;
TBCCR0=10000;
TBCCTL1|=OUTMOD_7;
TBCCR2=100;
TBCCTL2|=OUTMOD_7;
TBCCR2=200;
TBCCTL3|=OUTMOD_7;
TBCCR3=400;
TBCCTL4|=OUTMOD_7;
TBCCR4=1000;
TBCCTL5|=OUTMOD_7;
TBCCR5=2000;
TBCCTL6|=OUTMOD_7;
TBCCR6=5000;
}
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
DSC_Init();
PWMA_IO_Init();
// PWMB_IO_Init();
PWMA_TA_Init();
// PWMB_TB_Init();
while(1);
}
|
|