基于RT-THREAD的定时鱼缸喂食器设计

芯片为STM32F407,利用仿真完成设计,末尾为仿真图。

线程一通过DS18B20自动测量温度,当温度大于30℃或小于20℃时通过使能PC6串口使LED1灯发光进行报警;

线程二通过RTC时钟获取现实时间,每天的凌晨24点自动投食,通过使能PC7串口控制LED2灯发光0.5s;

LCD实时显示当前温度与学生姓名及学号内容;

用EMWIN取模软件将汉字取模并通过LCD显示;

通过RT-THREAD多线程控制,线程一控制温度的相关内容,线程二控制RTC时钟及LCD显示屏内容

移植时需要注意对于外设串口的配置

下述为thread线程的代码。
#include "threads.h"
#include "stm32f4xx_hal.h"
#include "gpio.h"

/* USER CODE BEGIN Includes */
#include "ILI9341B8.H"
#include "DS18B20.H"
RTC_DateTypeDef SDATE;
RTC_TimeTypeDef STIME;
extern uint8_t data[5];
extern int16_t TEMP;
uint8_t date[2];
//extern uint16_t HUM,TEM;
static char *s;
void SystemClock_Config(void);
//Ïß³Ìthread1
void led1()
{
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_SET);
}
void led2()
{
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET);
}
void thread1(void* parameter)
{

//µ÷¶ÈÆ÷Ëø,½øÈëÁÙ½çÇø
rt_enter_critical();
LCD_Inital();//ÀïÃæµÄÑÓʱҪ»»³É²Ù×÷ϵͳµÄÑÓʱ
LCD_Clear(BLACK);
//Í˳öÁÙ½çÇø
rt_exit_critical();

while(1)
{
ds18_start();
rt_sprintf(s,"%3d",TEMP);
disstr(10,10,s,BLUE);
if(TEMP>30||TEMP<20)
{
led1();
}
else
{
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_6,GPIO_PIN_RESET);

}
rt_thread_delay(50);
}
}

//Ïß³Ìthread2
void thread2(void* parameter)
{
while(1)
{

char *w;
//µ÷¶ÈÆ÷Ëø,½øÈëÁÙ½çÇø
rt_enter_critical();
rt_exit_critical();


HAL_RTC_GetDate(&hrtc,&SDATE,RTC_FORMAT_BIN);
switch(SDATE.WeekDay)
{
case 1:w="Monday";break;
case 2:w="Tuesday";break;
case 3:w="Wednesday";break;
case 4:w="Thursday";break;
case 5:w="Friday";break;
case 6:w="Saturday";break;
case 0:w="Sunday";break;
}
date[0]=SDATE.WeekDay;
if(date[1]!=date[0])
{
date[1]=date[0];
led2();
rt_thread_delay(500);
}
else
{
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET);
}
rt_thread_delay(50);
}

}

//Ïß³Ìthread3
void thread3(void* parameter)
{

}

仿真图

 

 

posted @ 2021-07-15 17:06  通信小九  阅读(122)  评论(0编辑  收藏  举报