欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2166|回復: 0
收起左側

超聲波測距模塊的單片機源碼

[復制鏈接]
ID:308567 發表于 2018-4-15 14:40 | 顯示全部樓層 |閱讀模式
超聲波測距模塊

單片機源程序如下:
  1. /*******************************************************************************
  2. * 日期           : 2015.7.29
  3. * 實 驗 名                 : 1602 顯示 超聲波 返回距離值         
  4. * 實驗說明       : 1.基于22.1184MHz晶振
  5. * 注    意                 : 用本程序掃描得出最大距離為 60 厘米  最小為 2 厘米
  6.                                    掃描周期60ms以上 并將 掃描標志位        設置在 u_speed()函數 后面
  7. -----------------------------------------------------------------------------------
  8. * 修改內容       :
  9. *******************************************************************************/

  10. #include <reg52.h>
  11. #include "Ultrasonic.h"
  12. #include "1602.h"
  13. #define LED P0
  14. #define LED_SEL P2


  15. static char flag = 0;
  16. unsigned char code LED_num []={                            //共陰                          
  17.                                 0x3f,0x06,0x5b,0x4f,0x66,
  18.                                 0x6d,0x7d,0x07,0x7f,0x6f} ;

  19. unsigned char code place[]={0x00,0x01,0x02,0x03} ;

  20. void t_init();                                                            //中斷初始化

  21. int main()
  22. {
  23.         unsigned int re_1 = 0, re_2 = 0;
  24.     unsigned char time = 0;
  25.     unsigned char index = 0;
  26.     unsigned int length = 0;
  27.         t_init();                                                          

  28. //    Lcd1602_Int ();                                                          

  29. //        writecom(0x80 + 3);
  30. //        writedata('0');
  31. //        writedata('0');
  32. //        writedata('0');
  33. //    writedata('0');
  34. //        writedata(' ');
  35. //        writedata('M');
  36. //        writedata('M');
  37.    
  38.         while(1)
  39.         {
  40.                 if(flag == 1)                                          //80ms 為一次超聲波掃描周期
  41.                 {       
  42.             time++;
  43.             flag = 0;
  44.             
  45. //            writecom(0x80 + 3);
  46. //            writedata('0' + re_1%10000/1000);
  47. //                        writedata('0' + re_1%1000/100);
  48. //                        writedata('0' + re_1%100/10);
  49. //                        writedata('0' + re_1%10/1);       
  50.             
  51.             
  52.             switch(index)
  53.             {
  54.                 case 0:LED_SEL = place[0] ; LED = LED_num[length%10000/1000];break;
  55.                 case 1:LED_SEL = place[1] ; LED = LED_num[length%1000/100];break;
  56.                 case 2:LED_SEL = place[2] ; LED = LED_num[length%100/10];break;
  57.                 case 3:LED_SEL = place[3] ; LED = LED_num[length%10/1];break;
  58.                 default : ;
  59.             }
  60.             if(index<3)
  61.             {
  62.                 index++;
  63.             }
  64.             else
  65.             {
  66.                 index = 0;
  67.             }
  68.                        
  69.                 }
  70.         
  71.         if(time == 7)
  72.         {
  73.             time = 0;
  74.             TR1 = 0;
  75.             //length = u_range();             //掃描標志位要放在返回值后面, u_range()函數 執行有點長 影響測量周期
  76.             re_1 = length;
  77.             TR1 = 1;
  78.         }

  79.         }

  80.         return 0;
  81. }

  82. void t_init()
  83. {               
  84.         TMOD = 0X11;
  85.        
  86.     TH1 = 0x0B8;        //定時10ms   
  87. ……………………

  88. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
超聲波測距.rar (54.72 KB, 下載次數: 6)


回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表