| 
              #include <stdio.h>#include <stm32f10x.h>
 
 // 一定要在工程属性的Target->Code Generation中勾选Use MicroLIB复选框
 
 int fgetc(FILE *fp)
 {
 while ((USART1->SR & USART_SR_RXNE) == 0);
 return USART1->DR;
 }
 
 int fputc(int ch, FILE *fp)
 {
 USART1->DR = ch;
 while ((USART1->SR & USART_SR_TXE) == 0);
 return ch;
 }
 
 int main(void)
 {
 int n;
 RCC->APB2ENR = RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_USART1EN;
 GPIOA->CRH = 0x000004b0;
 GPIOA->CRL = 0xb4bb0000;
 
 USART1->BRR = 0x1d4c; // 波特率: 9600
 USART1->CR1 = USART_CR1_UE | USART_CR1_TE | USART_CR1_RE; // 打开串口发送和接收
 
 puts("请输入一个数: ");
 scanf("%d", &n);
 printf("您输入的数字是: %d\n", n);
 printf("这个数乘上2后是: %d\n", n * 2);
 
 while (1);
 }
 
 |