【文件属性】:
文件名称:超声波程序
文件大小:1KB
文件格式:TXT
更新时间:2016-05-16 13:34:54
超声波 51 数码管
51 超声波 数码管显示距离
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit P0_1=P0^1;
sbit P0_2=P0^2;
uint time=0,timer=0;
uchar posit=0;
unsigned long S=0;
bit flag =0;
uchar const discode[] ={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,0x00};
uchar const positon[3]={ 0xdf,0xef,0xf7};
uchar disbuff[4] ={ 0,0,0,0,};
void delay(uint x)
{
uchar i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void Display(void)
{
if(posit==0)
{
P1=(discode[disbuff[posit]])&0x7f;
}
else
{
P1=discode[disbuff[posit]];}
P2=positon[posit];
if(++posit>=3)
posit=0;
}
void Conut(void)
{
time=TH0*256+TL0;
TH0=0;
TL0=0;
S=(time*1.7)/100;
if((S>=700)||flag==1)
{
flag=0;
disbuff[0]=10;
disbuff[1]=10;
disbuff[2]=10;
……