代码如下:
#include <msp430g2553.h>
#include "12864.h"
#include "delay.h"
#define uint unsigned int
#define uchar unsigned char
unsigned long int mk=0;
uint num=0;
/************************主函数****************************/
void main(void)
{
WDTCTL = WDTPW+WDTHOLD; //关闭看门狗
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ; // DCO 1MHz
lcdinit(); //复位1602液晶
// LCD_dsp_string(1,0,"占空比:");
LCD_dsp_string(1,0,"脉宽:");
LCD_dsp_string(2,0,"脉宽:");
// LCD_dsp_string(3,0,"脉宽:");
// LCD_dsp_string(4,0,"脉宽:");
P1IES = 0; // P1.4为 IO中断,上升沿
P1IE |= BIT4;
// P1REN |= BIT4;
// P1OUT &= ~BIT4; //下拉电阻
P1SEL |= BIT0; //P1.0 ACLK输出
P1DIR |= BIT0;
BCSCTL1 |= DIVA_3;
TACTL |= TACLR;
TACCTL0 |= CCIE;
// TACTL = TASSEL_2+MC_2; //SMCLK 8M,清计数器,使能中断,连续增计模式
while(1)
{
_EINT();
LPM0;
mk=num*65536+mk;
if(mk<5000)
{
LCD_set_xy(1,3);
LCD_write_dat('0'+mk/10000);
LCD_write_dat('0'+mk/1000%10);
LCD_write_dat('0'+mk/100%10);
LCD_write_dat('0'+mk/10%10);
LCD_write_dat('0'+mk%10);
LCD_write_dat('u');
LCD_write_dat('s');
}
else
{
mk=mk/1000;
LCD_set_xy(1,3);
LCD_write_dat('0'+mk/10000);
LCD_write_dat('0'+mk/1000%10);
LCD_write_dat('0'+mk/100%10);
LCD_write_dat('0'+mk/10%10);
LCD_write_dat('0'+mk%10);
LCD_write_dat('m');
LCD_write_dat('s');
}
num=0;
TACTL |=TACLR;
delay_ms(500);
}
}
/************中断函数****************/
#pragma vector=
tiMER0_A0_VECTOR
__interrupt void TimerA0 (void)
{
num++;
}
#pragma vector=PORT1_VECTOR // P1口中断处理函数
__interrupt void PORT1_ISR(void)
{
TACTL = TASSEL_2+MC_2;
while(P1IN&BIT4 == BIT4);
TACTL = MC_0;
__disable_interrupt();
mk=TAR;
P1IFG = 0;
LPM0_EXIT; // Clear CPUOFF bit from 0(SR)
}
我是使用的IO中断测的脉宽,可是实际效果不理想,就只是测ACLK8分频后都一直显示五千多ms,求大神助攻,帮忙看看。另外直接使用定时器的捕获测我也试过,但是好像只能测到1K到6K左右。
一周热门 更多>