任务一:实现红色LED灯每一秒闪烁,并且串口5输出当前时间,输出格式(任务1:2019-10-07 10:10:14);任务二:实现绿色LED灭4秒亮1秒,并且每5秒使用串口5输出当前时间,输出格式(任务2:2019-10-07 10:10:14)
任务函数
char *timeFORMAT="ccyy-MM-dd hh:mm:ss";
char para[40];
void gettime(LPSYSTEMTIME lpsystime)
{
getSystemTimeInt(lpsystime);
DatetimeToStr(lpsystime,(int8_t*)timeFORMAT,(int8_t *)para);
Uart_SendData(E_UART5,(uint8_t *)para,strlen(para));
}//从系统中获取时间
void taskfunction1(void *pvParameters)
{
SYSTEMTIME stime1;
uint8_t thread1[5]={'t','a','s','k','1'};
uint8_t enter1[2]={'\r','\n'};
for( ;; )
{
GPIO_SetBits(GPIOE,GPIO_Pin_7);
GPIO_SetBits(GPIOD,GPIO_Pin_13);
vTaskDelay(1000);
GPIO_ResetBits(GPIOE,GPIO_Pin_7);
GPIO_ResetBits(GPIOD,GPIO_Pin_13);
vTaskDelay(1000);
Uart_SendData(E_UART5,thread1,5);
gettime(&stime1);
Uart_SendData(E_UART5,enter1,2);
}
}//任务1实现
void taskfunction2(void *pvParameters)
{
SYSTEMTIME stime2;
uint8_t thread2[5]={'t','a','s','k','2'};
uint8_t enter2[2]={'\r','\n'};
for( ;; )
{
GPIO_SetBits(GPIOE,GPIO_Pin_8);
GPIO_SetBits(GPIOD,GPIO_Pin_14);
vTaskDelay(1000);
GPIO_ResetBits(GPIOE,GPIO_Pin_8);
GPIO_ResetBits(GPIOD,GPIO_Pin_14);
vTaskDelay(5000);
Uart_SendData(E_UART5,thread2,5);
gettime(&stime2);
Uart_SendData(E_UART5,enter2,2);
}
}//任务2实现
主函数
int main (void)
{
struct rtc_time RTCtime={0,0,0,1,1,2019,1};//初始化RTC,注意这里不能定义指针,要定义数组
struct rtc_time NEWtime={0,13,15,17,10,2019,3};
RTC_CheckAndConfig(&RTCtime);
WriteTime(&NEWtime);//写入系统时间
Led_Init();
Sys_Init();
Door_Init();
Uart_Init(E_UART5,9600,UART_Parity_No);
xTaskCreate((TaskFunction_t )taskfunction1, //任务函数
(const char * )"task1", //任务名称
(uint16_t )128, //任务堆栈大小
(void* )NULL, //传递给任务函数的参数
(UBaseType_t )1, //任务优先级
(TaskHandle_t* )NULL); //任务句柄
xTaskCreate((TaskFunction_t )taskfunction2,
(const char * )"task2",
(uint16_t )128,
(void* )NULL,
(UBaseType_t )1,
(TaskHandle_t* )NULL);
vTaskStartScheduler(); //开启任务调度
}
结果