三、部分代码
//单片机头文件
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
//网络协议层
#include "onenet.h"
//网络设备
#include "esp8266.h"
//硬件驱动
#include "delay.h"
#include "usart.h"
//C库
#include <string.h>
#include "PWM.h"
#include "jidianqi.h"
#include "YuYin.h"
#include "MP3.h"
#include "SysTick.h"
#include "oled.h"
char T[5]={0,0,0};
char H[5]={0,0,0};
u16 temperature=0,humidity=0;
char ret;
u8 hump_temp[10];
unsigned short timeCount = 0; //发送间隔变量
unsigned char *dataPtr = NULL;
short flag = 0;
u8 Target1=0;
u8 Target2=0;
u8 Target3=0;
u8 Target4=0;
u8 all_staus = 0;
u8 Open_JumpEdge=0;
u8 WakeUp_Flag=0;
/功能函数
/*
************************************************************
* 函数名称: Hardware_Init
*
* 函数功能: 硬件初始化
*
* 入口参数: 无
*
* 返回参数: 无
*
* 说明: 初始化单片机功能以及外接设备
************************************************************
*/
void Hardware_Init(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //中断控制器分组设置
delay_init(); //systick初始化
Usart3_Init(115200); //串口3,驱动ESP8266用
PWM_Init(); //初始化PWM
ESP8266_Init(); //初始化ESP8266
LED_Config(); //初始化LED指示灯或者说是继电器
YuYin_Init(); //语音识别初始化
MP3_Init(); //播放模块初始化
SysTick_Init(); //公共定时器初始化
OLED_Init(); //OLED屏初始化
}
/*
************************************************************
* 函数名称: Keep_Connet_Esp8266
*
* 函数功能: 不断上传数据,使之保持接入物联网平台
*
* 入口参数: 无
*
* 返回参数: 无
*
* 说明: 一旦停止数据上传,物联网平台会断开
************************************************************
*/
void Keep_Connet_Esp8266 (void)
{
if(++timeCount >= 2000) //发送间隔20s
{
OneNet_SendData(); //发送数据
timeCount = 0;
ESP8266_Clear();
}
dataPtr = ESP8266_GetIPD(0);
if(dataPtr != NULL)
OneNet_RevPro(dataPtr);
delay_ms(10);
}
/*
************************************************************
* 函数名称: main
*
* 函数功能:
*
* 入口参数: 无
*
* 返回参数: 0
*
* 说明:
***
*********************************************************
*/
int main(void)
{
Hardware_Init(); //初始化外围硬件
while(OneNet_DevLink()) //接入OneNET
delay_ms(500);
OLED_CLS();
ShowSmartTrash(); //显示“智能垃圾桶”
Show_Author(); //显示“设计·作者名“
//ShowTemperature(); //显示”温湿度”
while(1)
{
Keep_Connet_Esp8266();
if(YuYin_RX_STA == 1)
{
if(MP3_State() == 0)
{
if(YuYin_RX_CMD==49 || YuYin_RX_CMD==50)
{
WakeUp_Flag = 1;
MP3_Star(5);
}
else if(WakeUp_Flag == 1)
{
WakeUp_Flag=0;
if(YuYin_RX_CMD%4 == 1)
{
MP3_Star(1);
Target1 = 1;
Show_chiyu();
}
else if(YuYin_RX_CMD%4 == 2)
{
MP3_Star(2);
Target2 = 1;
Show_qita();
}
else if(YuYin_RX_CMD%4 == 3)
{
MP3_Star(3);
Target3 = 1;
Show_youhai();
}
else
{
MP3_Star(4);
Target4 = 1;
Show_kehuishou();
}
}
}
YuYin_RX_STA = 0;
}
if(SysTick_JumpEdge(&Open_JumpEdge, &SysTickBit.Time1s)==1)
{
if(Target1 != 0)
{
Target1++;
TIM_SetCompare1(TIM4,700);
if(Target1>6)
{
TIM_SetCompare1(TIM4,500);
Target1 = 0;
ShowTrashNoPeople();
}
}
if(Target2 != 0)
{
Target2++;
TIM_SetCompare2(TIM4,900);
if(Target2>6)
{
TIM_SetCompare2(TIM4,600);
ShowTrashNoPeople();
Target2 = 0;
}
}
if(Target3 != 0)
{
Target3++;
TIM_SetCompare4(TIM4,900); //有害
if(Target3>6)
{
TIM_SetCompare4(TIM4,500);
ShowTrashNoPeople();
Target3 = 0;
}
}
if(Target4 != 0)
{
Target4++;
TIM_SetCompare3(TIM4,900); //可回收
if(Target4>6)
{
TIM_SetCompare3(TIM4,550);
ShowTrashNoPeople();
Target4 = 0;
}
}
}
switch( flag )
{
case 1 :GPIO_SetBits(GPIOA,GPIO_Pin_1); break;
case 2 :GPIO_ResetBits(GPIOA, GPIO_Pin_1); break;
case 3 :TIM_SetCompare1(TIM4,700);break;
case 4 :TIM_SetCompare1(TIM4,500);break;
case 5 :TIM_SetCompare2(TIM4,900);break;
case 6 :TIM_SetCompare2(TIM4,600);break;
case 7 :TIM_SetCompare4(TIM4,900);break;
case 8 :TIM_SetCompare4(TIM4,500);break;
case 9 :TIM_SetCompare3(TIM4,900);break;
case 10:TIM_SetCompare3(TIM4,550);break;
}
}
}
|