![]() |
發布時間: 2019-4-13 14:58
正文摘要:采用IAR環境,實現普通模塊測距,串口輸出數據。 代碼如下: #include "VL53L0.h" #include "myiic.h" uint16_t bswap(u8 b[]) { uint16_t val = ((b[0]< ... |
好資料 |
非常不錯的資料,值得參考,謝謝啦 |
非常不錯的資料,值得參考 |
這個才是 main.c /**************************************/ /* WeBee團隊 */ /* Zigbee學習例程 */ /*例程名稱: */ /*建立時間:2012/04/18 */ /*描述:main **************************************/ #include <ioCC2530.h> #include "type.h" #include "clock.h" #include "uart.h" #include "VL53L0.h" #include "myiic.h" #include "delay.h" void main(void) { clockInit(); uartInit(); IIC_Init(); u8 val = 0; u8 gbuf[16]; uint32_t cnt = 0; // uint16_t count[3]; 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) // uartSendString("\r\n readey \r\n",12); // else // uartSendString("\r\n NOT readey \r\n",16); VL53L0X_Read_Len(VL53L0X_Add, 0x14 , 12, gbuf);//讀取數據 // count[0] = makeuint16(gbuf[7], gbuf[6]);//ambient count // count[1] = makeuint16(gbuf[9], gbuf[8]);//signal count // count[2] = makeuint16(gbuf[11], gbuf[10]);//距離 // DeviceRangeStatusInternal = ((gbuf[0] & 0x78) >> 3);//status //打印距離值 uartPutInt16(makeuint16(gbuf[11], gbuf[10])); delay_ms(500); } } |
由于CC2530是無IIC硬件支持的,所以寫了一個,上面應該是采用普通測距模式,由于該芯片是不提供測距函數的,因此是根據ARDUINO的原碼移植的。 |