久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 18497|回復: 37
打印 上一主題 下一主題
收起左側

VL53l0x激光測距的stm32與51單片機程序

  [復制鏈接]
跳轉到指定樓層
樓主
ID:379688 發表于 2018-7-27 07:29 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
VL53l0x激光測距--單片機程序

還有一個是ST 的

  1. #include "stm32f10x.h" //stm32頭文件
  2. #include "usart.h"
  3. #include "sys.h"
  4. #include "delay.h"
  5. #include "led.h"
  6. #include "vl53l0x.h"
  7. #include "vl53l0x_it.h"




  8. /******************************************************************************/
  9. extern VL53L0X_Dev_t vl53l0x_dev;//設備I2C數據參數
  10. extern u8 alarm_flag;
  11. /******************************************************************************/
  12. int main(void)
  13. {
  14.         u32 i;
  15.         u8 mode;
  16.         VL53L0X_RangingMeasurementData_t RangingMeasurementData;
  17.         
  18.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//分組2
  19.         uart_init(115200);  //串口1
  20.         delay_init();
  21.         LED_Init();
  22.         delay_ms(200);
  23.         
  24.         if(vl53l0x_init(&vl53l0x_dev))//vl53l0x初始化
  25.                 printf("VL53L0X_init Error!!!\r\n");
  26.         else
  27.                 printf("VL53L0X_init OK\r\n");
  28.         
  29.         mode=3;  //高速模式,寫錯會導致測量速度慢
  30.         vl53l0x_interrupt_start(&vl53l0x_dev,mode);
  31.          
  32.          while(1)
  33.          {
  34.                  //VL53L0X_ClearInterruptMask(dev,0);//清除VL53L0X中斷標志位
  35.                  //status = VL53L0X_StopMeasurement(dev); //停止測量
  36.                  
  37.                  if(alarm_flag==1)//觸發中斷
  38.                          {
  39.                                  alarm_flag=0;
  40.                                  VL53L0X_GetRangingMeasurementData(&vl53l0x_dev,&RangingMeasurementData);//獲取測量距離,并且顯示距離
  41.                                  printf("d: %3d mm\r\n",RangingMeasurementData.RangeMilliMeter);
  42.                                  VL53L0X_ClearInterruptMask(&vl53l0x_dev,0);//清除VL53L0X中斷標志位
  43.                          }
  44.                         i++;
  45.                          if(i>=0x1fffff)
  46.                          {
  47.                                  i=0;
  48.                                  LED0=!LED0;
  49.                          }
  50.          }
  51. }
  52. /***************************************************************************/
  53. /***************************************************************************/
復制代碼



單片機源程序如下:
  1. /*****************************
  2. 更新日期2017年2月28日

  3. 模擬串口參考stc官方程序
  4. 來自arduino實例

  5. 使用11.0592MHz內部RC;
  6. VL53L0X:
  7. SCL-->P3.3
  8. SDA-->P3.2
  9. 串口:
  10. P3.0 RXD
  11. P3.1 TXD
  12. *******************************/

  13. #include"stc.h"
  14. #include"i2c.h"
  15. #include"VL53L0X.h"
  16. #include "intrins.h"
  17. #define uchar unsigned char
  18. #define uint unsigned int


  19. /***********全局變量定義**************/
  20. bit flag;
  21. uchar val1;
  22. short val_s;
  23. uchar gbuf[16];
  24. uint acnt ;
  25. uint scnt;
  26. uint dist ;
  27. uchar DeviceRangeStatusInternal;

  28. #define BAUD  0xFE80                  // 9600bps @ 11.0592MHz


  29. //sfr AUXR = 0x8E;
  30. sbit RXB = P3^0;                        //define UART TX/RX port
  31. sbit TXB = P3^1;

  32. typedef bit BOOL;
  33. typedef unsigned char BYTE;
  34. typedef unsigned int WORD;

  35. BYTE TBUF,RBUF;
  36. BYTE TDAT,RDAT;
  37. BYTE TCNT,RCNT;
  38. BYTE TBIT,RBIT;
  39. BOOL TING,RING;
  40. BOOL TEND,REND;

  41. void UART_INIT();



  42. void delay()
  43. {
  44.     unsigned char i;
  45.     for(i=0; i<100; i++);
  46. }
  47. void Delay1ms()                //@11.0592MHz
  48. {
  49.     unsigned char i, j;

  50.     _nop_();
  51.     i = 11;
  52.     j = 190;
  53.     do
  54.     {
  55.         while (--j);
  56.     } while (--i);
  57. }

  58. void delay_ms(unsigned int time)
  59. {
  60.     unsigned char
  61.     i;
  62.     for(i=1; i<=time; i++)
  63.         Delay1ms();
  64. }


  65. void uartsend_int16(short val)
  66. {
  67.     uchar val1;
  68.     val1=val/10000;
  69.     while(!TEND);
  70.     TEND=0;
  71.     TBUF='0'+val1;
  72.     TING=1;
  73.     val1=val%10000/1000;
  74.     while(!TEND);
  75.     TEND=0;
  76.     TBUF='0'+val1;
  77.     TING=1;
  78.     val1=val%1000/100;
  79.     while(!TEND);
  80.     TEND=0;
  81.     TBUF='0'+val1;
  82.     TING=1;
  83.     val1=val%100/10;
  84.     while(!TEND);
  85.     TEND=0;
  86.     TBUF='0'+val1;
  87.     TING=1;
  88.     val1=val%10/1;
  89.     while(!TEND);
  90.     TEND=0;
  91.     TBUF='0'+val1;
  92.     TING=1;
  93. }
  94. void uartprintf(char *s)
  95. {
  96.     int i=0;
  97.     while(s[i]!='\0')
  98.     {
  99.         while(!TEND);
  100.         TEND=0;
  101.         TBUF=s[i];
  102.         TING=1;
  103.         i++;
  104.     }
  105. }
  106. void uartprintenter()
  107. {
  108.     while(!TEND);
  109.     TEND=0;
  110.     TBUF=0x0d;
  111.     TING=1;
  112.         while(!TEND);
  113.     TEND=0;
  114.     TBUF=0x0a;
  115.     TING=1;
  116. }
  117. void main()
  118. {
  119.     uchar val = 0;
  120.     int cnt = 0;
  121.     TMOD = 0x00;                        //timer0 in 16-bit auto reload mode
  122.     AUXR = 0x80;                        //timer0 working at 1T mode
  123.     TL0 = BAUD;
  124.     TH0 = BAUD>>8;                      //initial timer0 and set reload value
  125.     TR0 = 1;                            //tiemr0 start running
  126.     ET0 = 1;                            //enable timer0 interrupt
  127.     PT0 = 1;                            //improve timer0 interrupt priority
  128.     EA = 1;                             //open global interrupt switch

  129.     UART_INIT();
  130.     uartprintf("start");
  131.     while (1)
  132.     {
  133.         vl53l0x_send(VL53L0X_REG_SYSRANGE_START, 0x01);
  134.         while (cnt < 100) { // 1 second waiting time max
  135.             delay_ms(10);
  136.             val = vl53l0x_read(VL53L0X_REG_RESULT_RANGE_STATUS);
  137.             if (val & 0x01) break;
  138.             cnt++;
  139.         }
  140.         if (val & 0x01) uartprintf("ready");
  141.         else uartprintf("not ready");
  142.                                 uartprintenter();
  143.         //vl53l0x_read_block(0x14, 12);
  144.                                 gbuf[0]=vl53l0x_read(0x14);
  145.                                 gbuf[7]=vl53l0x_read(0x14+7);
  146.                                 gbuf[6]=vl53l0x_read(0x14+6);
  147.                                 gbuf[9]=vl53l0x_read(0x14+9);
  148.                                 gbuf[8]=vl53l0x_read(0x14+8);
  149.                                 gbuf[11]=vl53l0x_read(0x14+11);
  150.                                 gbuf[10]=vl53l0x_read(0x14+10);
  151.         acnt = makeuint16(gbuf[7], gbuf[6]);
  152.         scnt = makeuint16(gbuf[9], gbuf[8]);
  153.         dist = makeuint16(gbuf[11], gbuf[10]);
  154.         DeviceRangeStatusInternal = ((gbuf[0] & 0x78) >> 3);
  155.                                 if(DeviceRangeStatusInternal==11&&dist>20&&dist<1200)
  156.                                 {
  157.                                         uartprintf("distance:");
  158.                                         uartsend_int16(dist);
  159.                                         uartprintf("mm");
  160.                                         uartprintenter();
  161.                                 }
  162.                                 else
  163.                                 {
  164.                                         uartprintf("error");
  165.                                         uartprintenter();
  166.                                 }
  167.         delay_ms(100);

  168.     }
  169. }
  170. void tm0() interrupt 1 using 1
  171. {
  172.     if (RING)
  173.     {
  174.         if (--RCNT == 0)
  175.         {
  176.             RCNT = 3;                   //reset send baudrate counter
  177.             if (--RBIT == 0)
  178.             {
  179.                 RBUF = RDAT;            //save the data to RBUF
  180.                 RING = 0;               //stop receive
  181.                 REND = 1;               //set receive completed flag
  182.             }
  183.             else
  184.             {
  185.                 RDAT >>= 1;
  186.                 if (RXB) RDAT |= 0x80;  //shift RX data to RX buffer
  187.             }
  188.         }
  189.     }
  190.     else if (!RXB)
  191.     {
  192.         RING = 1;                       //set start receive flag
  193.         RCNT = 4;                       //initial receive baudrate counter
  194.         RBIT = 9;                       //initial receive bit number (8 data bits + 1 stop bit)
  195.     }

  196.     if (--TCNT == 0)
  197.     {
  198.         TCNT = 3;                       //reset send baudrate counter
  199.         if (TING)                       //judge whether sending
  200.         {
  201.             if (TBIT == 0)
  202.             {
  203.                 TXB = 0;                //send start bit
  204.                 TDAT = TBUF;            //load data from TBUF to TDAT
  205.                 TBIT = 9;               //initial send bit number (8 data bits + 1 stop bit)
  206.             }
  207.             else
  208. ……………………

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

所有資料51hei下載(如有錯誤,煩請大神批評指導):
STM32: VL53L0X_interrupt.rar (358.49 KB, 下載次數: 432)
51: VL53l0x激光測距.rar (62.09 KB, 下載次數: 566)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏18 分享淘帖 頂2 踩
回復

使用道具 舉報

沙發
ID:295901 發表于 2018-7-28 14:07 | 只看該作者
謝謝分享,樓主辛苦了 好資料,51黑有你更精彩!!!
回復

使用道具 舉報

板凳
ID:63090 發表于 2018-8-28 11:40 | 只看該作者
資料下載了試試,應該能用
回復

使用道具 舉報

地板
ID:63090 發表于 2018-8-28 11:40 | 只看該作者
謝謝分享,樓主辛苦了
回復

使用道具 舉報

5#
ID:470357 發表于 2019-1-18 22:04 | 只看該作者
這個有51的例程么·
回復

使用道具 舉報

6#
ID:388992 發表于 2019-2-15 12:05 | 只看該作者
謝謝樓主的分享!
回復

使用道具 舉報

7#
ID:418864 發表于 2019-2-26 11:31 | 只看該作者
感謝樓主,非常好!
回復

使用道具 舉報

8#
ID:337439 發表于 2019-3-1 09:45 | 只看該作者
樓主,我是小白,有好多看不懂哦,
回復

使用道具 舉報

9#
ID:116773 發表于 2019-3-1 12:21 | 只看該作者
qwevt123 發表于 2019-1-18 22:04
這個有51的例程么·

第2段代碼就是51的啊。
回復

使用道具 舉報

10#
ID:139724 發表于 2019-3-18 10:20 | 只看該作者
謝謝樓主分享!
回復

使用道具 舉報

11#
ID:337439 發表于 2019-3-19 21:24 | 只看該作者
為啥我用不了你的測量程序
回復

使用道具 舉報

12#
ID:480951 發表于 2019-4-3 12:19 | 只看該作者
謝謝樓主分享
回復

使用道具 舉報

13#
ID:500798 發表于 2019-4-4 19:11 | 只看該作者
樓主你的STM32代碼是可以執行的嗎?我發現網友們的代碼都基本是一個流程,但是到我這里就沒辦法執行了,都是沒辦法校準
回復

使用道具 舉報

14#
ID:237360 發表于 2019-4-12 17:27 | 只看該作者
謝謝樓主分享
回復

使用道具 舉報

15#
ID:329116 發表于 2019-5-15 14:50 | 只看該作者
感謝樓主分享
回復

使用道具 舉報

16#
ID:216667 發表于 2019-9-10 22:29 | 只看該作者
謝謝!分享,辛苦了!
回復

使用道具 舉報

17#
ID:670476 發表于 2019-12-22 16:07 | 只看該作者
樓主第2段51代碼可以直接下到單片機里試嗎,看著有點不全呀
回復

使用道具 舉報

18#
ID:658039 發表于 2019-12-25 20:15 | 只看該作者
激光測距比超聲波遠得多,精度也高!頂起!
回復

使用道具 舉報

19#
ID:593927 發表于 2020-2-14 13:55 | 只看該作者
哈哈,剛下載一個STM32的,就看到這個51的,這下省事了。
回復

使用道具 舉報

20#
ID:593927 發表于 2020-2-14 15:29 | 只看該作者
親測51程序可以用,代碼非常非常少,輕松入門。
回復

使用道具 舉報

21#
ID:684386 發表于 2020-2-25 18:28 | 只看該作者
avrbbs 發表于 2020-2-14 15:29
親測51程序可以用,代碼非常非常少,輕松入門。

兄弟與51單片機相連的是單VL53L0模塊還是帶STM32單片機的模塊
回復

使用道具 舉報

22#
ID:164507 發表于 2020-5-20 20:23 | 只看該作者
謝謝分享,樓主辛苦了
回復

使用道具 舉報

23#
ID:666388 發表于 2020-6-2 04:21 來自手機 | 只看該作者
avrbbs 發表于 2020-2-14 13:55
哈哈,剛下載一個STM32的,就看到這個51的,這下省事了。

從哪里下的,求知
回復

使用道具 舉報

24#
ID:217265 發表于 2021-3-4 18:44 | 只看該作者
51的代碼測20mm以下的和700mm以上的好像用不了
回復

使用道具 舉報

25#
ID:882947 發表于 2021-3-5 15:56 | 只看該作者
多謝!好人一生平安!
回復

使用道具 舉報

26#
ID:431670 發表于 2021-8-17 15:18 | 只看該作者
附件里面是 STM32的例程啊,51的完整例程呢?
回復

使用道具 舉報

27#
ID:968460 發表于 2021-9-26 22:09 | 只看該作者
太感興趣了
回復

使用道具 舉報

28#
ID:585636 發表于 2021-11-11 20:08 | 只看該作者
里面的變量 acnt和scnt 是什么意思
回復

使用道具 舉報

29#
ID:979438 發表于 2021-12-21 01:37 來自手機 | 只看該作者
51例程中,您用的什么顯示啊
回復

使用道具 舉報

30#
ID:815693 發表于 2022-3-25 12:53 | 只看該作者
STC的可以用嗎
回復

使用道具 舉報

31#
ID:161115 發表于 2022-5-10 16:02 | 只看該作者
感謝樓主無私的分享
回復

使用道具 舉報

32#
ID:1039984 發表于 2022-7-19 20:19 | 只看該作者
樓主辛苦,學習了
回復

使用道具 舉報

33#
ID:1040821 發表于 2022-7-29 11:03 | 只看該作者
樓主第2段51代碼可以直接下到單片機里試嗎,看著有點不全呀
回復

使用道具 舉報

34#
ID:120085 發表于 2023-6-27 18:30 | 只看該作者
51代碼不全呀,和你展示的不一樣,你檢查下
回復

使用道具 舉報

35#
ID:155485 發表于 2023-8-22 11:01 | 只看該作者

為啥我用不了你的測量程序
回復

使用道具 舉報

36#
ID:1133618 發表于 2024-10-16 19:59 | 只看該作者
wjz2017 發表于 2021-3-4 18:44
51的代碼測20mm以下的和700mm以上的好像用不了

有沒有什么辦法改一下模式啊,改成長距離模式。
回復

使用道具 舉報

37#
ID:208271 發表于 2025-3-19 23:33 | 只看該作者
只測試了51程序,虛擬串口有傳數據,但數據有問題,調試助手顯示空白。后面改了程序,換回原串口,可以顯示。總結如下:
1.測量范圍5-100CM。不在范圍內會顯示error
2.測量精度2CM
3.只要接SCL,SDA,VCC,GND接即可,可以5V供電。
4.以下為串口助手接收的部分數據:
readyerrorreadyerrorreadydistance:0491mm
readyerrorreadyerrorreadydistance:0338mm
readydistance:0342mm
readyerrorreadyerrorreadydistance:0346mm
readydistance:0343mm
readydistance:0337mm
readyerrorreadydistance:0344mm
readyerrorreadyerrorreadydistance:0338mm
readydistance:0335mm
readyerrorreadydistance:0335mm
readydistance:0327mm
readydistance:0269mm
readydistance:0270mm
readydistance:0270mm
readydistance:0256mm
readydistance:0263mm
readydistance:0255mm
readydistance:0249mm
readydistance:0250mm
readydistance:0246mm
readydistance:0246mm
readydistance:0238mm
readydistance:0240mm
readydistance:0240mm
readydistance:0240mm
readydistance:0243mm
readydistance:0201mm
readydistance:0198mm
readydistance:0198mm
readydistance:0196mm
readydistance:0211mm
readyerrorreadydistance:0308mm
readyerrorreadydistance:0308mm
readydistance:0309mm
readydistance:0309mm
readyerrorreadyerrorreadyerrorreadyerrorreadyerrorreadyerrorreadyerrorreadyerrorreadyerrorreadyerrorreadyerrorreadyerrorreadyerrorreadydistance:0331mm
readydistance:0309mm
readydistance:0304mm
readydistance:0327mm
readyerrorreadyerrorreadyerrorreadydistance:0303mm

5.以下為修改后的主程序,可傳數據到串口助手,其它程序不用改。整個復制替換吧
/*****************************
更新日期2017年2月28日

模擬串口參考stc官方程序
來自arduino實例

使用11.0592MHz內部RC;
VL53L0X:
SCL-->P3.3
SDA-->P3.2
串口:
P3.0 RXD
P3.1 TXD
*******************************/

#include"stc.h"
#include"i2c.h"
#include"VL53L0X.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int


/***********全局變量定義**************/
bit flag;
uchar val1;
short val_s;
uchar gbuf[16];
uint acnt ;
uint scnt;
uint dist ;
uchar DeviceRangeStatusInternal;

//#define BAUD  0xFE80                  // 9600bps @ 11.0592MHz
//
//
////sfr AUXR = 0x8E;
//sbit RXB = P3^0;                        //define UART TX/RX port
//sbit TXB = P3^1;

typedef bit BOOL;
typedef unsigned char BYTE;
typedef unsigned int WORD;

BYTE TBUF,RBUF;
BYTE TDAT,RDAT;
BYTE TCNT,RCNT;
BYTE TBIT,RBIT;
BOOL TING,RING;
BOOL TEND,REND;

//void UART_INIT();

char dd[]="0000";



void delay()
{
    unsigned char i;
    for(i=0; i<100; i++);
}
void Delay1ms()                //@11.0592MHz
{
    unsigned char i, j;

    _nop_();
    i = 11;
    j = 190;
    do
    {
        while (--j);
    } while (--i);
}

void delay_ms(unsigned int time)
{
    unsigned char
    i;
    for(i=1; i<=time; i++)
        Delay1ms();
}


//void uartsend_int16(short val)
//{
//    uchar val1;
//    val1=val/10000;
//    while(!TEND);
//    TEND=0;
//    TBUF='0'+val1;
//    TING=1;
//    val1=val%10000/1000;
//    while(!TEND);
//    TEND=0;
//    TBUF='0'+val1;
//    TING=1;
//    val1=val%1000/100;
//    while(!TEND);
//    TEND=0;
//    TBUF='0'+val1;
//    TING=1;
//    val1=val%100/10;
//    while(!TEND);
//    TEND=0;
//    TBUF='0'+val1;
//    TING=1;
//    val1=val%10/1;
//    while(!TEND);
//    TEND=0;
//    TBUF='0'+val1;
//    TING=1;
//}
//void uartprintf(char *s)
//{
//    int i=0;
//    while(s[i]!='\0')
//    {
//        while(!TEND);
//        TEND=0;
//        TBUF=s[i];
//        TING=1;
//        i++;
//    }
//}
//void uartprintenter()
//{
//    while(!TEND);
//    TEND=0;
//    TBUF=0x0d;
//    TING=1;
//        while(!TEND);
//    TEND=0;
//    TBUF=0x0a;
//    TING=1;
//}


void Uart_Init(void)
{
    SCON=0x50;   //UART方式1
    PCON=0x00;  
    TMOD=0x21;  
    TH1=0xFD;
    TL1=0xFD;  
    TR1=1;       
    EA=1;
        ES=0;
}

void Uart_Send_Byte(char c)//UART Send a byte                通過串口發送一個字節
{
        SBUF = c;
        while(!TI);                 
        TI = 0;
}

void Uart_Send_Byte2(char *s)//UART Send a byte                通過串口發送一個字節
{
        int i=0;
while(s[i]!=0)
{
        Uart_Send_Byte(s[i]);
        i++;
}
}

void main()
{
    uchar val = 0;
    int cnt = 0;
//    TMOD = 0x00;                        //timer0 in 16-bit auto reload mode
//    AUXR = 0x80;                        //timer0 working at 1T mode
//    TL0 = BAUD;
//    TH0 = BAUD>>8;                      //initial timer0 and set reload value
//    TR0 = 1;                            //tiemr0 start running
//    ET0 = 1;                            //enable timer0 interrupt
//    PT0 = 1;                            //improve timer0 interrupt priority
//    EA = 1;                             //open global interrupt switch
//
//    UART_INIT();
//    uartprintf("start");

        Uart_Init();
         Uart_Send_Byte2("OK");


    while (1)
    {

        vl53l0x_send(VL53L0X_REG_SYSRANGE_START, 0x01);
        while (cnt < 100) { // 1 second waiting time max
            delay_ms(10);
            val = vl53l0x_read(VL53L0X_REG_RESULT_RANGE_STATUS);
            if (val & 0x01) break;
            cnt++;
        }
        if (val & 0x01) Uart_Send_Byte2("ready");
        else Uart_Send_Byte2("not ready");
//                                uartprintenter();
        //vl53l0x_read_block(0x14, 12);
                                gbuf[0]=vl53l0x_read(0x14);
                                gbuf[7]=vl53l0x_read(0x14+7);
                                gbuf[6]=vl53l0x_read(0x14+6);
                                gbuf[9]=vl53l0x_read(0x14+9);
                                gbuf[8]=vl53l0x_read(0x14+8);
                                gbuf[11]=vl53l0x_read(0x14+11);
                                gbuf[10]=vl53l0x_read(0x14+10);
        acnt = makeuint16(gbuf[7], gbuf[6]);
        scnt = makeuint16(gbuf[9], gbuf[8]);
        dist = makeuint16(gbuf[11], gbuf[10]);
        DeviceRangeStatusInternal = ((gbuf[0] & 0x78) >> 3);
                                if(DeviceRangeStatusInternal==11&&dist>20&&dist<1200)
                                {
                                        Uart_Send_Byte2("distance:");
                                        dd[0]=dist/1000+48;dd[1]=dist%1000/100+48;dd[2]=dist%100/10+48;dd[3]=dist%10+48;
                                        Uart_Send_Byte2(dd);

//                                        uartsend_int16(dist);
                                        Uart_Send_Byte2("mm\r\n");
//                                        uartprintenter();
                                }
                                else
                                {
                                        Uart_Send_Byte2("error");
//                                        uartprintenter();
                                }
        delay_ms(100);

    }
}
//void tm0() interrupt 1 using 1
//{
//    if (RING)
//    {
//        if (--RCNT == 0)
//        {
//            RCNT = 3;                   //reset send baudrate counter
//            if (--RBIT == 0)
//            {
//                RBUF = RDAT;            //save the data to RBUF
//                RING = 0;               //stop receive
//                REND = 1;               //set receive completed flag
//            }
//            else
//            {
//                RDAT >>= 1;
//                if (RXB) RDAT |= 0x80;  //shift RX data to RX buffer
//            }
//        }
//    }
//    else if (!RXB)
//    {
//        RING = 1;                       //set start receive flag
//        RCNT = 4;                       //initial receive baudrate counter
//        RBIT = 9;                       //initial receive bit number (8 data bits + 1 stop bit)
//    }
//
//    if (--TCNT == 0)
//    {
//        TCNT = 3;                       //reset send baudrate counter
//        if (TING)                       //judge whether sending
//        {
//            if (TBIT == 0)
//            {
//                TXB = 0;                //send start bit
//                TDAT = TBUF;            //load data from TBUF to TDAT
//                TBIT = 9;               //initial send bit number (8 data bits + 1 stop bit)
//            }
//            else
//            {
//                TDAT >>= 1;             //shift data to CY
//                if (--TBIT == 0)
//                {
//                    TXB = 1;
//                    TING = 0;           //stop send
//                    TEND = 1;           //set send completed flag
//                }
//                else
//                {
//                    TXB = CY;           //write CY to TX port
//                }
//            }
//        }
//    }
//}
//
//
//
//void UART_INIT()
//{
//    TING = 0;
//    RING = 0;
//    TEND = 1;
//    REND = 0;
//    TCNT = 0;
//    RCNT = 0;
//}

回復

使用道具 舉報

38#
ID:1148059 發表于 2025-4-21 19:41 | 只看該作者
我想請問一下這個測量的怎么改才能讓它測量數據0cm——100cm
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 亚洲最新网址 | 涩涩视频在线观看 | 在线免费观看毛片 | 久久精品国产一区二区电影 | 日韩精品一区二区三区 | 成人精品视频 | 国产成人久久 | 91佛爷在线观看 | av在线免费观看网站 | 国产精品日韩高清伦字幕搜索 | 操射视频 | 国产成人精品一区二区三区 | 国产高清免费在线 | 欧美乱码精品一区二区三区 | 女人精96xxx免费网站p | 亚洲先锋影音 | 大久| av大片在线 | 久久精品中文 | 久久精品国产一区二区电影 | 国产精品视频免费观看 | 国产美女自拍视频 | 在线一区二区三区 | 色综合天天天天做夜夜夜夜做 | 在线电影日韩 | 久草.com | 亚洲欧美日韩一区二区 | 精产国产伦理一二三区 | 日韩在线一区二区 | 国产免费一区二区 | 视频1区 | 国产乱码久久久久久 | 午夜电影网址 | 人人做人人澡人人爽欧美 | av网站免费观看 | 欧美性生交大片免费 | 91传媒在线观看 | 91久久久久久 | 国产精品色| 中文字幕欧美日韩 | 夜夜爽99久久国产综合精品女不卡 |