本帖最后由 sky.sun.zz 于 2022-9-23 10:22 编辑
【ESK32-30519 + ESK32-21001测评】5、基于HT32F54253的人体额温报警系统
本工程是这次评测活动过程的单独评测结果的综合,利用ESK32-30519 + ESK32-21001硬件资源组成了基于HT32F54253的人体额温报警系统。
硬件资源:
软件资源:
BFTM定时器
LEDC数码管代码库
TKL触摸按键代码库
Buzzer蜂鸣器代码
DVB_LED代码库
USART代码库
实现功能:人体红外测温报警系统。
通过USART串口读取温度传感器数据;
4位LED数码管显示人体温度值。两位整数+1位小数,平时末位数码管显示摄氏度“c”,进入设置模式时末位数码管显示“-”;
4只触摸按键用于设定报警温度的阈值:PD1进入设置模式,PD2退出设置模式,PD3增加报警阈值,PD4减少报警阈值;
当超温时,蜂鸣器声响报警,红色LED亮起报警。
HT32F54235代码库的特点:
1、HT32F54235的LEDC功能使得用户无需关注底层函数就能方便驱动LED数码管;
2、触摸按键克服了普通触点按键寿命短的毛病。
3、蜂鸣器的代码调用非常简单,音频的频率、时长、占空比、次数等在函数调用时一目了然,简单方便。
主要代码
int main(void){
GPIO_Configuration();
LEDC_Configuration();
BFTM_Configuration();
TKL_Configuration();
gURRx_Ptr = gRx_Buffer;
HT32F_DVB_LEDInit(HT_LED1);
HT32F_DVB_LEDInit(HT_LED2);
HT32F_DVB_LEDInit(HT_LED3);
UxART_Configuration();
Buzzer_Fun1();
HT32F_DVB_LEDInit(HT_LED1);
HT32F_DVB_LEDInit(HT_LED2);
HT32F_DVB_LEDInit(HT_LED3);
HT32F_DVB_LEDOn(HT_LED1);
HT32F_DVB_LEDOn(HT_LED3);
while (1){
UxART_RxTest();
if(gIsUpdateChar)
{
if(Flag.SetupStatus==1)
LEDC_Disp(Alarm_Value);
else
LEDC_Disp(Temperature);
gIsUpdateChar = FALSE;
}
Touch_Key_Main_Function();
if(!TKL_Is_Standby())
{
#if (1)
if(TKL_Is_KeyScanCycle()){
for(u8 i=0;i<28;i++)
{
if(TKL_Is_KeyPress(i))
{
switch(i)
{
case 16:
{
while(TKL_Is_KeyPress(16))
{Touch_Key_Main_Function();
}
Flag.SetupStatus=0;
break;
case 17:
{
while(TKL_Is_KeyPress(17))
{
Touch_Key_Main_Function();
}
Flag.SetupStatus=1;
break;
} case 22:
{
KeyData = TKL_Get_AllKeyState();
while(TKL_Is_KeyPress(22))
{
Touch_Key_Main_Function();
}
keyPress= (TKL_Get_AllKeyState());
TKL_Is_KeyPress(22)==SET;
if(keyPress!=SET)
{
if(Flag.SetupStatus==1)
{
if(Alarm_Value>280)
Alarm_Value--;
}
}
break;
}
case 23:
{
while(TKL_Is_KeyPress(23))
{
Touch_Key_Main_Function();
}
if(Flag.SetupStatus==1)
{
if(Alarm_Value<480)
Alarm_Value++;
}
break;
}
default: break;
}
break;
}
}
KeyData = TKL_Get_AllKeyState();
if(KeyData & (1<<0)){
}
else
}
}
#endif
}
}
}
void GPIO_Configuration(void)
{
CKCU_PeripClockConfig_TypeDef CKCUClock = {{0}};
CKCUClock.Bit.AFIO = 1;
CKCUClock.Bit.PA = 1;
CKCU_PeripClockConfig(CKCUClock, ENABLE);
CKCU_PeripClockConfig_TypeDef CKCUClock = {{0}};
CKCUClock.Bit.AFIO = 1;
CKCUClock.Bit.PA = 1;
CKCU_PeripClockConfig(CKCUClock, ENABLE);
AFIO_GPxConfig(HTCFG_LEDC_SEG0_GPIO_ID, HTCFG_LEDC_SEG0_AFIO_PIN, AFIO_FUN_LEDC);
AFIO_GPxConfig(HTCFG_LEDC_SEG1_GPIO_ID, HTCFG_LEDC_SEG1_AFIO_PIN, AFIO_FUN_LEDC);
AFIO_GPxConfig(HTCFG_LEDC_SEG2_GPIO_ID, HTCFG_LEDC_SEG2_AFIO_PIN, AFIO_FUN_LEDC);
AFIO_GPxConfig(HTCFG_LEDC_SEG3_GPIO_ID, HTCFG_LEDC_SEG3_AFIO_PIN, AFIO_FUN_LEDC);
AFIO_GPxConfig(HTCFG_LEDC_SEG4_GPIO_ID, HTCFG_LEDC_SEG4_AFIO_PIN, AFIO_FUN_LEDC);
AFIO_GPxConfig(HTCFG_LEDC_SEG5_GPIO_ID, HTCFG_LEDC_SEG5_AFIO_PIN, AFIO_FUN_LEDC);
AFIO_GPxConfig(HTCFG_LEDC_SEG6_GPIO_ID, HTCFG_LEDC_SEG6_AFIO_PIN, AFIO_FUN_LEDC);
AFIO_GPxConfig(HTCFG_LEDC_SEG7_GPIO_ID, HTCFG_LEDC_SEG7_AFIO_PIN, AFIO_FUN_LEDC);
AFIO_GPxConfig(HTCFG_LEDC_COM0_GPIO_ID, HTCFG_LEDC_COM0_AFIO_PIN, AFIO_FUN_LEDC);
AFIO_GPxConfig(HTCFG_LEDC_COM1_GPIO_ID, HTCFG_LEDC_COM1_AFIO_PIN, AFIO_FUN_LEDC);
AFIO_GPxConfig(HTCFG_LEDC_COM2_GPIO_ID, HTCFG_LEDC_COM2_AFIO_PIN, AFIO_FUN_LEDC);
AFIO_GPxConfig(HTCFG_LEDC_COM3_GPIO_ID, HTCFG_LEDC_COM3_AFIO_PIN, AFIO_FUN_LEDC);
}
void BFTM_Configuration(void)
{
CKCU_SetPeripPrescaler(CKCU_PCLK_BFTM0, CKCU_APBCLKPRE_DIV2);
CKCU_PeripClockConfig_TypeDef CKCUClock = {{ 0 }};
CKCUClock.Bit.BFTM0 = 1;
CKCU_PeripClockConfig(CKCUClock, ENABLE);
BFTM_SetCompare(HT_BFTM0, (SystemCoreClock >> 10));
BFTM_SetCounter(HT_BFTM0, 0);
BFTM_IntConfig(HT_BFTM0, ENABLE);
BFTM_EnaCmd(HT_BFTM0, ENABLE);
NVIC_EnableIRQ(BFTM0_IRQn);
}
void LEDC_Configuration(void)
{
LEDC_InitTypeDef LEDC_InitStruct;
CKCU_PeripClockConfig_TypeDef CKCUClock = {{0}};
CKCUClock.Bit.LEDC = 1;
CKCU_PeripClockConfig(CKCUClock, ENABLE);
LEDC_InitStruct.LEDC_ClockSource = LEDC_SRC_PCLK; LEDC_InitStruct.LEDC_ClockPrescaler = HTCFG_LEDC_CLOCK_PRESCAL - 1;
LEDC_InitStruct.LEDC_DutyClockNumber = HTCFG_LEDC_DUTY_CLOCK_NUMBER;
LEDC_InitStruct.LEDC_COMxEN = HTCFG_LEDC_COM1EN | HTCFG_LEDC_COM2EN |\
HTCFG_LEDC_COM3EN | HTCFG_LEDC_COM4EN; /* Enable COMx
LEDC_InitStruct.LEDC_DeadTime = 0;
LEDC_Init(&LEDC_InitStruct);
LEDC_SetPolarityMode(HTCFG_LEDC_COM1POL | HTCFG_LEDC_COM2POL | HTCFG_LEDC_COM3POL | HTCFG_LEDC_COM4POL,
LEDC_SEG0POL | LEDC_SEG1POL | LEDC_SEG2POL | LEDC_SEG3POL |\
LEDC_SEG4POL | LEDC_SEG5POL | LEDC_SEG6POL | LEDC_SEG7POL,
COMMON_CATHODE);
LEDC_IntConfig(ENABLE);
NVIC_EnableIRQ(LEDC_IRQn);
LEDC_Cmd(ENABLE);
}
void UxART_Configuration(void)
{
CKCU_PeripClockConfig_TypeDef CKCUClock = {{0}};
CKCUClock.Bit.AFIO = 1;
CKCUClock.Bit.HTCFG_UART_RX_GPIO_CLK = 1;
CKCUClock.Bit.HTCFG_UART_IPN = 1;
CKCU_PeripClockConfig(CKCUClock, ENABLE);
GPIO_PullResistorConfig(HTCFG_UART_RX_GPIO_PORT, HTCFG_UART_RX_GPIO_PIN, GPIO_PR_UP);
AFIO_GPxConfig(HTCFG_UART_TX_GPIO_ID, HTCFG_UART_TX_AFIO_PIN, AFIO_FUN_USART_UART);
AFIO_GPxConfig(HTCFG_UART_RX_GPIO_ID, HTCFG_UART_RX_AFIO_PIN, AFIO_FUN_USART_UART);
USART_InitTypeDef USART_InitStructure = {0};
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WORDLENGTH_8B;
USART_InitStructure.USART_StopBits = USART_STOPBITS_1;
USART_InitStructure.USART_Parity = USART_PARITY_NO;
USART_InitStructure.USART_Mode = USART_MODE_NORMAL;
USART_Init(HTCFG_UART_PORT, &USART_InitStructure);
NVIC_EnableIRQ(HTCFG_UART_IRQn);
USART_IntConfig(HTCFG_UART_PORT, USART_INT_RXDR, ENABLE);
USART_TxCmd(HTCFG_UART_PORT, ENABLE);
USART_RxCmd(HTCFG_UART_PORT, ENABLE);
NVIC_EnableIRQ(HTCFG_UART_IRQn);
USART_IntConfig(HTCFG_UART_PORT, USART_INT_RXDR, ENABLE);
USART_TxCmd(HTCFG_UART_PORT, ENABLE);
USART_RxCmd(HTCFG_UART_PORT, ENABLE);
}
void UxART_RxTest(void)
{
uint8_t i;
uint16_t temp;
uint16_t CRC;
CRC=0x00;
if (gURRx_Length >= 6)
{
for(i=0;i<5;i++)
CRC +=gRx_Buffer;
CRC &=0x00ff;
if(CRC==gRx_Buffer[5])
{
temp=gRx_Buffer[3]<<8;
temp |=gRx_Buffer[4];
Temperature=BCD2HEX(temp);
}
gURRx_Length = 0;
}
}
void LEDC_Disp(uint16_t data)
{
DiapBuf[0]=NumberChar[data%1000/100];
DiapBuf[1]=NumberChar[data%100/10]|0x02;
DiapBuf[2]=NumberChar[data%10];
if(Flag.SetupStatus==1)
DiapBuf[3]=0x40;
else
{
DiapBuf[3]=0x68;
if(Alarm_Value<Temperature)
Buzzer_Fun1();
HT32F_DVB_LEDOn(HT_LED1);
HT32F_DVB_LEDOff(HT_LED2);
HT32F_DVB_LEDOn(HT_LED3);
}
LEDC_SetData(HTCFG_LEDC_COM_D1, DiapBuf[0]);
LEDC_SetData(HTCFG_LEDC_COM_D2, DiapBuf[1]);
LEDC_SetData(HTCFG_LEDC_COM_D3, DiapBuf[2]);
LEDC_SetData(HTCFG_LEDC_COM_D4, DiapBuf[3]);
}
void Buzzer_Fun1(void)
{
HT32F_DVB_LEDOn(HT_LED2);
HT32F_DVB_LEDOff(HT_LED1);
HT32F_DVB_LEDOff(HT_LED3);
Buzzer_Init(0);
Buzzer_Start(4, 3000, 150, 50);
while (Buzzer_IsFinish() == FALSE);
}
视频(这个视频链接一直弄不起来,管管有空帮忙看看我哪里操作错误)
https://v.youku.com/v_show/id_XNTkwMzU2Mzk5Ng==.html?firsttime=30[/media
[media=x,500,375][/media]
合泰的ESK32-30519 + ESK32-21001套件以其丰富的硬件和软件资源,为用户提供了一个方便实用的开发平台,使得开发者能以较短的时间开发出经济实用的好产品。
感谢21IC,感谢合泰提供这次难得的锻炼机会。
|