#include<msp430f5529.h>
#include "HAL_Dogs102x6.h"
char width[10];
char ta[11];
unsigned int i=0;
unsigned long int AverageTB0;
//unsigned int num;
void main()
{
WDTCTL=WDTPW+WDTHOLD; //关闭看门狗
Dogs102x6_init();
Dogs102x6_backlightInit();
Dogs102x6_setBacklight(5);
Dogs102x6_setContrast(8);
Dogs102x6_clearScreen();
P2DIR &= ~BIT0;
P2SEL|=BIT0; //P5.6作为捕获模块功能的输入端输入方波
P6DIR |=BIT0;
P6OUT |=BIT0;
//-------开晶振XT2---------
P5SEL=BIT2+BIT3; //声明特殊功能,将用作外部时钟晶振XT2输入
UCSCTL6&=~XT2OFF; //开启XT2
do
{
UCSCTL7 &= ~(XT2OFFG);
SFRIFG1 &= ~OFIFG;
}while (UCSCTL7 & XT2OFFG);
UCSCTL4 |= SELM_5 + SELS_5;
UCSCTL6 &= ~SMCLKOFF;
//-----------------------------
/*TBCCTL0&=~(CCIS1+CCIS0); // 捕获源为P7.5,即CCI0A(也是CCI0B)
TBCCTL0|=CM_2+SCS+CAP; //下降沿捕获,同步捕获,工作在捕获模式
TBCCTL0|=CCIE; //允许捕获比较模块提出中断请求
TBCTL|=ID_3;
TBCTL|=TBSSEL_2; //选择时钟MCLK
TBCTL|=TBCLR; //定时器清零,
//定时器开始计数(连续计数模式0~0xFFFF)
TBCTL|=MC_2; */
TA1CTL |= TASSEL_2 + MC_2 + ID_3 +TACLR; // ACLK, upmode,8fenpin clear TAR
TA1CCTL1 |=CAP+CCIS_1+CM_1+CCIE; //CM_1是捕获模式的选择
_EINT();
while(1);
}
//―――――定时器TB的CCR0的中断:用于检测脉冲上升与下降沿――――
#pragma vector=TIMER1_A1_VECTOR
__interrupt void TIMER1_A1_ISR(void)
{
if(TA1CCTL1&CM1) //捕获到下降沿
{
P6OUT |=BIT0;
TA1CTL|=TACLR;
TA1CCTL1=(TA1CCTL1&(~CM1))|CM0; //改为上升沿捕获:CM1置零,CM0置一
}
else if(TA1CCTL1&CM0) //捕获到上升沿
{
P6OUT &= ~BIT0;
width[i++]=TA1CCR0; //记录下结束时间
TA1CCTL1=(TA1CCTL1&(~CM0))|CM1; //改为下降沿捕获:CM0置零,CM1置一
if(i==10)
{
AverageTB0 = 0;
for(i = 0; i < 10; i++)
AverageTB0 += width[i];
AverageTB0 >>= 5; //除以10求平均值,以免数据不停跳变
i=0;
}
//num = 360 * f * AverageTB0;
ta[0] = width[0]/10000%10+'0';
ta[1] = width[0]/1000%10+'0';
ta[2] = width[0]/100%10 + '0';
ta[3] = (width[0]%100)/10 + '0';
ta[4] = width[0]%10+'0';
Dogs102x6_stringDraw(3, 5, "Time", DOGS102x6_DRAW_NORMAL);
Dogs102x6_stringDrawXY(3, 30, ta, DOGS102x6_DRAW_NORMAL);
}
}
调试进不了中断。。不知道为什么。。 |