我想用定时器b来做iar里面定时器a的演示程序功能。但是我把程序改好之后,一直不能正常运行,从右面的disassem××y窗口里面看不到数据。请问为何。程序那里有错?谢谢大侠!!!
#include <msp430x14x.h>
void main(void)
{
P1DIR |= 0x03; // P1.0 P1.1output
P1OUT |= 0x00;
while(1)
{
WDTCTL=WDTPW+WDTHOLD;
TBCTL=0X0220; //TimerB 为连续计数模式
TBCCR0=3000; //
TBCCTL0=CCIE;
_NOP();
}
}
#pragma vector=TIMERB0_VECTOR
__interrupt void Timer_B(void)
{
P1OUT^=BIT0;
TBCCR0 += 3000;
}
谢谢!!定时器不是两个中断向量吗?
定时器不是两个中断向量吗?我看在演示程序里面TA的就没有,我也就没加!!!!
这是iar的例程:它能够正常运行,请问为何?我就是想用定时器b做这样的功能
请指点。谢谢!!!
//********************************************************
// MSP-FET430P140 Demo - Timer_A Toggle P1.0, CCR0 Contmode ISR, DCO SMCLK
//
// Description; Toggle P1.0 using using software and TA_0 ISR. Toggle rate is
// set at 50000 DCO/SMCLK cycles. Default DCO frequency used for TACLK.
// Durring the TA_0 ISR P0.1 is toggled and 50000 clock cycles are added to
// CCR0. TA_0 ISR is triggered exactly 50000 cycles. CPU is normally off and
// used only durring TA_ISR.
// ACLK = n/a, MCLK = SMCLK = TACLK = DCO~ 800k
//
//
// MSP430F149
// ---------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.0|-->LED
//
// M. Buccini
// Texas Instruments, Inc
// October 2003
// Built with IAR Embedded Workbench Version: 2.20A
//************************************************************
#include <msp430x14x.h>
void main(void)
{
P1OUT &=0X00;
while(1){
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x01; // P1.0 P1.1,P1.2,P1.3 output
P1OUT |= 0x08;
CCTL0 = CCIE; // CCR0 interrupt ena××ed
CCR0 = 30000;
TACTL = TASSEL_2 + MC_2; // SMCLK, contmode
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
}
// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
P1OUT ^= 0x01; // Toggle P1.0
CCR0 += 30000; // Add Offset to CCR0
}
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
记得开中断.
能够告诉我是怎样解决的吗?我发现TimerB 在连续计数模式,在中断中不断修改TBCCR的时候,有时候会出现定时不准的情况。搞不清楚为什么?
程序是这样的,你看看!!!
#include <msp430x14x.h>
unsigned int m;
void main(void)
{WDTCTL=WDTPW+WDTHOLD;
P4DIR |= 0x01; // P4.0 output
P4OUT |= 0x00;
m=0;
while(1)
{
TBCTL=0X0220;
TBCCR0=60000;
TBCCTL0=CCIE;
_EINT();
}
}
#pragma vector=TIMERB0_VECTOR
__interrupt void Timer_B(void)
{
if (m==4)
{
P4OUT^=BIT0;
TBCCR0 += 60000;
m=0;
}
m++;
}