TI中文支持网
TI专业的中文技术问题搜集分享网站

msp430捕获程序

msp430g2553系统自带程序ta.21c。在launch pad上我把p1.1和p2.1连接后跑程序。为什么一直进不了中断??不是都连接了p1.1和p2.1了吗

#include <msp430.h>

unsigned char Count, First_Time;
unsigned int REdge1, REdge2, FEdge;

int main(void)
{
unsigned int Period, ON_Period;
unsigned char DutyCycle;

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

// P1SEL |= BIT0;
P1DIR |= BIT0; // P1.0/LED Output
P1OUT &= ~BIT0; // LED off
if (CALBC1_8MHZ==0xFF) // If calibration constant erased
{ while(1); // do not load, trap CPU!! }
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_8MHZ; // Set DCO to 8MHz
DCOCTL = CALDCO_8MHZ;

// Configure Port Pins
P2DIR |= BIT1; // P2.1/TA1.1 Output
P2SEL |= BIT1; // TA1.1 Option select
P1DIR &= ~BIT2; // P1.1/TA0.1 Input Capture
P1SEL |= BIT2; // TA0.1 option select

// Configure TA1.1 to output PWM signal
// Period = 82/32khz = 2.5ms ~ 400Hz Freq
TA1CCR0 = 82-1; // Period Register
TA1CCR1 = 21; // TA1.1 25% dutycycle
TA1CCTL1 |= OUTMOD_7; // TA1CCR1, Reset/Set
TA1CTL = TASSEL_1 + MC_1 + TACLR; // ACLK, upmode, clear TAR

// Configure the TA0CCR1 to do input capture
TA0CCTL1 = CAP + CM_3 + CCIE + SCS + CCIS_0;
// TA0CCR1 Capture mode; CCI1A; Both
// Rising and Falling Edge; interrupt enable
TA0CTL |= TASSEL_2 + MC_2 + TACLR; // SMCLK, Cont Mode; start timer

// Variable Initialization
Count = 0x0;
First_Time = 0x01;

while(1)
{
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0
__no_operation(); // For debugger
// On exiting LPM0
if (TA0CCTL1 & COV) // Check for Capture Overflow
while(1); // Loop Forever

Period = REdge2 – REdge1; // Calculate Period
ON_Period = FEdge-REdge1; // On period
DutyCycle = ((unsigned long)ON_Period*100/Period);
if(DutyCycle!= 25)
{
P1OUT |= BIT0;
}
else
{
P1OUT &= ~BIT0;
}
}
}

// TA0_A1 Interrupt vector
#pragma vector = TIMER0_A1_VECTOR
__interrupt void TIMER0_A1_ISR (void)
{
switch(__even_in_range(TA0IV,0x0A))
{
case TA0IV_NONE: break; // Vector 0: No interrupt
case TA0IV_TACCR1: // Vector 2: TACCR1 CCIFG
if (TA0CCTL1 & CCI) // Capture Input Pin Status
{
// Rising Edge was captured
if (!Count)
{
REdge1 = TA0CCR1;
Count++;
}
else
{
REdge2 = TA0CCR1;
Count=0x0;
__bic_SR_register_on_exit(LPM0_bits + GIE); // Exit LPM0 on return to main
}

if (First_Time)
First_Time = 0x0;
}
else
{
// Falling Edge was captured
if(!First_Time)
{
FEdge = TA0CCR1;
}
}
break;
case TA0IV_TACCR2: break; // Vector 4: TACCR2 CCIFG
case TA0IV_6: break; // Vector 6: Reserved CCIFG
case TA0IV_8: break; // Vector 8: Reserved CCIFG
case TA0IV_TAIFG: break; // Vector 10: TAIFG
default: break;
}
}

user5274669:

不好意思。光看注释去了。P1DIR &= ~BIT2; // P1.1/TA0.1 Input Capture。这里系统程序应该错了吧?应该是P1DIR &= ~BIT1吧。这样才是P1.1/TA0.1 Input Capture

user5274669:

回复 user5274669:

改了之后还是没办法运行

灰小子:

回复 user5274669:

感谢分享经验。尽信书不如无书。
发现问题然后找到原因所在,也是一种升华。

赞(0)
未经允许不得转载:TI中文支持网 » msp430捕获程序
分享到: 更多 (0)