mspg2553的ccs中自带程序ta.21c不能运行

2019-03-23 22:27发布

CCSmsp430g2553自带程序ta.21c。在launch pad上我把p1.1和p2.1连接后跑程序。一直进不了中断。后来看了下程序发现他的自带程序有两行有错。我用//////////////标记了出来。这两行应该是P1DIR &= ~BIT1;P1SEL |= BIT1,他程序是BIT2。但是修改之后还是一直进不了中断。我后来又用函数发生器作为捕获信号接到p1.1,仍然进不了中断。以前没有朋友运行过ta.21c这个程序吗?难道能正常运行?
#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;
}
}

此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
7条回答
数码小叶
2019-03-24 15:30
< :TI_MSP430_内容页_SA7 --> 你之前做过flash的擦写实验没??

一周热门 更多>

相关问题

    相关文章