日韩一区二区三区精品,欧美疯狂xxxxbbbb牲交,热99re久久免费视精品频,人妻互换 综合,欧美激情肉欲高潮视频

歷史上的今天

今天是:2025年05月20日(星期二)

正在發(fā)生

2018年05月20日 | STM32下Keil IDE中Printf函數(shù)的使用

發(fā)布者:幸福時刻 來源: eefocus關(guān)鍵字:STM32  Keil  IDE  Printf函數(shù) 手機(jī)看文章 掃描二維碼
隨時隨地手機(jī)看文章

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

選”Use MicroLIB

 

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

用Printf 函數(shù)

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

若使得在程序中使用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個函數(shù) usart配置 和 重定向 C庫的printf函數(shù)

 /* 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()調(diào)用

printf("The is a example!" );

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

之類的輸出函數(shù)


關(guān)鍵字:STM32  Keil  IDE  Printf函數(shù) 引用地址:STM32下Keil IDE中Printf函數(shù)的使用

上一篇:STM32 在 KEIL 下使用 SWV 輸出調(diào)試信息
下一篇:STM32的ADC多通道采集的實現(xiàn)

推薦閱讀

特斯拉(上海)有限公司已于5月10號在上海成立,根據(jù)國家企業(yè)信息信息公示系統(tǒng),登記機(jī)關(guān)為浦東新區(qū)市場監(jiān)管局,法定代表人顯示為Xiaotong Zhu,公司住所為浦東新區(qū)南匯新城鎮(zhèn)。這意味著特斯拉正式落戶中國上海。?據(jù)國家企業(yè)信用信息公示系統(tǒng)顯示,特斯拉(上海)有限公司于5月10日獲上海浦東新區(qū)市場監(jiān)管局核發(fā)的營業(yè)執(zhí)照,注冊資本1億元,股東為特斯拉...
據(jù)報道,5月18日,中國科學(xué)院第十五屆公眾科學(xué)日拉開帷幕。公眾科學(xué)日期間,中科院沈陽自動化所舉行了以“探索世界智造未來”為主題的科技成果展。其中,“海斗”號萬米級自主水下機(jī)器人和深海液壓機(jī)械手系統(tǒng)兩項科研成果的實物首次與公眾見面。別看“海斗”號身高只有1.2米,與一個五六歲的孩子差不多,但它的體重卻有260公斤,最大工作水深11000米,它可...
優(yōu)派(ViewSonic)宣布推出全新升級的便攜投影M1 mini Plus。全新的M1 mini Plus擁有榮獲2020年iF設(shè)計大獎的小巧外觀,可輕易將投影機(jī)放入口袋中,以及三種不同顏色時尚外殼,讓用戶可依照每天自身搭配隨意更換。除了炫酷的外觀設(shè)計外,優(yōu)派M1 mini Plus全新配置了芒果牛奶的智能系統(tǒng),海量片源隨意觀賞,同時還支持手機(jī)同屏和投屏;內(nèi)置2W JBL藍(lán)牙...
貿(mào)澤電子開售適用于樓宇和工廠自動化的Texas Instruments DP83TD510E以太網(wǎng)PHY2021年5月20日 – Texas Instruments (TI) 解決方案的全球授權(quán)分銷商貿(mào)澤電子 (Mouser Electronics) 即日起備貨TI DP83TD510E以太網(wǎng)物理層 (PHY) 器件。該P(yáng)HY可實現(xiàn)超過2km的電纜傳輸距離,是一款符合IEEE 802.3cg 10BASE-T1L規(guī)范的收發(fā)器,無需為實現(xiàn)高帶寬通...

史海拾趣

小廣播
設(shè)計資源 培訓(xùn) 開發(fā)板 精華推薦

最新單片機(jī)文章

 
EEWorld訂閱號

 
EEWorld服務(wù)號

 
汽車開發(fā)圈

 
機(jī)器人開發(fā)圈

電子工程世界版權(quán)所有 京ICP證060456號 京ICP備10001474號-1 電信業(yè)務(wù)審批[2006]字第258號函 京公網(wǎng)安備 11010802033920號 Copyright ? 2005-2025 EEWORLD.com.cn, Inc. All rights reserved