标题: 超声波测距(LCD1602显示) 给大家学习一下! [打印本页]

作者: 初心22    时间: 2019-6-12 22:20
标题: 超声波测距(LCD1602显示) 给大家学习一下!
#include<reg51.h>
#include<intrins.h>
#include"lcd.h"
sbit Trig = P2^1;
sbit Echo = P2^0;

unsigned char PuZh[]=" Pechin Science ";
unsigned char code ASCII[15] =    {'0','1','2','3','4','5','6','7','8','9','.','-','M'};
static unsigned char DisNum = 0; //显示用指针      
       unsigned int  time=0;
    unsigned long S=0;
    bit      flag =0;
    unsigned char disbuff[4]    ={ 0,0,0,0,};
void Conut(void)
{
  time=TH0*256+TL0;
  TH0=0;
  TL0=0;

  S=(time*1.7)/100;     //算出来是CM
  if((S>=700)||flag==1) //超出测量范围显示“-”
  {  
   flag=0;
  
   DisplayOneChar(0, 1, ASCII[11]);
   DisplayOneChar(1, 1, ASCII[10]); //显示点
   DisplayOneChar(2, 1, ASCII[11]);
   DisplayOneChar(3, 1, ASCII[11]);
   DisplayOneChar(4, 1, ASCII[12]); //显示M
  }
  else
  {
   disbuff[0]=S%1000/100;
   disbuff[1]=S%1000%100/10;
   disbuff[2]=S%1000%10 %10;
   DisplayOneChar(0, 1, ASCII[disbuff[0]]);
   DisplayOneChar(1, 1, ASCII[10]); //显示点
   DisplayOneChar(2, 1, ASCII[disbuff[1]]);
   DisplayOneChar(3, 1, ASCII[disbuff[2]]);
   DisplayOneChar(4, 1, ASCII[12]); //显示M
  }
}
void zd0() interrupt 1    //T0中断用来计数器溢出,超过测距范围
  {
    flag=1;        //中断溢出标志
  }
void  StartModule()            //启动模块
  {
   Trig=1;                        //启动一次模块
   _n

pro.zip

2.18 KB, 下载次数: 20, 下载积分: 黑币 -5

程序


作者: 在许啥子    时间: 2020-4-29 12:39
请问超出测量范围那里为什么是s大于等于700?700是怎么得来的
作者: 在许啥子    时间: 2020-4-29 12:42
我拿到的一个程序用的好像是11.0592的时钟频率S=time1*1.87/100,仿真时却用的是12的时钟频率。我把仿真时的频率改成12反而不行




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1