|
用定时器A测方波周期成功,改用定时B却出不来,求助哪里有问题。。
[复制链接]
这是A成功了的
- /****************POWSOS__430************************
- 程序功能:动态显示文字“welcome”
- ----------------------------------------------------
- 测试说明:观察液晶显示
- //算方波的周期 多少秒
- ****************************************************/
- #include <msp430x14x.h>
- #include "paly.h"
- #include <stdio.h>
- unsigned char buf[];
- unsigned char x[];
- float pwm;
- float cha;
- unsigned int pwm_start1,pwm_end1,pwm_wide1;
- unsigned int over;
- unsigned int pwm_start2,pwm_end2,pwm_wide2;
- void main(void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
-
- P1SEL|=BIT2; //P1.2 CCI1A
- P1SEL|=BIT3; //P1.3 CCI2A
- P3DIR|=BIT0;
- P4DIR&=~BIT0;
-
- TACCTL1 =CAP+CM_3+CCIS_0+SCS+CCIE; //捕获模式,上升和下降都捕获,选择CCI1A,同步,捕获中断开 Capture input select: 0 - CCI1A
- TACCTL2 =CAP+CM_3+CCIS_0+SCS+CCIE; //捕获模式,上升和下降都捕获,选择CCI2A,同步,捕获中断开 Capture input select: 0 - CCI2A
- TACTL = TASSEL_1 + MC_2; //ACLK,L连续计数模式
- _EINT(); //开总中断
- _NOP();
- while(1)
- {
- if(pwm_end1>=pwm_start1)
- {
- pwm_wide1=(pwm_end1-pwm_start1)*2;
- }
- else if(pwm_end1<pwm_start1)
- {
- pwm_wide1=(pwm_start1-pwm_end1)*2;
- }
- //pwm_cha=pwm_start1-pwm_start2;
- pwm=pwm_wide1;
- cha=pwm/32768;
- //显示程序
- WDTCTL = WDT_ADLY_1000; //间隔定时器,定时1000ms
- P6DIR |= BIT2;P6OUT |= BIT2; //关闭电平转换
- LcdReset();
- sprintf(buf,"%f",cha);
- DispNChar(1,0,8,buf);
- sprintf(x,"%f",over);
- DispNChar(3,1,4,x);
- }
-
- }
- // Timer_A3 Interrupt Vector (TAIV) handler
- #pragma vector=TIMERA1_VECTOR
- __interrupt void Timer_A(void)
- {
-
- switch(TAIV)
- {case 2:
- if(TACCTL1 & CM0)
- {
- pwm_start1=CCR1;
- TACCTL1=(TACCTL1&(~CM0))|CM1; //更变设置为下降沿触发
- over=0;
- }
- else if(TACCTL1 & CM1)
- {
- TACCTL1=(TACCTL1&(~CM1))|CM0; //更变设置为上升沿触发
- pwm_end1=CCR1;
- }
- break;
- case 4:
- if(TACCTL2 & CCI)
- pwm_start2=CCR2;
- else
- pwm_end2=CCR2;
- break;
- case 10:
- over++;
- break;
- }
- LPM0_EXIT;
- return;
- }
复制代码
这是我依照定时器A改的定时器B的。。。
- /****************POWSOS__430************************
- 程序功能:动态显示文字“welcome”
- ----------------------------------------------------
- 测试说明:观察液晶显示
- //算方波的周期 多少秒
- ****************************************************/
- #include <msp430x14x.h>
- #include "paly.h"
- #include <stdio.h>
- unsigned char buf[];
- unsigned char x[];
- float pwm;
- float cha;
- unsigned int pwm_start1,pwm_end1,pwm_wide1;
- unsigned int over;
- unsigned int pwm_start2,pwm_end2,pwm_wide2;
- void main(void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
-
- P4SEL|=BIT1; //P4.1
- P3DIR|=BIT0;
- P4DIR&=~BIT0;
-
- TBCCTL1 =CAP+CM_3+CCIS_1+SCS+CCIE; //捕获模式,上升和下降都捕获,选择CCI1A,同步,捕获中断开 Capture input select: 0 - CCI1A
- TBCTL = TBSSEL_1 + MC_2; //ACLK,L连续计数模式
- _EINT(); //开总中断
- _NOP();
- while(1)
- {
- if(pwm_end1>=pwm_start1)
- {
- pwm_wide1=(pwm_end1-pwm_start1)*2;
- }
- else if(pwm_end1<pwm_start1)
- {
- pwm_wide1=(pwm_start1-pwm_end1)*2;
- }
- //pwm_cha=pwm_start1-pwm_start2;
- pwm=pwm_wide1;
- cha=pwm/32768;
- //显示程序
- WDTCTL = WDT_ADLY_1000; //间隔定时器,定时1000ms
- P6DIR |= BIT2;P6OUT |= BIT2; //关闭电平转换
- LcdReset();
- sprintf(buf,"%f",cha);
- DispNChar(1,0,8,buf);
- sprintf(x,"%f",over);
- DispNChar(3,1,4,x);
- }
-
- }
- // Timer_B7 Interrupt Vector (TAIV) handler
- #pragma vector=TIMERB0_VECTOR
- __interrupt void Timer_B(void)
- {
-
- switch(TBIV)
- {case 2:
- if(TBCCTL1 & CM0)
- {
- pwm_start1=CCR1;
- TBCCTL1=(TBCCTL1&(~CM0))|CM1; //更变设置为下降沿触发
- over=0;
- }
- else if(TBCCTL1 & CM1)
- {
- TBCCTL1=(TBCCTL1&(~CM1))|CM0; //更变设置为上升沿触发
- pwm_end1=CCR1;
- }
- break;
- case 4:
- if(TBCCTL2 & CCI)
- pwm_start2=CCR2;
- else
- pwm_end2=CCR2;
- break;
- case 10:
- over++;
- break;
- }
- LPM0_EXIT;
- return;
- }
复制代码
不明白为什么A能出来改成B就不行了。。
|
|