本次实验是为了了解RT-thread的工作流程以及简单的实验RT来进行一个学习
实验材料:STM32c8t6+1.44寸TFT显示屏+红外传感器+分光棱镜
实验结果:可以进行红外定时选择,实验成功分为三个线程做任务
线程一:开机时间显示
//APP1
static void led1_thread_entry(void* parameter)
{
rt_uint8_t hour=0,munite=0,second=0;
rt_uint8_t dispBuff[100];
//Show_Picture();
Demo_Menu();
while (1)
{
if(second<59) {
second++;
}
else
{
second=0;
munite++;
if(munite==60)
{
second=0;
munite=0;
hour++;
if(hour==24)
{
second=0;
munite=0;
hour=0;
}
}
}
sprintf(dispBuff,"-%02d:%02d:%02d-",hour,munite,second);
Draw_Font24B(4,30,RED,dispBuff);
// Draw_Font16B(4,40,YELLOW,dispBuff);//8*16 “ABC”
rt_thread_delay(1000); /* 延时500个tick */
}
}
?线程二:红外遥控判断
//APP2
static void APP2_thread_entry(void* parameter)
{
rt_err_t uwRet = RT_EOK;
rt_uint8_t key=0;
rt_uint8_t dispBuff[100];
rt_uint8_t t=0;
rt_uint8_t *str=0;
while(1)
{
key=Remote_Scan();
if(key)
{
switch(key)
{
case 162:
//1
str= "*计时器 10 min*";
munite = 10;
hour=0;
second=0;
break;
case 98:
//2
str= "*计时器 20 min*";
munite = 20;
hour=0;
second=0;
break;
case 226://3
str= "*计时器 30 min*";
munite = 30;
hour=0;
second=0;
break;
case 34://4
str= "*计时器 40 min*";
munite = 40;
hour=0;
second=0;
break;
case 2://5
str= "*计时器 50 min*";
munite = 50;
hour=0;
second=0;
break;
case 194://6
str= "*计时器 60 min*";
munite = 60;
hour=0;
second=0;
break;
case 224://7
str= "*计时器 90 min*";
hour = 1;
munite = 30;
second=0;
break;
case 168://8
str= "* 计时器 2 h *";
hour = 1;
munite = 60;
second=0;
break;
case 144://9
str= "* 计时器 3 h *";
hour = 2;
munite = 60;
second=0;
break;
case 152:
str= "detected code 0";
break;
case 104:
str= "detected code *";
break;
case 176:
str= "detected code #";
break;
case 24:
str= "detected code ↑";
break;
case 16:
str= "detected code ←";
break;
case 74:
str= "detected code ↓";
break;
case 90:
str= "detected code →";
break;
case 56:
str= "detected code OK ";
break;
default:
str= "EMOURE";
break;
}
// uwRet = rt_thread_resume(APP3_thread);/* 恢复APP3线程! */
// if(RT_EOK == uwRet)
// {
// rt_kprintf("恢复APP3线程成功!\n");
// }
// else
// {
// rt_kprintf("恢复APP3线程失败!失败代码:0x%lx\n",uwRet);
// }
Draw_Font16B(4,100,BRRED,str); //显示SYMBOL
}
}
}
?线程三:计时器
//APP3
static void APP3_thread_entry(void* parameter)
{
rt_err_t uwRet = RT_EOK;
rt_uint8_t dispBuff[100];
while (1)
{
if(second>0) {
second--;
}
else
{
second=59;
munite--;
//time++;
if(munite==0)
{
munite=60;
second=59;
hour--;
if(hour==0)
{
munite=60;
second=59;
// uwRet = rt_thread_suspend(APP3_thread);/* 挂起APP3线程 */
// if(RT_EOK == uwRet)
// {
// rt_kprintf("挂起APP3线程成功!\n");
// }
// else
// {
// rt_kprintf("挂起APP3线程失败!失败代码:0x%lx\n",uwRet);
// }
}
}
}
sprintf(dispBuff," time:%02d:%02d:%02d",hour,munite,second);
Draw_Font16B(4,80,YELLOW,dispBuff);//8*16 “ABC”
rt_thread_delay(980); /* 延时500个tick */
}
}
程序代码:01.RT红外定时器.zip-OS文档类资源-CSDN下载
|