#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit shuma1=P2^4;
sbit shuma2=P2^5;
sbit shuma3=P2^6;
sbit shuma4=P2^7;
void senddata(uchar dat);
void display(uchar distance);
void delay(uint z);
uchar distance,temp;
void main()
{
TMOD = 0x20;
SCON = 0x50;
TH1 = 0xF3;
TL1 = TH1;
PCON = 0x00;
EA = 1;
ES = 1;
TR1 = 1;
while(1)
{
//senddata(12);
delay(100);
display(distance);
}
}
void senddata(uchar dat)
{
SBUF =dat;
while(!TI);
TI = 0;
}
void receivedata() interrupt 4
{
if(RI)
{
distance=SBUF;
}
else
TI = 0;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uchar distance)
{
uint temp1,temp2, ge,shi,bai;
unsigned code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
ge=distance%10;
temp1=distance/10;
shi=temp1%10;
temp2=temp1/10;
bai=temp2%10;
P0=0xff;
shuma1=1;
shuma2=1;
shuma3=1;
shuma1=0;
P0=table[bai];
delay(1);
shuma1=1;
P0=0xff;
shuma2=0;
P0=table[shi];
delay(1);
shuma2=1;
P0=0xff;
shuma3=0;
P0=table[ge];
delay(1);
shuma3=1;
P0=0xff;
shuma4=0;
P0=table[0];
delay(1);
shuma4=1;
P0=0xff;
}
这是收发程序 请高手们们看一看 哪里不对 |