test44x_tb02.c

来自「msp430系列开发板源代码」· C语言 代码 · 共 53 行

C
53
字号
//******************************************************************************
//  MSP430-TEST44X Demo - Timer_B Toggle P5.1, TBCCR0 upmode ISR, DCO SMCLK
//
//  Description; toggle P5.1 using using software and TB_0 ISR. Timer_B is
//  configured in upmode, thus the timer will overflow when TBR counts to TBCCR0.
//  In this example, CCR0 is loaded with 20000.
//  ACLK = n/a, MCLK = SMCLK = TACLK = DCO=1M
//
//           MSP430F449
//         ---------------
//     /|\|            XIN|-
//      | |               |
//      --|RST        XOUT|-
//        |               |
//        |           P5.1|-->LED
//
//  Lierda, Inc
//  February 2006.03
//  Built with IAR Embedded Workbench Version: 3.40A
//  ID:  MSP430-TEST44X
//  DATA:2005-7-12
//  REV: 2.0A
//  程序功能:该程序是用F449的内部TIMER_B CCR0的比较模式功能,来控制P5.1口驱动LED 500ms闪烁。
//  硬件连接:先连接P5.1口的短接器,然后连接键盘上方的短接器J2。
//
//******************************************************************************

#include <msp430x44x.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;             // Stop WDT
  TBCTL = TBSSEL0 + TBCLR;              // ACLK, clear TBR
  TBCCTL0 = CCIE;                       // TBCCR0 interrupt enabled
  TBCCR0 = 16384;                       // 500ms interrupt
  P5DIR |= 0x02;                        // Set P5.1 to output direction
  TBCTL |= MC0;                         // Start Timer_a in upmode
  _EINT();                              // Enable interrupts

  for (;;)
  {
    _BIS_SR(CPUOFF);                    // CPU off
    _NOP();                             // Required only for C-spy
  }
}

#pragma vector=TIMERB0_VECTOR
__interrupt void Timer_B (void)
{
  P5OUT ^= 0x02;                        // Toggle P5.1 using exclusive-OR
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?