keil仿真stm32f103系列单片机魔术棒参数设置

默认参数

魔术棒-Debug:/images/stm32/keil仿真stm32f103系列单片机魔术棒参数设置/png1.png

仿真参数

-p后跟的是stm32单片机型号

魔术棒-Debug:/images/stm32/keil仿真stm32f103系列单片机魔术棒参数设置/png2.png

添加仿真串口配置文件

文件格式:.ini

文件内容

1
2
  MODE COM1 115200,0,8,1
  ASSIGN COM1 <S1IN> S1OUT

重写输入/输出函数

重写输入/输出函数是在main.c文件中完成的

重写输入/输出函数之前需要先在main.c文件包含一下"stdio.h"头文件

1
  #include "stdio.h"

在main.c重写printf函数

1
2
3
4
5
6
7
  int fputc(int c, FILE * f)
  {		
	  int ch = 0;
	  ch=c;
	  HAL_UART_Transmit(&huart1,(uint8_t*)&ch,1,1000);//发送串口
	  return c;
  }

在main.c重写scanf函数

1
2
3
4
5
6
  int fgetc(FILE * F)    
  {
	  int ch_r = 0;
	  HAL_UART_Receive (&huart1,(uint8_t*)&ch_r,1,0xffff);//接收
	  return ch_r;
  }

参考链接

https://blog.csdn.net/qq_28317769/article/details/106659139

STM32自学笔记-0-重写printf和scanf

Licensed under CC BY-NC-SA 4.0