void ShowMessageLBJ(POCSAG_RESULT* POCSAG_Msg,float rssi,uint8_t lqi) { char MessageLBJ[4][7] = {{0},{0},{0},{0}} char MessageLBJ[3][7] = {{0},{0},{0}}; for(uint8_t i = 0;i < 5;i++) { strncpy(MessageLBJ[i],POCSAG_Msg->txtMsg+i5,5); } OLED_ShowString(68,0,MessageLBJ[0],16); OLED_Display_16x16(1,0,MessageLBJ[0]); OLED_Display_16x16(28,2,MessageLBJ[1][2],16); OLED_Display_16x16(38,2,MessageLBJ[1][3],16); OLED_Display_16x16(78,2,MessageLBJ[2],16); OLED_Display_16x16(18,4,MessageLBJ[3],16); OLED_ShowString(58,6,Link_Info[0],16); OLED_ShowString(148,6,Link_Info[1],16); } 这个是STM32F103C8T6和ssd1306的显示函数,现在是收到消息直接显示,不会息屏,能不能帮我把它修改为收到消息后常亮6秒,如果有新消息就替换显示,不使用HAL_GetTick();
时间: 2024-03-08 12:46:51 浏览: 54
poc.rar_ pocsag_pocsag_pocsag解码
可以使用定时器来实现常亮6秒的功能,具体实现步骤如下:
1. 定义一个全局变量,用于表示当前是否有新消息。
```c
static uint8_t has_new_message = 0;
```
2. 在收到新消息时,将变量设置为1,并且重新显示消息。
```c
void ShowMessageLBJ(POCSAG_RESULT* POCSAG_Msg,float rssi,uint8_t lqi) {
char MessageLBJ[4][7] = {{0},{0},{0},{0}};
char MessageLBJ[3][7] = {{0},{0},{0}};
for(uint8_t i = 0;i < 5;i++) {
strncpy(MessageLBJ[i],POCSAG_Msg->txtMsg+i5,5);
}
OLED_ShowString(68,0,MessageLBJ[0],16);
OLED_Display_16x16(1,0,MessageLBJ[0]);
OLED_Display_16x16(28,2,MessageLBJ[1][2],16);
OLED_Display_16x16(38,2,MessageLBJ[1][3],16);
OLED_Display_16x16(78,2,MessageLBJ[2],16);
OLED_Display_16x16(18,4,MessageLBJ[3],16);
OLED_ShowString(58,6,Link_Info[0],16);
OLED_ShowString(148,6,Link_Info[1],16);
has_new_message = 1; // 设置有新消息
}
```
3. 配置一个定时器,每隔6秒检查一次是否有新消息,如果有则重新显示消息,并将变量设置为0。
```c
void TIM2_IRQHandler(void) {
if(TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) {
if(has_new_message) { // 如果有新消息
// 重新显示消息
OLED_Clear();
ShowMessageLBJ(&POCSAG_Msg, rssi, lqi);
has_new_message = 0; // 将变量设置为0
}
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
}
}
void TIM2_Configuration(void) {
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
TIM_TimeBaseStructure.TIM_Period = 59999; // 定时器溢出时间为6秒
TIM_TimeBaseStructure.TIM_Prescaler = 7199; // 定时器时钟为72MHz,分频系数为7200
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM2, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
```
4. 在 `main` 函数中调用 `TIM2_Configuration` 函数配置定时器即可。
```c
int main(void) {
// ...
TIM2_Configuration();
// ...
}
```
阅读全文