|
本程序是《MSP430系列單片機(jī)系統(tǒng)工程設(shè)計(jì)與實(shí)踐》書(shū)里面的源碼,(包含工程文件 (例2.8.22)))完整例程下載:http://www.torrancerestoration.com/bbs/dpj-46245-1.html

- #include <msp430x42x.h>
- /********************************************************************
- * 名 稱:Divider_SetDivFactor
- * 功 能:設(shè)置分頻系數(shù)
- * 入口參數(shù):Factor: 分頻系數(shù) (2~65535)
- * 出口參數(shù):無(wú)
- ********************************************************************/
- void Divider_SetDivFactor(unsigned int Factor) //設(shè)置分頻系數(shù)
- {
- TACCR0=Factor-1; // 分頻系數(shù)=計(jì)數(shù)器溢出周期
- TACCR2=Factor/2; // 占空比=50%
- }
- void main( void )
- {
- WDTCTL = WDTPW + WDTHOLD; // 停止看門狗
- FLL_CTL0 |= XCAP18PF; // 配置晶振負(fù)載電容
- P1DIR &=~BIT5; // P1.5(TACLK)作為輸入引腳
- P1SEL |= BIT5; // 允許其第二功能,作為TACLK輸入
- P2DIR |= BIT0; // P2.0作為輸出
- P2SEL |= BIT0; // 允許P2.0第二功能,作為TA2輸出
- TACTL = TASSEL_0 + MC_1 ; // TA外部計(jì)數(shù),增計(jì)數(shù)模式
- TACCTL2 = OUTMOD_7; // TA2作為輸出,模式7 (PWM模式)
- Divider_SetDivFactor(100); // 100分頻
- while(1)
- {
- //CPU可以繼續(xù)執(zhí)行其他任務(wù)
- }
- }
復(fù)制代碼
|
|