赛题
部分程序展示
主函数刷新:
while (1)
{
key=scankey();
key_function(key);
Interface_function();
Alarm_function();
}
按键模块:
void key_function(uint8_t key)
{
if(key==1)
{
if(flag_Interface==0)
{
sprintf((char *)Line1_buf," RTC-SETTING ");
LCD_DisplayStringLine(Line1,Line1_buf);
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
RTC->CR&=~(1<<8);
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
LED_state&=~(1<<1);
LED_state|=(1<<0);
LED_ALL(LED_state);
flag_Interface=1;
flag_set_time=0;
}
else if(flag_Interface==1)
{
set_time(GetTime.Hours,GetTime.Minutes,GetTime.Seconds);
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc);
RTC->CR|=(1<<8);
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc);
sprintf((char *)Line1_buf," MAIN ");
LCD_DisplayStringLine(Line1,Line1_buf);
USART_RTC_buf[8]=GetTime.Hours/10+48; USART_RTC_buf[9]=GetTime.Hours%10+48;
USART_RTC_buf[11]=GetTime.Minutes/10+48; USART_RTC_buf[12]=GetTime.Minutes%10+48;
USART_RTC_buf[14]=GetTime.Seconds/10+48; USART_RTC_buf[15]=GetTime.Seconds%10+48;
HAL_UART_Transmit(&huart1,USART_RTC_buf,sizeof(USART_RTC_buf),50);
X24c02_buf[1]++;
m24c02_write(X24c02_buf+1,DATA_ARR+1,1);HAL_Delay(5);
LED_state|=(1<<1);
LED_ALL(LED_state);
flag_Interface=0;
}
else if(flag_Interface==2) {if(++flag_set_time==3) {flag_set_time=0;}}
}
else if(key==2)
{
if(flag_Interface==0)
{
sprintf((char *)Line1_buf," ALARM-SETTING ");
Line3_buf[2]='A';Line3_buf[3]='l';Line3_buf[4]='a';
Line3_buf[5]='r';Line3_buf[6]='m';
LCD_DisplayStringLine(Line1,Line1_buf);
LCD_DisplayStringLine2(Line3,2,Line3_buf+2,5);
flag_Interface=2;flag_set_time=0;
LED_state&=~(1<<2);
LED_state|=(1<<0);
LED_ALL(LED_state);
}
else if(flag_Interface==2)
{
set_alarm(time_alarm_clock[0],time_alarm_clock[1],time_alarm_clock[2]);
sprintf((char *)Line1_buf," MAIN ");
Line3_buf[2]=' ';Line3_buf[3]=' ';Line3_buf[4]='R';
Line3_buf[5]='T';Line3_buf[6]='C';
LCD_DisplayStringLine(Line1,Line1_buf);
LCD_DisplayStringLine2(Line3,2,Line3_buf+2,5);
USART_Alarm_buf[10]=time_alarm_clock[0]/10+48; USART_Alarm_buf[11]=time_alarm_clock[0]%10+48;
USART_Alarm_buf[13]=time_alarm_clock[1]/10+48; USART_Alarm_buf[14]=time_alarm_clock[1]%10+48;
USART_Alarm_buf[16]=time_alarm_clock[2]/10+48; USART_Alarm_buf[17]=time_alarm_clock[2]%10+48;
HAL_UART_Transmit(&huart1,USART_Alarm_buf,sizeof(USART_Alarm_buf),50);
LED_state|=(1<<2);
LED_ALL(LED_state);
X24c02_buf[2]++;
X24c02_buf[3]=time_alarm_clock[0];
X24c02_buf[4]=time_alarm_clock[1];
X24c02_buf[5]=time_alarm_clock[2];
m24c02_write(X24c02_buf+2,DATA_ARR+2,4);HAL_Delay(5);
flag_Interface=0;
}
else if(flag_Interface==1) {if(++flag_set_time==3) {flag_set_time=0;}}
}
else if(key==3)
{
if(flag_Interface==1)
{
if(flag_set_time==0) {if(++GetTime.Hours>=24) {GetTime.Hours=0;}}
else if(flag_set_time==1) {if(++GetTime.Minutes>=60) {GetTime.Minutes=0;}}
else if(flag_set_time==2) {if(++GetTime.Seconds>=60) {GetTime.Seconds=0;}}
}
else if(flag_Interface==2)
{
if(flag_set_time==0) { if(++time_alarm_clock[flag_set_time]>=24) {time_alarm_clock[flag_set_time]=0;} }
else { if(++time_alarm_clock[flag_set_time]>=60) {time_alarm_clock[flag_set_time]=0;} }
}
}
else if(key==4)
{
if(flag_Interface==1)
{
if(flag_set_time==0) {if(--GetTime.Hours>=24) {GetTime.Hours=23;}}
else if(flag_set_time==1) {if(--GetTime.Minutes>=60) {GetTime.Minutes=59;}}
else if(flag_set_time==2) {if(--GetTime.Seconds>=60) {GetTime.Seconds=59;}}
}
else if(flag_Interface==2)
{
if(flag_set_time==0) { if(--time_alarm_clock[flag_set_time]>=24) {time_alarm_clock[flag_set_time]=23;} }
else { if(--time_alarm_clock[flag_set_time]>=60) {time_alarm_clock[flag_set_time]=59;} }
}
}
}
LCD模块:
void Interface_function(void)
{
static u8 last_time;
if(get_sub(TASK_TIMES.Interface_TIME)==0)
{
TASK_TIMES.Interface_TIME=get_time()+Interface_time;
if(flag_Interface==0)
{
HAL_RTC_GetTime(&hrtc,&GetTime,RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc,&GetDate,RTC_FORMAT_BIN);
Line3_buf[8]=GetTime.Hours/10+48; Line3_buf[9]=GetTime.Hours%10+48;
Line3_buf[11]=GetTime.Minutes/10+48; Line3_buf[12]=GetTime.Minutes%10+48;
Line3_buf[14]=GetTime.Seconds/10+48; Line3_buf[15]=GetTime.Seconds%10+48;
}
else if(flag_Interface==1)
{
Line3_buf[8]=GetTime.Hours/10+48; Line3_buf[9]=GetTime.Hours%10+48;
Line3_buf[11]=GetTime.Minutes/10+48; Line3_buf[12]=GetTime.Minutes%10+48;
Line3_buf[14]=GetTime.Seconds/10+48; Line3_buf[15]=GetTime.Seconds%10+48;
}
else if(flag_Interface==2)
{
Line3_buf[8]=time_alarm_clock[0]/10+48; Line3_buf[9]=time_alarm_clock[0]%10+48;
Line3_buf[11]=time_alarm_clock[1]/10+48; Line3_buf[12]=time_alarm_clock[1]%10+48;
Line3_buf[14]=time_alarm_clock[2]/10+48; Line3_buf[15]=time_alarm_clock[2]%10+48;
}
if((flag_Interface!=0)&&(flag_set_time==0)) {LCD_SetTextColor(Red);LCD_DisplayStringLine2(Line3,8,Line3_buf+8,2);LCD_SetTextColor(White); }
else { LCD_DisplayStringLine2(Line3,8,Line3_buf+8,2); }
if((flag_Interface!=0)&&(flag_set_time==1)) {LCD_SetTextColor(Red);LCD_DisplayStringLine2(Line3,11,Line3_buf+11,2);LCD_SetTextColor(White); }
else { LCD_DisplayStringLine2(Line3,11,Line3_buf+11,2); }
if((flag_Interface!=0)&&(flag_set_time==2)) {LCD_SetTextColor(Red);LCD_DisplayStringLine2(Line3,14,Line3_buf+14,2);LCD_SetTextColor(White); }
else { LCD_DisplayStringLine2(Line3,14,Line3_buf+14,2); }
if(flag_Interface==0)
{
if(last_time!=Line3_buf[15])
{
LED_state^=(1<<0);
LED_ALL(LED_state);
last_time=Line3_buf[15];
}
}
}
}
闹钟模块:
void Alarm_function(void)
{
if(flag_sAlarm==1)
{
TASK_TIMES.sAlarm_TIME=get_time()+sAlarm_time;
flag_sAlarm=2;
LED_state^=(1<<7);
LED_ALL(LED_state);
}
else if(flag_sAlarm==2)
{
if(get_sub(TASK_TIMES.sAlarm_TIME)==0)
{
LED_state^=(1<<7);
LED_ALL(LED_state);
flag_sAlarm=0;
}
}
}
下载链接: https://pan.baidu.com/s/1LMECSy3GuABduu42YUJdSQ 提取码:qy2o
|