⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 超声波发射程序.lst

📁 基于单片机的超声波测距程序,用C编写.液晶显示
💻 LST
字号:
C51 COMPILER V8.01   砡蒧波发射程序                                                        11/21/2006 21:22:30 PAGE 1   


C51 COMPILER V8.01, COMPILATION OF MODULE 砡蒧波发射程序
OBJECT MODULE PLACED IN 超声波发射程序.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE 超声波发射程序.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include<reg52.h>
   2          #include<intrins.h>
   3          #define uchar unsigned char
   4          #define uint unsigned int
   5          #define ulong unsigned long
   6          
   7          uint c;
   8          ulong l,time;
   9          char i=1,j=1,k=80;
  10          char t,tp=10,ts,tg,lb,ls,lg,lsf,fh,cb,cs,cg;
  11          sbit RW=P2^1;
  12          sbit RS=P2^0;
  13          sbit E=P2^2;
  14          sbit rece=P3^3;
  15          sbit tup=P1^1;
  16          sbit tdown=P1^0;
  17          sbit aj=P1^2;
  18          sbit reset=P1^3;
  19          
  20          sbit sg=P3^7;
  21          sbit DQ=P3^5;
  22          sbit ctl=P3^5;
  23          
  24          
  25          void delay(uint i)
  26          {while(i--);
  27   1       }
  28          
  29          //************液晶显示***************//
  30          
  31          void writercom(uchar q)
  32          {E=1;
  33   1       RS=0;
  34   1       RW=0;
  35   1       P0=q;
  36   1       E=0;
  37   1       delay(20);
  38   1       }
  39          
  40          void writerdata(uchar o)
  41          {
  42   1       E=1;
  43   1       RS=1;
  44   1       RW=0;
  45   1       P0=o;
  46   1       E=0;
  47   1       delay(20);
  48   1       }
  49          
  50          void writer_d(uchar *u)
  51          {while(*u)
  52   1        writerdata(*u++);
  53   1       }
  54          
  55          void xsinit(void)
C51 COMPILER V8.01   砡蒧波发射程序                                                        11/21/2006 21:22:30 PAGE 2   

  56          {writercom(0x01);
  57   1       writercom(0x38);//使用8位数据,显示两行,使用5*7的字型//
  58   1       writercom(0x0c);//显示设置,不显示光标,字符不显闪琐//
  59   1       writercom(0x06);//光标从左往右移,内容不移//
  60   1      
  61   1        }
  62          
  63          pdisplay()
  64          {writercom(0x80);
  65   1       writer_d("Press any key   ");
  66   1       writercom(0xba);
  67   1       writer_d("  to continue...");
  68   1       delay(2000);
  69   1      
  70   1      }
  71          
  72          bdisplay()
  73          {writercom(0x80);
  74   1       writer_d("Ultrasonic      ");
  75   1       writercom(0xba);
  76   1       writer_d("    range finder");
  77   1       delay(60000);
  78   1       }
  79          
  80          ipdisplay()
  81          {writercom(0x80);
  82   1       writer_d(" Please input   ");
  83   1       writercom(0xba);
  84   1       writer_d("T(");
  85   1       writerdata(0xdf);
  86   1       writer_d("C) with K1,K2.");
  87   1       delay(2000);
  88   1       }
  89          
  90          
  91          
  92          //*************超声波测距*************************//
  93          
  94          void csbinit()    //初始化程序,计数/定时器状态 //
  95          {TMOD=0x12;    //定时器1工作在定时方式1,定时器0工作在定时方式2//
  96   1       IE=0x84;          //中断设置//
  97   1       TH0=244;
  98   1       TL0=244;
  99   1       }
 100          
 101          void sen()         //超声波发射程序//
 102          {uchar times=0;
 103   1       TR0=1;
 104   1       TR1=1;        //开定时器//
 105   1       while(1)
 106   1       {while(TF0==0);
 107   2        sg=~sg;
 108   2        times++;     //翻转20次,发送10个脉冲信号的超声波//
 109   2        TF0=0;   
 110   2        if(times==20)break;}
 111   1        times=0;
 112   1      }
 113          
 114          csbdata()
 115          {lb=l/1000000;
 116   1       ls=l%1000000/100000;
 117   1       lg=l%1000000%100000/10000;
C51 COMPILER V8.01   砡蒧波发射程序                                                        11/21/2006 21:22:30 PAGE 3   

 118   1       lsf=l%1000000%100000%10000/1000;
 119   1       if(lsf>=5)lg=lg+1;
 120   1      }
 121          
 122          rec()interrupt 2 using 2//接收中断程序//
 123          {TR1=0;//关计数器//
 124   1       ctl=0;
 125   1       time=TH1*256+TL1; //算出t的值,t的单位为us//
 126   1       l=time*c/2;
 127   1       TH1=0;
 128   1       TL1=0;
 129   1       }
 130          
 131          display1()
 132          {
 133   1       while(k--)
 134   1        {ipdisplay();
 135   2         if(tup==0||tdown==0||reset==0||aj==0){i=0;break;}
 136   2         }
 137   1         k=60;
 138   1       while(k--)
 139   1        {pdisplay();
 140   2         if(tup==0||tdown==0||reset==0||aj==0){i=0;break;}
 141   2         }
 142   1         k=60;
 143   1       }
 144          measure()
 145          {csbdata();
 146   1        while(1)
 147   1        {if(aj==1)break;}
 148   1        ctl=0;
 149   1        sen();
 150   1        delay(200);
 151   1        ctl=1;
 152   1       }
 153          
 154          
 155          display2()
 156          {writercom(0x80);
 157   1       writer_d("T:");
 158   1       writerdata(fh);
 159   1       writerdata(ts+0x30);
 160   1       writerdata(tg+0x30);
 161   1       writerdata(0xdf);
 162   1       writer_d("C ");
 163   1       writer_d("c=");
 164   1       writerdata(cb+0x30);
 165   1       writerdata(cs+0x30);
 166   1       writerdata(cg+0x30);
 167   1       writer_d("m/s");
 168   1       while(i)
 169   1       {while(k--)
 170   2        {writercom(0xba);
 171   3         writer_d("Press K3 measure");
 172   3         if(aj==0){i=0;break;}
 173   3         delay(2000);}
 174   2         k=20;
 175   2        while(k--)
 176   2        {writercom(0xba);
 177   3         writer_d("                ");
 178   3         if(aj==0){i=0;break;}
 179   3         delay(2000);}
C51 COMPILER V8.01   砡蒧波发射程序                                                        11/21/2006 21:22:30 PAGE 4   

 180   2         k=20;
 181   2        }
 182   1        i=1;
 183   1       measure();
 184   1       delay(2000);
 185   1       csbdata();
 186   1       writercom(0x80);
 187   1       if(l<=360000)writer_d("too near!       ");
 188   1       else if(TH1>=93)writer_d("too long!       ");
 189   1       else {csbdata();
 190   2             writer_d("L=");
 191   2             writerdata(lb+0x30);
 192   2             writerdata('.');
 193   2             writerdata(ls+0x30);
 194   2             writerdata(lg+0x30);
 195   2             writer_d("m  ");      
 196   2             writer_d("T:");
 197   2             writerdata(fh);
 198   2             writerdata(ts+0x30);
 199   2             writerdata(tg+0x30);
 200   2             writerdata(0xdf);
 201   2             writer_d("C ");
 202   2             }
 203   1       while(i)
 204   1      {writercom(0xba);
 205   2       writer_d("Press K4 again..");
 206   2       if(tup==0&&tdown==0){j=0;break;}
 207   2       if(reset==0){i=0;break;}
 208   2        
 209   2       }
 210   1      }
 211          //***************温度输入程序**************//
 212          iptemp()
 213          {while(1)
 214   1       {if(t<0){fh=0x2d;t=~t+1;}
 215   2        else{fh=0x20;}
 216   2        ts=t/10;
 217   2        tg=t%10;
 218   2        writercom(0x80);
 219   2        writer_d("    T:");
 220   2        writerdata(fh);
 221   2        writerdata(ts+0x30);
 222   2        writerdata(tg+0x30);
 223   2        writerdata(0xdf);
 224   2        writer_d("C  ");
 225   2        if(tup==0){tp++;if(tp>=99)tp=99;}
 226   2        delay(7000);
 227   2        if(tdown==0){tp--;if(tp<=(-30))tp=(-30);}
 228   2        t=tp;
 229   2        delay(7000);
 230   2        writercom(0xba);
 231   2        writer_d("Press K4 finish ");
 232   2        if(reset==0)break;
 233   2        }
 234   1      }
 235          //********声速处理程序************************//
 236          sscl()
 237          {c=340;
 238   1      
 239   1       cb=c/100;
 240   1       cs=c%100/10;
 241   1       cg=c%100%10;
C51 COMPILER V8.01   砡蒧波发射程序                                                        11/21/2006 21:22:30 PAGE 5   

 242   1       }
 243          
 244          //***************主程序***************//
 245          main()
 246          {while(1)
 247   1      {xsinit();
 248   2       csbinit();
 249   2       bdisplay();
 250   2       bdisplay();
 251   2       bdisplay();
 252   2       bdisplay();
 253   2       bdisplay();
 254   2       ipdisplay();
 255   2       ipdisplay();
 256   2       while(i)
 257   2       {display1();
 258   3        }
 259   2       i=1;
 260   2       delay(20000);
 261   2       iptemp();  //调温度输入函数//
 262   2       sscl();
 263   2       delay(20000);
 264   2      while(j)
 265   2      {display2();
 266   3       i=1;
 267   3       
 268   3      }
 269   2      j=1;
 270   2      delay(60000);
 271   2      }
 272   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1260    ----
   CONSTANT SIZE    =    236    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     25       3
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -