LORA 網(wǎng)關(guān) 代碼
單片機源程序如下:
- /******************************************************************
- * 文件:main.c
- * 功能:主函數(shù)入口
- * 日期:2018-02-16
- * 作者:zx
- * 版本:Ver.1.0 | 最初版本
- *
- * Copyright (C) 2017 zx. All rights reserved.
- *******************************************************************/
- #include "stdio.h"
- #include "string.h"
- #include "DELAY/Delay.h"
- #include "ADC/ADC.h"
- #include "LED/LED.h"
- #include "NVIC/NVIC.h"
- #include "IIC/IIC.h"
- #include "OLED/OLED.h"
- #include "UART/uart.h"
- #include "NetWork.h"
- #include "TLink.h"
- #include "SPIx/SPIx.h"
- #include "SX1278/SX1278.h"
- #include "NodeBus.h"
- DeviceSta_Strcture device = {0};
- DeviceBlock DeviceBlock_StructureArray[2];
- int main(void)
- {
- u8 i = 0;
- /*初始化各外設*/
- initSysTick();
- initADC();
- initUART();
- initUART2();
- initLED();
- initIIC();
- initOLED();
- initSPIx(SPI2);
- initSX1278();
-
- initNVIC(NVIC_PriorityGroup_2);//開啟UART2的接收和空閑中斷
- formatScreen(0x00);//清屏
- /*打印ESP8266啟動信息到OLED*/
- if(initESP8266()!=0)
- {
- showString(0,0,"init ok!",FONT_16_EN);
- }else
- {
- showString(0,0,"init error!",FONT_16_EN);
- }
- if(connectAP(SSID,PWD)!=0)
- {
- showString(0,2,"conn ap ok!",FONT_16_EN);
- }else
- {
- showString(0,2,"con ap error!",FONT_16_EN);
- }
- if(connectTlink()!=0)
- {
- showString(0,4,"conn TLink ok!",FONT_16_EN);
- }else
- {
- showString(0,4,"conn TLink no!",FONT_16_EN);
- }
- Delay_ms(1000);//讓數(shù)據(jù)保持一段時間
- formatScreen(0x00);
- showCNString(32,0,"風媒電子",FONT_16_CN);
- showString(0,2,"Hum :",FONT_16_EN);
- showString(0,4,"Temp:",FONT_16_EN);
- showString(0,6,"Lux :",FONT_16_EN);
- while (1)
- {
- /*數(shù)據(jù)采集顯示*/
- if(++i>30)
- {
- i = 0;
- sendMasterAsk(SLAVE1_ADDR,OP_R_SENSOR,PRAM_R_ALL);//主機發(fā)送指令
- receiveSlaveAck(SLAVE1_ADDR,OP_R_SENSOR,PRAM_R_ALL,DeviceBlock_StructureArray);//接收從機數(shù)據(jù)
- Delay_ms(100);
- while(receiveSlaveAck(SLAVE1_ADDR,OP_R_SENSOR,PRAM_R_ALL,DeviceBlock_StructureArray)!=FRAME_OK && ++i<10)//等待從機響應
- {
- Delay_ms(100);
- }
- i = 0;
- device.Humidity = DeviceBlock_StructureArray[SLAVE1_ADDR].Humidity;
- device.Temperature = DeviceBlock_StructureArray[SLAVE1_ADDR].Temperature;
- device.Lux = DeviceBlock_StructureArray[SLAVE1_ADDR].Lux;
- showNumber(40,2,device.Humidity,DEC,3,FONT_16_EN);
- showNumber(40,4,device.Temperature,DEC,3,FONT_16_EN);
- showNumber(40,6,device.Lux,DEC,4,FONT_16_EN);
- sendDeviceStatus(&device);
- }
- toggleLED();
- Delay_ms(100);
- }
- }
復制代碼
所有資料51hei提供下載:
31_LoRa網(wǎng)關(guān).7z
(211.89 KB, 下載次數(shù): 50)
2019-3-16 00:55 上傳
點擊文件名下載附件
LORA 網(wǎng)關(guān)代碼 下載積分: 黑幣 -5
|