|
- #include <msp430g2553.h>
- #include "LCD_init.h"
- #define CPU_F ((double)1000000)
- #define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
- #define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
- #define delay_s(x) __delay_cycles((long)(CPU_F*(double)x/1.0))
- unsigned int start,end;
- unsigned char overflow;
- unsigned int length;
- unsigned char display_buffer[]={0x00,0x00,0x00,0x00,0xff};
- unsigned char number_table[]={'0','1','2','3','4','5','6','7','8','9'};
- void Data_Converter(uchar *p)
- {
- uint j=0;
- j=length/1000;
- p[0]=number_table[length/10000];
- j=length%10000/1000;
- p[1]=number_table[j];
- j=length%1000/100;
- p[2]=number_table[j];
- j=length%100/10;
- p[3]=number_table[j];
- j=length%10/1;
- p[4]=number_table[j];
- }
- void LCD_GPIO_init(void)
- {
- LCD_DIR|=BIT0+BIT1+BIT2+BIT3+BIT5;
- LCD_IN|=BIT4;//字库输入脚设置
- }
- void setup(void)
- {
- BCSCTL1 = CALBC1_1MHZ; /* Set DCO 改变频率显示速度改变 */
- DCOCTL = CALDCO_1MHZ;
- P1DIR |= BIT0+BIT3; //设置P1.0 P1.4为输出
- P1SEL |= BIT1 + BIT2; //设置P1.2端口为功能模块使用
- TA0CTL = TASSEL_1 | ID_0 | MC_2 | TACLR; //定时器A时钟信号选择ACLK,同时设置定时器A计数模式为连续增计模式
- TA0CCTL0 = CM_1 | CCIS_0 | SCS | CAP | CCIE;
- _EINT(); //中断允许
- LCD_GPIO_init();
- initial_lcd();
- clear_screen(); //clear all dots
- }
- int main(void)
- {
- WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
- setup();
- start=1;
- while(1)
- {
- P1OUT |= BIT0;
- delay_us(15);
- P1OUT &= ~BIT0;
- delay_ms(60);
- length=start;
- Data_Converter(display_buffer);
- display_GB2312_string(2,1,display_buffer);
- }
- }
- #pragma vector=TIMER0_A0_VECTOR
- __interrupt void TIMER0_A0(void)
- {
- switch(TA0IV) //向量查询
- {
- case 2: //捕获中断
- if(TA0CCTL0&CM_0) //上升沿
- {
- TA0CCTL0=(TA0CCTL0&(~CM_1))|CM_2;//更变设置为下降沿触发
- start=TA0CCR0; //记录初始时间
- overflow=0; //溢出计数变量复位
- }
- else if (TA0CCTL0&CM_2) //下降沿
- {
- TA0CCTL0=(TA0CCTL0&(~CM_2))|CM_1;//更变设置为上升沿触发
- end=TA0CCR0;
- TA0CTL |= TACLR;//用start,end,overflow计算脉冲宽度
- }
- break;
- case 10: //定时器溢出中断
- overflow++;
- break; //溢出计数加1
- default:break;
- }
- }
复制代码 我在写一个对脉冲宽度的捕捉然后在显示屏上显示出脉冲的宽度,这是程序的一部分。然后我调试的时候,一开始是发现无法进入中断,然后对P1.1口接VCC时应该会有一个上升沿的,但是没有进入中断,但是接GND的时候会产生中断,但是这个时候观察寄存器TA0IV 发现一直显示的是0x0000,我就觉得很奇怪,请问是怎么回事呢?
|
|