//单片机头文件
#include "stm32f10x.h"
//硬件驱动
#include "delay.h"
#include "usart.h"
#include "light.h"
#include "lcd1602.h"
#include "sht20.h"
#include "i2c.h"
#include "key.h"
void Hardware_Init(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //中断控制器分组设置
Delay_Init(); //Systick初始化,用于普通的延时
Usart1_Init(115200); //初始化usart1,波特率115200
LIGHT_Init(); //初始化
Lcd1602_Init(); //LCD1602初始化
Key_Init();
IIC_Init();
UsartPrintf(USART1, "\r\n麒麟座开发板-V2.2\r\n"); //打印
UsartPrintf(USART1, "欢迎登陆中移物联官方网站:open.iot.10086.cn\r\n");
}
int main(void)
{
Hardware_Init(); //硬件初始化
Lcd1602_DisString(0x80, "OneNet");
while(1)
{
switch(Keyboard())
{
case KEY1DOUBLE:
UsartPrintf(USART1, "按键1--双击\r\n");
LIGHT_GetVoltag();
Lcd1602_DisString(0xC0, "light:%f", light_info.voltag);
UsartPrintf(USART1, "光强: %f\r\n", light_info.voltag);
DelayMs(1000);
break;
case KEY0DOWN:
UsartPrintf(USART1, "按键1--单击\r\n");
SHT20_GetValue();
Lcd1602_DisString(0xC0, "%0.1fC,%0.1f%%", sht20_info.tempreture, sht20_info.humidity);
UsartPrintf(USART1, "%0.1fC,%0.1f%%\r\n", sht20_info.tempreture, sht20_info.humidity);
DelayMs(200);
break;
}
DelayXms(10);
}
}
四
//单片机头文件
#include "stm32f10x.h"
//网络协议层
#include "onenet.h"
//网络设备
#include "esp8266.h"
//硬件驱动
#include "delay.h"
#include "beep.h"
#include "usart.h"
#include "i2c.h"
#include "sht20.h"
#include "lcd1602.h"
#include "key.h"
//C库
#include <string.h>
void Hardware_Init(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //中断控制器分组设置
Delay_Init(); //systick初始化
Usart1_Init(115200); //串口1,打印信息用
Usart2_Init(115200); //串口2,驱动ESP8266用
IIC_Init(); //IIC初始化
Beep_Init(); //蜂鸣器初始化
Lcd1602_Init(); //LCD1602初始化
Key_Init();
UsartPrintf(USART_DEBUG, " Hardware init OK\r\n");
}
int main(void)
{
unsigned short timeCount = 0; //发送间隔变量
unsigned char *dataPtr = NULL;
Hardware_Init(); //初始化外围硬件
ESP8266_Init(); //初始化ESP8266
Beep_Set(BEEP_ON); //鸣叫提示接入成功
DelayXms(250);
Beep_Set(BEEP_OFF);
while(1)
{
switch(Keyboard())
{
case KEY0DOWN:
UsartPrintf(USART1, "按键1--单击\r\n");
SHT20_GetValue();
Lcd1602_DisString(0xC0, "%0.1fC,%0.1f%%", sht20_info.tempreture, sht20_info.humidity);
UsartPrintf(USART1, "%0.1fC,%0.1f%%\r\n", sht20_info.tempreture, sht20_info.humidity);
case KEY1DOWN:
UsartPrintf(USART1, "按键1--单击\r\n");
if(++timeCount >= 500) //发送间隔5s
{
SHT20_GetValue();
UsartPrintf(USART_DEBUG, "OneNet_SendData\r\n");
OneNet_SendData();
timeCount = 0;
ESP8266_Clear();
}
dataPtr = ESP8266_GetIPD(0);
if(dataPtr != NULL)
OneNet_RevPro(dataPtr);
DelayXms(10);
Lcd1602_DisString(0x80, "success");
}
}
}