超声波 测距
include #include #define Keydown 1 #define KeyUp 0 bit KeyFirst=1; bit KeyState=KeyUp; uchar KeyValue; ***it CLK=P1^6; ***it DAT=P1^5; ***it MeasureEn=P3^7;uchar NumCode[4]={0,0,0,0};uchar code LedSelect[4]={0x01,0x02,0x04,0x08}; //数码管的为选通信号int timeData;int DispNum;int DispTemp;uint Distance[3]={0,0,0}; //定义三次测量结果数组uchar T0Num;uchar MeasureTime; //第几次测量bit FlagEndMeasure; //测量完成一次的标志bit Flag20ms=0;bit Flag50ms=0;bit Flag1s=0;extern bit FlagSgn; //DS18B20正负温度标志void StartMeasured(); //启动测距void Measure3Times(); //启动测距三次,并取中值//---------------------------------------------------------void T0Init(){TMOD=0x01;TH0=(65536-5000)/256; //定时5ms,动态扫描TL0=(65536-5000)%256 TR0=1;这里出错(syntax error near 'TR0')ET0=1;EA=1;}
更多回帖