#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define pi 3.14
#define r 0.33
sbit duan=P2^0;
sbit we =P2^1;
uchar code tab_duan[]={0x3F,0x06,0x5B,0x4F,
0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,
0x39,0x5E,0x79,0x71};
uchar code tab_we[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void delay(uint);
bit flag;
uchar t,sec;
uint v1,s1,n;
float
time,s,v;
float tab_v[6];
void show(uchar j,uchar k)
{
P0=0;
P0=0;
duan=1;
P0=tab_duan[j];
duan=0;
P0=0XFF;
P0=0XFF;
we=1;
P0=tab_we[k];
we=0;
delay(2);
}
void delay(uint n)
{
uint x,y;
for(x=n;x>0;x--);
for(y=110;y>0;y--);
}
void init()
{
TMOD=0x01;
TH1=0x3c;
TL1=0xb0;
TR1=1;
EA=1;
EX0=1;
PX0=1;
IT0=1;
ET0=1;
}
void rupt()interrupt 0
{uchar i;
time=sec+t*0.05;
sec=0;t=0;
tab_v[5]=0.9*pi*r/time;
if(tab_v[5]>=5)
{
flag=0;
for(i=0;i<6;i++)
tab_v
=tab_v[i+1];
}
else
flag=1;
TR0=0;
TH0=0x3c;
TL0=0xb0;
TR0=1;
n++;
if(n==50000)
n=0;
if(time>=5)
n=0;
}
void timer0()interrupt 1
{TH0=0x3c;
TL0=0xb0;
t++;
}
void date_deal()
{
uchar i;
if(t==20)
{
t=0;
sec++;
}
if(flag==1)
v=tab_v[5];
else
{
v=0;
for(i=0;i<6;i++)
v+=tab_v;
v=v/6;
}
s=0.00025*pi*r*n;
}
void main()
{
init();
while(1)
{
date_deal();
v1=v*10;
s1=s*10;
show(v1/100,0);
show(v1/10%10,1);
show(v1%10,2);
show(s1/1000%10,4);
show(s1/100%10,5);
show(s1/10%10,6);
show(s1%10,7);
}
}
基于单片机的车速里程表的设计
仿真没结果
求大神带。。。
一周热门 更多>