#include
unsigned int pwm_start,pwm_end,pwm_wide=0;
float fre=0.000;
#define uchar unsigned char
#define uint unsigned int
#define lint long int
unsigned int start,end;
float data,num,m1;
long int m2=10,j=0;
uchar a[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};//0->9,共阴;
uchar num1,num2,num3,num4,num5,num6;
void delay(uint j) //延时函数
{ uint x,y;
for(x=j;x>0;x--)
for(y=50;y>0;y--);
}
void xianshi(float fre)//数码管动态显示函数(P2->位,P3->段)
{
lint tt,ttt,tttt,ttttt;
tt=(lint)fre; //整数部分
ttt=(lint)(fre*10);//第一位小数
tttt=(lint)(fre*100);//第二位小数
ttttt=(lint)(fre*1000);
num1=(tt/100)%10;
num2=(tt/10)%10;
num3=tt%10;
num4=ttt%10;
num5=tttt%10;
num6=ttttt%10;
P2OUT |= BIT0;//亮第一个数码管
P3OUT=a[num1];
delay(6);
P2OUT=0x00;
P2OUT = 0x02;//亮第二个数码管
P3OUT=a[num2];
delay(6);
P2OUT=0x00;
P2OUT = 0x04;//亮第三个数码管
P3OUT=a[num3];
P3OUT |=BIT7;//点亮小数点
delay(6);
P2OUT=0x00;
P2OUT = 0x08;//亮第四个数码管
P3OUT=a[num4];
delay(6);
P2OUT=0x00;
P2OUT = 0x10;//亮第五个数码管
P3OUT =a[num5];//第一位小数
delay(6);
P2OUT =0x00;
P2OUT = 0x20;//亮第六个数码管
P3OUT =a[num6];//第二位小数
delay(6);
P2OUT=0x00;
}
void main (void)
{
WDTCTL = WDTPW+WDTHOLD; //关闭看门狗定时器
P1SEL = BIT2; //设置P1.2端口为功能模块使用,CCI0A
P2DIR =0x3f; //位选
P3DIR =0xff; //段选
P2OUT =0x00;
P3OUT =0x00;
TACTL = TASSEL0+TACLR+TAIE+MC1; //定时器A时钟信号选择ACLK,同时设置定时器A计数模式为连续增计模式
CCTL1 = CM_3+SCS+CAP+CCIE+CCIS0; //捕获模式,上升和下降都捕获,CCI0A为捕获信号源
_EINT(); //中断允许
for(;;)
{
_BIS_SR(LPM0_bits + GIE);
_NOP();
pwm_wide=(pwm_end-pwm_start+overflow*65536)*0.000125;
fre=1/(2*pwm_wide); // 频率
xianshi(fre);
}
}
// Timer_A3 Interrupt Vector (TAIV) handler
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A1(void)
{
switch(TAIV)
{case 2:
if(TACCTL1 & CCI)
pwm_start=CCR1;
else
pwm_end=CCR1;
break;
case 4:
break;
case 10: overflow++;
break;
}
LPM0_EXIT;
}
请各位大虾看看这个程序有什么问题么,指导一下,谢谢了!!