有偿代查代码
目录
一、题目
二、程序代码
1. 显示功能
2. 按键功能
3. 串口功能
4. LED指示灯功
一、题目
二、程序代码
1. 显示功能
void LCD_Proc(void)
{F1=80000000/((PRESCALER1+1)*(AUTORELOAD1+1));F7=80000000/((PRESCALER7+1)*(AUTORELOAD7+1));D1_LCD=(COMPARE1+1)*100/(AUTORELOAD1+1);D7_LCD=(COMPARE7+1)*100/(AUTORELOAD7+1);if(LCD_Pag==1){sprintf((char *)LCD_Str," PA1 ");LCD_DisplayStringLine(Line2,LCD_Str);sprintf((char *)LCD_Str," F:%dHz ",F1);LCD_DisplayStringLine(Line3,LCD_Str);sprintf((char *)LCD_Str," D:%d%% ",D1_LCD);LCD_DisplayStringLine(Line4,LCD_Str);}else if(LCD_Pag==2){sprintf((char *)LCD_Str," PA7 ");LCD_DisplayStringLine(Line2,LCD_Str);sprintf((char *)LCD_Str," F:%dHz ",F7);LCD_DisplayStringLine(Line3,LCD_Str);sprintf((char *)LCD_Str," D:%d%% ",D7_LCD);LCD_DisplayStringLine(Line4,LCD_Str);}
}
2. 按键功能
void Key_Proc(void)
{if(uwTick-uwTick_Key<=10) return;uwTick_Key=uwTick;key_val=Key_Scan();key_down=key_val&(key_val^key_old);key_up=~key_val&(key_val^key_old);key_old=key_val;if((key_down==1)&&(control_mode==1)){if(LCD_Pag==1){Hz_Num1++;if(Hz_Num1==11){Hz_Num1=1;}switch(Hz_Num1){case 1:AUTORELOAD1=999;PRESCALER1=79;break; case 2:AUTORELOAD1=499;PRESCALER1=79;break;case 3:AUTORELOAD1=999/3;PRESCALER1=79;break;case 4:AUTORELOAD1=249;PRESCALER1=79;break;case 5:AUTORELOAD1=199;PRESCALER1=79;break;case 6:AUTORELOAD1=999/6;PRESCALER1=79;break;case 7:AUTORELOAD1=999/7;PRESCALER1=79;break;case 8:AUTORELOAD1=999;PRESCALER1=9;break;case 9:AUTORELOAD1=111;PRESCALER1=79;break;case 10:AUTORELOAD1=99;PRESCALER1=79;break;}}else if(LCD_Pag==2){Hz_Num7++;if(Hz_Num7==11){Hz_Num7=1;}switch(Hz_Num7){case 1:AUTORELOAD7=999;PRESCALER7=79;break; case 2:AUTORELOAD7=499;PRESCALER7=79;break;case 3:AUTORELOAD7=999/3;PRESCALER7=79;break;case 4:AUTORELOAD7=249;PRESCALER7=79;break;case 5:AUTORELOAD7=199;PRESCALER7=79;break;case 6:AUTORELOAD7=999/6;PRESCALER7=79;break;case 7:AUTORELOAD7=999/7;PRESCALER7=79;break;case 8:AUTORELOAD7=999;PRESCALER7=9;break;case 9:AUTORELOAD7=111;PRESCALER7=79;break;case 10:AUTORELOAD7=99;PRESCALER7=79;break;}}
// key_down=0;}else if((key_down==2)&&(control_mode==1)){if(LCD_Pag==1){Duty_Num1++;if(Duty_Num1>=10){Duty_Num1=1;}D1=Duty_Num1*10;COMPARE1=((AUTORELOAD1+1)*D1/100)-1;}else if(LCD_Pag==2){Duty_Num7++;if(Duty_Num7>=10){Duty_Num7=1;}D7=Duty_Num7*10;COMPARE7=((AUTORELOAD7+1)*D7/100)-1;}key_down=0;}else if((key_down==3)&&(control_mode==1)){if(LCD_Pag==1){LCD_Pag=2;}else if(LCD_Pag==2){LCD_Pag=1;}}else if(key_down==4){if(control_mode==1){control_mode=2;}else if(control_mode==2){control_mode=1;}}
}
3. 串口功能
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{if(control_mode==2){ if(Rx_Buff[0]==0x40){Tx_sign=3;}else if(Rx_Buff[0]==0x23){Tx_sign=4;}else{Tx_sign=2;}}else{Tx_sign=1;}HAL_UART_Receive_IT(&huart1,Rx_Buff,1);
}
void Usart_Tx(void)
{if(Tx_sign==1){sprintf((char *)Tx_Str,"KEY CONTROL\r\n");HAL_UART_Transmit(&huart1,Tx_Str,strlen((const char *)Tx_Str),50);}else if(Tx_sign==2){sprintf((char *)Tx_Str,"ERROR\r\n");HAL_UART_Transmit(&huart1,Tx_Str,strlen((const char *)Tx_Str),50);}else if(Tx_sign==3){LCD_Pag=1;}else if(Tx_sign==4){LCD_Pag=2;}Tx_sign=0;
}
4. LED指示灯功
void LED_Proc(uint8_t led)
{HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);HAL_GPIO_WritePin(GPIOC, led<<8, GPIO_PIN_RESET);HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
}
void LED_Show(void)
{if(uwTick-uwTick_led<=100) return;uwTick_led=uwTick; if(LED_num==1){LED_num=0;}else if(LED_num==0){LED_num=1;}if(control_mode==1){LED|=0x04;}else{LED&=0xfb;}if((LED_num==1)&&(LCD_Pag==1))//0.1秒闪烁标志 - 页面索引{if(F1>F7){LED|=0x01;LED&=0xfd;}}else if((LED_num==1)&&(LCD_Pag==2)){if(F1<F7){LED|=0x02;LED&=0xfe;}}else{LED&=0xfc;}}