ps:以前写的一个超级简单的多级菜单(hh)
#include "task.h"
#include "led.h"
#include "oled.h"
#include "delay.h"
#include "sys.h"
/*
---目前只有三个任务---
--需要更多可自行添加--
*/
u8 task = 0; /*任务项目*/
u8 task_sign = 1; /*任务标志*/
u8 key_sign = 0; /*按键标志*/
void Task_manage()
{
switch(task)
{
case 0: Task_Display(); break;
case 1: Task_1(); break;
case 2: Task_2(); break;
case 3: Task_3(); break;
}
}
void Task_Display()
{
if(IN1 == 0)
{
while( IN1 == 0 );
task_sign --;
if(task_sign <= 0)
{
task_sign = 3; /*task_sign 溢出就清零*/
}
}
if(IN3 == 0)
{
while( IN3 == 0 );
task_sign ++;
if(task_sign >= 4)
{
task_sign = 1; /*task_sign 溢出就清零*/
}
}
if(task_sign == 1)
{
OLED_ShowString(16,0,"Task_manage",16,1);
OLED_ShowString(30,16,"Task_One",16,0);
OLED_ShowString(30,32,"Task_Two",16,1);
OLED_ShowString(30,48,"Task_Three",16,1);
if(IN2 == 0)
{
OLED_Clear();
while(IN2 == 0);
Task_1(); /*确定进入任务1*/
}
}
else if(task_sign == 2)
{
OLED_ShowString(16,0,"Task_manage",16,1);
OLED_ShowString(30,16,"Task_One",16,1);
OLED_ShowString(30,32,"Task_Two",16,0);
OLED_ShowString(30,48,"Task_Three",16,1);
if(IN2 == 0)
{
OLED_Clear();
while(IN2 == 0);
Task_2(); /*确定进入任务2*/
}
}
else if(task_sign == 3)
{
OLED_ShowString(16,0,"Task_manage",16,1);
OLED_ShowString(30,16,"Task_One",16,1);
OLED_ShowString(30,32,"Task_Two",16,1);
OLED_ShowString(30,48,"Task_Three",16,0);
if(IN2 == 0)
{
OLED_Clear();
while(IN2 == 0);
Task_3(); /*确定进入任务3*/
}
}
else; /**防止跑飞*/
}
void Task_1()
{
/*任务1进程*/
while(1)
{
OLED_Refresh(); /*实时刷新 */
OLED_ShowString(35,0,"Task_One",16,1);
OLED_ShowString(20,16,"HR1:",16,1);
OLED_ShowString(20,32,"HR2:",16,1);
OLED_ShowNum(55,16,GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_8),1,16,1);
OLED_ShowNum(55,32,GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9),1,16,1);
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_8) == 0)
{
LED0 = 0;
}
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_8) == 1)
{
LED0 = 1;
}
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9) == 0)
{
LED0 = 0;
}
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9) == 1)
{
LED0 = 1;
}
/*Run进程1*/
if(IN4 == 0)
{
key_sign = 1; /*按键标志清零*/
while(IN4 == 0);
OLED_Clear();
break;
}
}
}
void Task_2()
{
/*任务2进程*/
while(1)
{
OLED_Refresh(); /*实时刷新 */
OLED_ShowString(35,0,"Task_Two",16,1);
//getVoltage();
OLED_ShowString(20,32,"No_Task!!!!!!",16,1);
/*Run进程2*/
if(IN4 == 0)
{
key_sign = 1; /*按键标志清零*/
while(IN4 == 0);
OLED_Clear();
break;
}
}
}
void Task_3()
{
/*任务3进程*/
while(1)
{
OLED_Refresh(); /*实时刷新 */
OLED_ShowString(30,0,"Task_Three",16,1);
OLED_ShowString(20,32,"No_Task!!!!!!",16,1);
/*Run进程3*/
if(IN4 == 0)
{
key_sign = 1; /*按键标志清零*/
while(IN4 == 0);
OLED_Clear();
break;
}
}
}
版权声明:本文为CSDN博主「Letitia-Ron」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_53718880/article/details/122301858
暂无评论