数码管版。。可能还有bug欢迎报告
#include <reg52.h>
#include <intrins.h>
#include <math.h>
#define DataPort P0
sbit rs=P1^0;
sbit e=P1^2;
sbit rw=P1^1;
sbit in=P3^5; //t1
sbit g=P0^0;
sbit s=P0^1;
sbit b=P0^2;
sbit q=P0^3;
sbit w=P0^4;
sbit dula=P1^0;
sbit wela=P1^1;
sbit ind=P2^0;
unsigned char tfc,num,waste,stof;
unsigned int hout,lout,c,t;
unsigned long int result,transit;
unsigned code otime[]={0x6f,0x6e,0x74,0x69,0x6d,0x65,0x3d};
code unsigned char seg7code[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void DelayUs2x(unsigned char t)
{
while(--t);
}
void delay(unsigned char t)
{
while(t--)
{
//????1mS
DelayUs2x(245);
DelayUs2x(245);
}
}
void led(unsigned long int dis)
{
num=0;
while(num!=30)
{
[s:9]0=seg7code[dis%10];
dula=1;
dula=0;
[s:9]0=0xef;
wela=1;
wela=0;
delay(1);
[s:9]0=seg7code[dis/10%10];
dula=1;
dula=0;
[s:9]0=0xf7;
wela=1;
wela=0;
delay(1);
[s:9]0=seg7code[dis/100%10];
dula=1;
dula=0;
[s:9]0=0xfb;
wela=1;
wela=0;
delay(1);
[s:9]0=seg7code[dis/1000%10];
dula=1;
dula=0;
[s:9]0=0xfd;
wela=1;
wela=0;
delay(1);
[s:9]0=seg7code[dis/10000%10];
dula=1;
dula=0;
[s:9]0=0xfe;
wela=1;
wela=0;
delay(1);
num++;
[s:9]0=0xff;
wela=1;
wela=0;
}
num=0;
}
void start()
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
TR0=1;
TR1=1;
t=0;
c=0;
while(t+c==0){}
if(t>=c)
{
while(c==0){}
TR0=0;
TR1=0;
tfc=1;
hout=TH0;
lout=TL0;
}
else
{
while(t==0){}
TR0=0;
TR1=0;
tfc=0;
hout=TH1;
lout=TL1;
}
}
unsigned long int calculate()
{
if(tfc==1)
{
transit=t*5000+(5000-(65536-(hout*256+lout)));
result=100000-(10000000/(transit/50));
}
if(tfc==0)
{
transit=((c+1)*5000)-(65536-(hout*256+lout));
result=transit*4; //Hundred Hz is the unit
}
return result;
}
void initial()
{
rs=0;
rw=0;
e=0;
TMOD=0x51 ; // T1=count T0=time
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
EA=1;
ET1=1;
ET0=1;
TR0=0;
TR1=0;
}
void main()
{
initial();
// while(1){c++;}
while(1)
{
start();
led(calculate());
ind=stof;
}
}
void count ()interrupt 3
{
c++;
if(t==0)
{
TH1=(65536-5000)/256; //reset count while time haven't trig
TL1=(65536-5000)%256;
}
}
void time () interrupt 1
{
t++;
if(c==0)
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
}
}
上几张图
[attachment=event]
#include <reg52.h>
#include <intrins.h>
#include <math.h>
#define DataPort P0
sbit rs=P1^0;
sbit e=P1^2;
sbit rw=P1^1;
sbit in=P3^5; //t1
sbit g=P0^0;
sbit s=P0^1;
sbit b=P0^2;
sbit q=P0^3;
sbit w=P0^4;
sbit dula=P1^0;
sbit wela=P1^1;
sbit ind=P2^0;
unsigned char tfc,num,waste,stof;
unsigned int hout,lout,c,t;
unsigned long int result,transit;
unsigned code otime[]={0x6f,0x6e,0x74,0x69,0x6d,0x65,0x3d};
code unsigned char seg7code[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void DelayUs2x(unsigned char t)
{
while(--t);
}
void delay(unsigned char t)
{
while(t--)
{
//????1mS
DelayUs2x(245);
DelayUs2x(245);
}
}
void led(unsigned long int dis)
{
num=0;
while(num!=30)
{
[s:9]0=seg7code[dis%10];
dula=1;
dula=0;
[s:9]0=0xef;
wela=1;
wela=0;
delay(1);
[s:9]0=seg7code[dis/10%10];
dula=1;
dula=0;
[s:9]0=0xf7;
wela=1;
wela=0;
delay(1);
[s:9]0=seg7code[dis/100%10];
dula=1;
dula=0;
[s:9]0=0xfb;
wela=1;
wela=0;
delay(1);
[s:9]0=seg7code[dis/1000%10];
dula=1;
dula=0;
[s:9]0=0xfd;
wela=1;
wela=0;
delay(1);
[s:9]0=seg7code[dis/10000%10];
dula=1;
dula=0;
[s:9]0=0xfe;
wela=1;
wela=0;
delay(1);
num++;
[s:9]0=0xff;
wela=1;
wela=0;
}
num=0;
}
void start()
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
TR0=1;
TR1=1;
t=0;
c=0;
while(t+c==0){}
if(t>=c)
{
while(c==0){}
TR0=0;
TR1=0;
tfc=1;
hout=TH0;
lout=TL0;
}
else
{
while(t==0){}
TR0=0;
TR1=0;
tfc=0;
hout=TH1;
lout=TL1;
}
}
unsigned long int calculate()
{
if(tfc==1)
{
transit=t*5000+(5000-(65536-(hout*256+lout)));
result=100000-(10000000/(transit/50));
}
if(tfc==0)
{
transit=((c+1)*5000)-(65536-(hout*256+lout));
result=transit*4; //Hundred Hz is the unit
}
return result;
}
void initial()
{
rs=0;
rw=0;
e=0;
TMOD=0x51 ; // T1=count T0=time
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
EA=1;
ET1=1;
ET0=1;
TR0=0;
TR1=0;
}
void main()
{
initial();
// while(1){c++;}
while(1)
{
start();
led(calculate());
ind=stof;
}
}
void count ()interrupt 3
{
c++;
if(t==0)
{
TH1=(65536-5000)/256; //reset count while time haven't trig
TL1=(65536-5000)%256;
}
}
void time () interrupt 1
{
t++;
if(c==0)
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
}
}
上几张图
[attachment=event]
200字以内,仅用于支线交流,主线讨论请采用回复功能。