#include <AT89X51.H> #include <intrins.h> #include <STDIO.H>
#define uchar unsigned char #define uint unsigned int #define RX P1_1 #define TX P1_2
unsigned int time=0; unsigned int timer=0; float S=0; bit flag =0;
void Conut(void) { time=TH0*256+TL0; TH0=0; TL0=0; S=(time*1.87)/100; if(flag==1) { flag=0; printf("-----\n"); }
printf("S=%fcm\n",S); }
void delayms(unsigned int ms) { unsigned char i=100,j; for(; ms; ms--) { while(--i) { j=10; while(--j); } } }
void zd0() interrupt 1 { flag=1; }
void StartModule() { TX=1; _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); TX=0; }
void main(void) { TMOD=0x21; SCON=0x50; TH1=0xFD; TL1=0xFD; TH0=0; TL0=0; TR0=1; ET0=1; TR1=1; TI=1;
EA=1;
while(1) { StartModule(); while(!RX); TR0=1; while(RX); TR0=0; Conut(); delayms(100);
}
}
|