码迷,mamicode.com
首页 > 其他好文 > 详细

MSP430F149学习之路——PWM信号

时间:2015-07-09 19:30:35      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

代码一:

 1 /*******************************
 2 程序功能:ACLK=32768Hz 
 3           PWM波 T=512/32768 占空比75%
 4 *********************************/
 5 
 6 #include <msp430x14x.h>
 7 void main()
 8 {
 9   WDTCTL = WDTPW + WDTHOLD;
10   TACTL  = TASSEL_1 + TACLR;
11   
12   CCTL0 = 0X00;
13   CCTL1 = 0X00;
14   
15   CCR0  = 512-1;    //T=512/32768
16   CCTL1 = OUTMOD_7;
17   CCR1  = 384;      //384/512=0.75
18   CCTL2 = OUTMOD_7;
19  // CCR2  = 124;
20   
21   P1DIR |= BIT2;k
22   P1SEL |= BIT2;
23   P2DIR |= BIT0;
24   P2SEL |= BIT0;
25   
26   TACTL |= MC_1;  
27 }

代码二:

 1 #include <msp430x14x.h>
 2 void int_clk()
 3 {
 4   BCSCTL1 &= ~XT2OFF;
 5   BCSCTL2 |= SELM1 + SELS;  //MCLK-->1MHz SMCLK-->8MHz
 6   do
 7   {
 8     IFG1 &= ~OFIFG;
 9     for(int i=0;i<100;i++)
10       _NOP();
11   }while((IFG1 & OFIFG)!=0);
12   IFG1 &= ~OFIFG;
13 }
14 void main()
15 {
16   WDTCTL = WDTPW + WDTHOLD;
17   int_clk();
18   P1DIR |= BIT0;
19   P1SEL |= BIT0;
20   TACCR0 = 800;  //PWM f=10kHz
21   TACCR1 = 400;   //1:1
22   TACCTL1 |= OUTMOD_7;
23   TACTL  = TASSEL_2 + MC_1;
24 }

 

MSP430F149学习之路——PWM信号

标签:

原文地址:http://www.cnblogs.com/boyiliushui/p/4633984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!