1.实现中断触发时,对应的LED灯状态取反
2.实现实验现象:对应中断触发时,打印一句话
3.例如按键1按下之后,led3灯状态取反,并且打印一句话:key1 down!!!
gpio.c
/* USER CODE BEGIN 0 */
void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)
{
switch(GPIO_Pin)
{
case GPIO_PIN_7:
printf("key2_down\n");
HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_10);
break;
case GPIO_PIN_8:
printf("key3_down\n");
HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_10);
break;
case GPIO_PIN_9:
HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_8);
printf("key1_down\n");
break;
}
}
/* USER CODE END 0 */
ustart.c
/* USER CODE BEGIN 0 */
int fputc(int ch, FILE* stream)
{
//判断发送寄存器是否
while(!(huart4.Instance->ISR & (0x1<<7)));
//将要发送的数据放入到发送寄存器中
huart4.Instance->TDR = ch;
//判断是否为\n 需要补一个\r
if(ch == '\n')
{
while(!(huart4.Instance->ISR & (0x1<<7)));
huart4.Instance->TDR = '\r';
}
return ch;
}