联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2018-06-23 03:00

/**************************************************

**************************************************/

#include "main.h"

#include "delay.h"

#include "nb_io.h"

#include "nb_deive.h"

#include "nb_lwm2m.h"

#include "rtc.h"

#include "i2c.h"

#include "oled.h"

#include "sht20.h"

#include "key.h"

#include "timer.h"

#include "FreeRTOS.h"

#include "task.h"




nb_device NB_LED={LED_OBJ,LED_INST,LED_RES,NB_Bool,1,""};

nb_device NB_TEMP={TEMP_OBJ,TEMP_INST,TEMP_RES,NB_Float,1,""};

nb_device NB_HUMP={HUMP_OBJ,HUMP_INST,HUMP_RES,NB_Float,1,""};


#define START_TASK_PRIO1

#define START_STK_SIZE120

void start_task(void * pvParameters);  //任务函数

TaskHandle_t StartTask_Handler;//任务句柄

#define LED_TASK_PRIO2

#define LED_STK_SIZE120

void LED_task(void * pvParameters);

TaskHandle_t LedTask_Handler;//任务句柄


#define NET_TASK_PRIO3

#define NET_STK_SIZE256

void NET_task(void * pvParameters);

TaskHandle_t NetTask_Handler;//任务句柄


#define NBHAND_TASK_PRIO4

#define NBHAND_STK_SIZE1000

void NbHand_task(void * pvParameters);

TaskHandle_t NbHandTask_Handler;//任务句柄


#define RTC_TASK_PRIO5

#define RTC_STK_SIZE120

void RTC_task(void * pvParameters);

TaskHandle_t RTCTask_Handler;//任务句柄


#define DATAUP_TASK_PRIO6

#define DATAUP_STK_SIZE500

void DATAUP_task(void * pvParameters);

TaskHandle_t DATAUP_Handler;//任务句柄


#define SHT20_TASK_PRIO7

#define SHT20_STK_SIZE200

void SHT20_task(void * pvParameters);

TaskHandle_t SHT20Task_Handler;//任务句柄


int main(void)

{

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);//中断优先级分组4

 delay_init(32);

USART1_Init(115200);

IIC_Init();

LED_Init();

RELAY_Init();

BEEP_Init();

keyInit();

My_RTC_Init();

OLED_Init();

TIM2_Init();

KEY_GPIO_Init();

printf("欢迎使用骑士智能科技 EVB_IOT_M1 开发板\r\n");

OLED_ClearScreen();

OLED_DisChar16x16(0, 16, an);

OLED_DisChar16x16(0, 32, shang);

OLED_DisChar16x16(0, 48, zhi);

OLED_DisChar16x16(0, 64, neng);

OLED_DisChar16x16(0, 80, ke);

OLED_DisChar16x16(0, 96, ji);

OLED_DisString8x16(2,24,"EVB_IOT_M1");

OLED_DisChar16x16(4, 0, wen);

OLED_DisChar16x16(4, 16, du);

OLED_DisString8x16(4,32,":");


OLED_DisChar16x16(6, 0, shi);

OLED_DisChar16x16(6, 16, du);

OLED_DisString8x16(6,32,":");

xTaskCreate((TaskFunction_t) start_task,

(char*) "start_task",

(uint16_t) START_STK_SIZE,

(void * ) NULL,

(UBaseType_t) START_TASK_PRIO,

(TaskHandle_t*) &StartTask_Handler);

   vTaskStartScheduler();          //开启任务调度

}


void start_task(void * pvParameters)

{

xTaskCreate((TaskFunction_t) LED_task,

(char*) "led_task",

(uint16_t) LED_STK_SIZE,

(void * ) NULL,

(UBaseType_t) LED_TASK_PRIO,

(TaskHandle_t*) &LedTask_Handler);

xTaskCreate((TaskFunction_t) NET_task,

(char*) "net_task",

(uint16_t) NET_STK_SIZE,

(void * ) NULL,

(UBaseType_t) NET_TASK_PRIO,

(TaskHandle_t*) &NetTask_Handler);

xTaskCreate((TaskFunction_t) NbHand_task,

(char*) "nbhand_task",

(uint16_t) NBHAND_STK_SIZE,

(void * ) NULL,

(UBaseType_t) NBHAND_TASK_PRIO,

(TaskHandle_t*) &NbHandTask_Handler);

xTaskCreate((TaskFunction_t) RTC_task,

(char*) "RTC_task",

(uint16_t) RTC_STK_SIZE,

(void * ) NULL,

(UBaseType_t) RTC_TASK_PRIO,

(TaskHandle_t*) &RTCTask_Handler);

xTaskCreate((TaskFunction_t) DATAUP_task,

(char*) "DATA_UP",

(uint16_t) DATAUP_STK_SIZE,

(void * ) NULL,

(UBaseType_t) DATAUP_TASK_PRIO,

(TaskHandle_t*) &DATAUP_Handler);

xTaskCreate((TaskFunction_t) SHT20_task,

(char*) "SHT20_task",

(uint16_t) SHT20_STK_SIZE,

(void * ) NULL,

(UBaseType_t) SHT20_TASK_PRIO,

(TaskHandle_t*) &SHT20Task_Handler);

vTaskDelete(StartTask_Handler);

}


void LED_task(void * pvParameters)

{

printf("LED is ok\r\n");

while(1)

{

if(!nbdeviceinfo.nb_work)

{

LED1=0;

vTaskDelay(600);

LED1=1;

vTaskDelay(1200);

}

else if(nbdeviceinfo.nb_work)

{

LED1=0;

vTaskDelay(200);

LED1=1;

vTaskDelay(500);

}

}

}


void NET_task(void * pvParameters)

{

printf("NET is ok\r\n");

NB_DEVICE_IO_Init();

NB_DEVICE_Reset();

while(1)

{


if(!nbdeviceinfo.device_ok)

{

vTaskSuspend(DATAUP_Handler);

if(!NB_DEVICE_Check())

nbdeviceinfo.device_ok=1;

}

if(nbdeviceinfo.device_ok)

if(!nbdeviceinfo.nb_work)

NB_DEVICE_Init();

if(nbdeviceinfo.nb_work)

{

if(!nblwm2minfo.flge)

{

NB_Lwm2m_Init();

if(nblwm2minfo.flge)

{

vTaskDelay(5000);

nblwm2minfo.ConnectOk=1;

vTaskResume(DATAUP_Handler);

}

}

}

else

vTaskDelay(100);

}

}


void NbHand_task(void * pvParameters)

{

printf("NbHand is ok!!!!\r\n");

while(1)

{

if(nbioinfo.rev_status)

{

if(nblwm2minfo.cmd_status)

NB_Lwm2m_DataHand();

 if(nbdeviceinfo.cmd_status)

NB_DEVICE_CmdHand();

else

NB_Lwm2m_CmdHand();

}

vTaskDelay(100);

}

}


void DATAUP_task(void * pvParameters)

{

u8 flge;

printf("DATAUP is ok\r\n");

nblwm2minfo.initstep=0;

while(1)

{

if(nblwm2minfo.flge&&nblwm2minfo.ConnectOk)

{

vTaskSuspend(NetTask_Handler);

nblwm2minfo.flge=0;

}

if(nblwm2minfo.ConnectOk==1)

{

if(nblwm2minfo.relay_flge)

{

LED3=0;

RELAY=0;

vTaskDelay(1000);

LED3=1;

RELAY=1;

nblwm2minfo.relay_flge=0;

nblwm2minfo.up_flge=1;

}

if(nblwm2minfo.up_flge)

{

//if(!NB_ResUP(&NB_TEMP))

//{

//printf("TEMP Resource Success\r\n");

//nblwm2minfo.initstep++;

//}

//vTaskDelay(200);

//if(!NB_ResUP(&NB_HUMP))

//{

//printf("HUMP Resource Success\r\n");

//nblwm2minfo.initstep++;

//}

if(flge!=LED3_IN)

{

flge=LED3_IN;

nblwm2minfo.up_flge=1;

}

sprintf(NB_LED.buf,"%d",!flge);

if(!NB_ResUP(&NB_LED))

{

printf("LED Resource Success\r\n");

nblwm2minfo.initstep++;

}

nblwm2minfo.up_flge=0;

}

}

vTaskDelay(500);

}

}



void RTC_task(void * pvParameters)

{

RTC_TimeTypeDef RTC_TimeStructure;

RTC_DateTypeDef RTC_DateStructure;

printf("RTC is ok\r\n");

while(1)

{

if(nbdeviceinfo.nb_work)

{

RTC_GetTime(RTC_Format_BIN,&RTC_TimeStructure);

RTC_GetDate(RTC_Format_BIN,&RTC_DateStructure);

nblwm2minfo.frist_time=RTC_TimeStructure.RTC_Seconds;

//if((nblwm2minfo.frist_time-nblwm2minfo.last_time)>30||(nblwm2minfo.last_time-nblwm2minfo.frist_time)>30)

//{

//nblwm2minfo.up_flge=1;

//nblwm2minfo.last_time=nblwm2minfo.frist_time;

//}

printf("\r\ndata:20%02d-%02d-%02d,time:%02d:%02d:%02d\r\n",RTC_DateStructure.RTC_Year,RTC_DateStructure.RTC_Month,RTC_DateStructure.RTC_Date,RTC_TimeStructure.RTC_Hours,RTC_TimeStructure.RTC_Minutes,RTC_TimeStructure.RTC_Seconds);

printf("温度:%0.1f  湿度:%0.1f\r\n",sht20Info.tempreture,sht20Info.humidity);

}

vTaskDelay(1000);

}

}


void SHT20_task(void * pvParameters)

{

printf("SHT20 is ok\r\n");

while(1)

{

SHT20_GetValue();

sprintf(NB_TEMP.buf,"%0.2f",sht20Info.tempreture);

sprintf(NB_HUMP.buf,"%0.2f",sht20Info.humidity);

OLED_DisString8x16(4,40,"%0.1fC",sht20Info.tempreture);

OLED_DisString8x16(6,40,"%0.1f%%",sht20Info.humidity);

vTaskDelay(1000);

}

}


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp