找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3709|回復: 2
收起左側

VL53L0X程序

[復制鏈接]
ID:237696 發(fā)表于 2017-10-7 20:38 | 顯示全部樓層 |閱讀模式
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "myiic.h"
#include "VL53L0.h"



//串口1發(fā)送一個字符
void usart1_send_char(u8 c[10],u8 len)
{
                        u8 t;
                //        printf("\r\n您發(fā)送的消息為:\r\n");
                        for(t=0;t<len;t++)
                        {
                                USART_SendData(USART1, c[t]);         //向串口1發(fā)送數(shù)據(jù)
                                while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待發(fā)送結束
                        }
        //                printf("\r\n\r\n");//插入換行  
}


int main(void)
{

        u8 val = 0;
  u8 gbuf[16];
        u8 DeviceRangeStatusInternal;

        uint32_t cnt = 0;
        uint16_t count[3];

        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設置系統(tǒng)中斷優(yōu)先級分組2
        delay_init(168);    //初始化延時函數(shù)
        uart_init(115200);        //初始化串口波特率為115200
  IIC_Init();


        while(1)
        {
                 VL53L0X_Write_Byte(VL53L0X_REG_SYSRANGE_START, 0x01);

                 while(cnt < 100)
                 {
                                delay_ms(10);
                                val = VL53L0X_Read_Byte(VL53L0X_REG_RESULT_RANGE_STATUS);
                                if( val & 0x01) break;
                                cnt++;
                 }

                 if( val & 0x01)
                                printf("\r\n readey \r\n");
                 else
                                printf("\r\n not readey \r\n");

                 VL53L0X_Read_Len(VL53L0X_Add, 0x14 , 12, gbuf);

                 count[0] = makeuint16(gbuf[7], gbuf[6]);
                 count[1] = makeuint16(gbuf[9], gbuf[8]);
                 count[2] = makeuint16(gbuf[11], gbuf[10]);
                 DeviceRangeStatusInternal = ((gbuf[0] & 0x78) >> 3);

                 printf("\r\n ambient count = %4d signal count = %4d distance = %4d status = %d ",count[0],count[1],count[2],DeviceRangeStatusInternal);
                // data_analy(count[2]);

                delay_ms(1000);
        }            
}

回復

使用道具 舉報

ID:246093 發(fā)表于 2017-11-4 21:18 | 顯示全部樓層
請問這個計算算法是什么啊
回復

使用道具 舉報

ID:294147 發(fā)表于 2018-3-19 17:36 | 顯示全部樓層
感謝分享
回復

使用道具 舉報

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

本版積分規(guī)則

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

Powered by 單片機教程網(wǎng)

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