感覺沒毛病啊,以前在at89c51上能用,改了點用在stc15上就不行了。
#include"C:\Keil\C51\INC\STC\STC15F2K60S2.H"
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit trig=P2^4;
sbit echo=P2^5;
sbit key=P2^0;
sbit s1=P1^5;
sbit s2=P1^6;
sbit s3=P1^7;
uint q[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90} ;
ulong h;
uint a,g,sh,b,m=0;
void main()
{
ulong s;
ulong l;
void ys();
EA=0;
kaishi: trig=0;
echo=0;
g=0;sh=0;b=0;h=0;l=0;s=0;
TMOD=0X01;
AUXR=0X00;
trig=1;
for(a=50;a>0;a--);
trig=0;
while(echo==0);
TL0=0x00;
TH0=0x00;
TR0=1;
while(echo==1&&TF0==0);
TR0=0;
h=TH0;l=TL0;
s=(h*256+l)*344/2000;
if(s<30||s>999) s=0;
g=s%10;
sh=s/10%10;
b=s/100;
while(1)
{ P0=0XFF;
s1=0;s2=1;s3=1; P0=q[g];ys();P0=0XFF;
s1=1;s2=0;s3=1;P0=q[sh];ys();P0=0XFF;
s1=1;s2=1;s3=0;P0=q[b]; ys(); P0=0XFF;
m++;
if(m==30){m=0;
goto kaishi;}
}
}
void ys()
{
uint x,y;
for(x=10;x>0;x--)
for(y=100;y>0;y--);
}
|