msp430输出pwm波

2019-03-24 13:07发布

打算让p12输出pwm波,但调试半天程序一直有问题,但不报错。用板子上的led和蜂鸣器,没有一点反应,后来改用proteus仿真了一下,显示输出电平没有变化,希望能有大神帮忙解决这个问题,不胜感激啊。。。
#include "msp430x14x.h"
void main()
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  P1DIR |=BIT2;
  P1SEL |=BIT2;
  TACCR0=4000;
  TACCTL1=OUTMOD_7;             // set/reset模式                 
  TACCR1=2000;
  TACTL =MC_1+TASSEL_1+TACLR;   //增计数模式 ACLK 清除定时器A
} 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
2条回答
wstt
2019-03-24 19:37
  1. //*******************************************************************************
  2. // MSP-FET430P140 Demo - Timer_A, PWM TA1-2, Up Mode, DCO SMCLK
  3. //
  4. // Description: This program generates two PWM outputs on P1.2,3 using
  5. // Timer_A configured for up mode. The value in CCR0, 512-1, defines the PWM
  6. // period and the values in CCR1 and CCR2 the PWM duty cycles. Using ~800kHz
  7. // SMCLK as TACLK, the timer period is ~640us with a 75% duty cycle on P1.2
  8. // and 25% on P1.3.
  9. // ACLK = n/a, SMCLK = MCLK = TACLK = default DCO ~800kHz.
  10. //
  11. // MSP430F149
  12. // -----------------
  13. // /|| XIN|-
  14. // | | |
  15. // --|RST XOUT|-
  16. // | |
  17. // | P1.2/TA1|--> CCR1 - 75% PWM
  18. // | P1.3/TA2|--> CCR2 - 25% PWM
  19. //
  20. // M. Buccini
  21. // Texas Instruments Inc.
  22. // Feb 2005
  23. // Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A
  24. //******************************************************************************

  25. #include

  26. void main(void)
  27. {
  28. WDTCTL = WDTPW + WDTHOLD; // Stop WDT
  29. P1DIR |= 0x0C; // P1.2 and P1.3 output
  30. P1SEL |= 0x0C; // P1.2 and P1.3 TA1/2 otions
  31. CCR0 = 512-1; // PWM Period
  32. CCTL1 = OUTMOD_7; // CCR1 reset/set
  33. CCR1 = 384; // CCR1 PWM duty cycle
  34. CCTL2 = OUTMOD_7; // CCR2 reset/set
  35. CCR2 = 128; // CCR2 PWM duty cycle
  36. TACTL = TASSEL_2 + MC_1; // SMCLK, up mode

  37. _BIS_SR(LPM0_bits); // Enter LPM0
  38. }
复制代码

一周热门 更多>

相关问题

    相关文章