装载  自  http://bbs.21ic.com/icview-860453-1-1.html

配置串口,利用printf函数输出字符,结果输出的还是ASCII码,这是为什么?难道是我的配置问题?
串口配置是没有问题的,那个printf的配置是在网上找的资料,就不清楚了。。

  1. #include "stm32f4xx.h"
  2. #include <stdio.h>
  3. void OpenCom(void)
  4. {
  5.   USART_InitTypeDef USART_InitStructure;
  6.   NVIC_InitTypeDef NVIC_InitStructure; 
  7.   GPIO_InitTypeDef GPIO_InitStructure;
  8.   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);        
  9.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
  10.   GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);        
  11.   GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
  12.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;
  13.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  14.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  15.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  16.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  17.   GPIO_Init(GPIOA, &GPIO_InitStructure);
  18.   USART_InitStructure.USART_BaudRate = BaudRate;
  19.   USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  20.   USART_InitStructure.USART_StopBits = USART_StopBits_1;
  21.   USART_InitStructure.USART_Parity = USART_Parity_No;
  22.   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  23.   USART_InitStructure.USART_Mode = USART_Mode_Rx|USART_Mode_Tx;
  24.   USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
  25.   USART_Init(USART1, &USART_InitStructure);        /* USART configuration */
  26.   USART_Cmd(USART1, ENABLE); /* Enable USART */
  27.   USART_ClearFlag(USART1, USART_FLAG_TC);
  28.   NVIC_InitStructure.NVIC_IRQChannel=USART1_IRQn;
  29.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
  30.   NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
  31.   NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
  32.   NVIC_Init(&NVIC_InitStructure);  
  33. }
  34. int main(void)
  35. {  
  36.    unsigned char i='a';     
  37.    OpenCom();
  38.    printf("%c\r\n",i);
  39.             
  40. }
  41. int fputc(int ch,FILE *f)
  42. {
  43.   USART_SendData(USART1,(unsigned char)ch);
  44.   while(!(USART1->SR&USART_FLAG_TXE));
  45.   return (ch);
  46. }
复制代码
posted on 2016-04-14 22:51  HDU李少帅  阅读(396)  评论(0编辑  收藏  举报