91视频丝瓜-91视频完整版高清-91视频网-91视频网店-91视频网或将从此无大神-91视频网入口

您好,歡迎訪問上海現易電子元器件有限公司網站!

021-51870898
021-51870898   18019251567
4新聞資訊
您的位置: 首頁 ->  新聞資訊 -> 單片機

?STM32下Keil IDE中Printf函數的使用

文章出處:單片機 責任編輯:上海現易電子元器件有限公司 發表時間:2018-05-20

請在MDK(keil)工程屬性的“Target“-》”Code Generation“中勾

選”Use MicroLIB

 

前提是你有一個完整keil的工程 比如ADC的調試的時候很多時候用到串口 這里教你怎么樣使

用Printf 函數

紅色字句為重點!!!!!

若使得在程序中使用Printf需做一下幾步
1,輸入輸出文件包含#include
2,在程序下添加宏定義代碼

/* Private function prototypes -----------------------------------------------*/

#ifdef __GNUC__
         /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf set to 'Yes') calls __io_putchar() */
       #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
     #else
      #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
    #endif /* __GNUC__ */
 
   /* Private functions ---------------------------------------------------------*/

3,添加如下2個函數 usart配置 和 重定向 C庫的printf函數

 /* System Clocks Configuration */


void RCC_Configuration(void)
{    
  /* Enable GPIO clock */
  RCC_APB2PeriphClockCmd(USARTy_GPIO_CLK | USARTz_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);

#ifndef USE_STM3210C_EVAL
  /* Enable USARTy Clock */
  RCC_APB2PeriphClockCmd(USARTy_CLK, ENABLE); 
#else
  /* Enable USARTy Clock */
  RCC_APB1PeriphClockCmd(USARTy_CLK, ENABLE); 
#endif
  /* Enable USARTz Clock */
  RCC_APB1PeriphClockCmd(USARTz_CLK, ENABLE);  
}

/* System Clocks Configuration */

 

/* Configure the GPIO ports */

void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

#ifdef USE_STM3210C_EVAL
  /* Enable the USART3 Pins Software Remapping */
  GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);
  
  /* Enable the USART2 Pins Software Remapping */
  GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);  
#elif defined(USE_STM3210B_EVAL) || defined(USE_STM32100B_EVAL)
  /* Enable the USART2 Pins Software Remapping */
  GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
#endif

  /* Configure USARTy Rx as input floating */
  GPIO_InitStructure.GPIO_Pin = USARTy_RxPin;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
  
  /* Configure USARTz Rx as input floating */
  GPIO_InitStructure.GPIO_Pin = USARTz_RxPin;
  GPIO_Init(USARTz_GPIO, &GPIO_InitStructure);  
  
  /* Configure USARTy Tx as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = USARTy_TxPin;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);

  /* Configure USARTz Tx as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = USARTz_TxPin;
  GPIO_Init(USARTz_GPIO, &GPIO_InitStructure); 
}

/* Configure the GPIO ports */

 

/* USARTy configuration ------------------------------------------------------*/

void USART_Configuration()
{

USART_InitTypeDef USART_InitStructure;
 USART_InitStructure.USART_BaudRate = 230400;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_Even;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  
  /* Configure USARTy */
  USART_Init(USARTy, &USART_InitStructure);
  /* Configure USARTz */
  USART_Init(USARTz, &USART_InitStructure);

}

/* USARTy configuration ------------------------------------------------------*/

 

/*  Retargets the C library printf function to the USART.  */
PUTCHAR_PROTOTYPE
{
USART_SendData(USART1, (uint8_t) ch);


while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{}

return ch;
}

/*  Retargets the C library printf function to the USART.  */

3,然后就可以在main()調用

printf("The is a example!" );

printf("%s%c%c%c%c%c%s",
           "#**",
           Value/256,Value%6,
          '&',
           Value_2/256,Value_2%6,
          "**%");

之類的輸出函數


上海現易電子元器件有限公司 版權所有 未經授權禁止復制或鏡像

CopyRight 2020-2025 www.urqm.cn All rights reserved   滬ICP備2020031792號

友情鏈接:

電話

易經理

18019251567

微信

易經理

易經理

頂部

咨詢
主站蜘蛛池模板: 亚洲 色 欧美 爱 视频 日韩 | 色婷婷小说 | 狂野欧美激情性XXXX在线观看 | 九九九精品 | 亚洲精品123区 | 插影院 | 久久人人槡人妻人人玩夜色AV | 麻豆自制传媒 最新网站 | 超乳w真性中出し冲田杏梨101 | 免费人成黄页在线观看日本 | 亚洲 校园 春色 另类 图片 | 国产免费1卡2卡 | 国产毛片女人高潮叫声 | 亚洲三级欧美 | 牛牛社区 | 国精产品999一区二区三区有限 | 99热久久这里只精品国产WWW | 老司机深夜福利在线观看 | 伦韩国理片在线观看 | 在线 国产 有码 亚洲 欧美 | 亚洲九九视频 | 久久WWW免费人成一看片 | 亚洲不卡影院 | 欧美亚洲色倩在线观看 | 8x成人永久在线观看视频 | 亚洲一区二区三区在线播放 | 又黄又刺激好看的小说 | 真实国产乱子露脸 | 成人黄色免费在线观看 | 装睡被陌生人摸出水好爽 | 打光屁屁vk丨视频 | 亚洲男人97色综合久久久 | 日本特爽特黄特刺激大片 | 中文字幕不卡一区二区 | 久久久久久久综合狠狠综合 | 精品国产经典三级在线看 | 精品久久久久久国产 | 亚洲精品一区二区三区四区久久 | 国产人妻精品久久久久久很牛 | 婷婷五色 | 99热这里只有精品8 99热这里只有精品9 |