各语句的意思
- #include "reg52.h"
- #define uchar unsigned char
- #define uint unsigned int
- unsigned int z;
- unsigned int time=0;
- unsigned char code s8[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- uchar timeL;
- uchar timeH;
- sbit TX=P2^0;
- sbit RX=P3^2;
- void delay(unsigned int x)
- {
- unsigned int y;
- for(x;x>0;x--)
- for(y=0;y<125;y++)
- ;
- }
- void Display(unsigned int x)
- {
- unsigned char shu1,shu2,shu3,shu4;
- shu1=x/1000;
- shu2=x/100%10;
- shu3=x/10%10;
- shu4=x%10;
- P2=s8[shu1];
- P0=0x80;
- delay(1);
- P2=s8[shu2];
- P0=0x40;
- delay(1);
- P2=s8[shu3];
- P0=0x08;
- delay(1);
- P2=s8[shu4];
- P0=0x01;
- delay(1);
- }
- void delay_20us()
- {
- uchar a ;
- for(a=0;a<10;a++);
- }
- void Conut(void)
- {
- time=TH0*256+TL0;
- TH0=0;
- TL0=0;
- // z=(time*340)/2;
- z=time/10;
- }
- void main ()
- {
- int y;
- TX=0;
- // EA=1;
- TMOD=0x01;
- TH0=0;
- TL0=0;
- TR0=0;
- TX=0;
- while(1)
- {
- TX=1;
- delay_20us() ;
- TX=0;
- while(RX==0);
- TR0=1;
- while(RX==1);
- TR0=0;
- Conut();
- for(y=0;y<50;y++)
- Display(z);
- }
- }
复制代码
|