您好,歡迎訪問上海意泓電子科技有限責(zé)任公司網(wǎng)站!
      4新聞資訊
      您的位置: 首頁(yè) ->  新聞資訊 -> 單片機(jī)

      ?STM32下Keil IDE中Printf函數(shù)的使用

      文章出處:?jiǎn)纹瑱C(jī) 責(zé)任編輯:上海意泓電子科技有限責(zé)任公司 發(fā)表時(shí)間:
      2018
      05-20

      請(qǐng)?jiān)贛DK(keil)工程屬性的“Target“-》”Code Generation“中勾

      選”Use MicroLIB

       

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

      用Printf 函數(shù)

      紅色字句為重點(diǎn)?。。。?!

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


      上海意泓電子科技有限責(zé)任公司 版權(quán)所有 未經(jīng)授權(quán)禁止復(fù)制或鏡像

      CopyRight 2020-2025 www.topsschool.com All rights reserved   滬ICP備2021005866號(hào)

      亚洲精品无码va人在线观看,少妇 逼小 水多,国产区免费av,国产精品无码观看

          亚洲综合区夜久久| 国产成人理论在线观看视频| 日韩欧美国产综合一区| 夜夜春天天弄精品视频| 亚洲av日韩aⅴ无码电影| 国产V欧美V日韩在线观看| 日韩熟妇啪啪无码视频精品| 中文字幕精品一区| 亚洲无码免费在线观看视频| 亚洲中文精品久久久久久蜜臀| 亚洲AV秘 无码一区在线播放| 岛国无码av不卡一区二区| 亚洲а∨天堂2014在线无码| 国产老妇女牲交视频| 精品蜜桃一区二区三区| 国产一级牲交高潮片毛片| 欧美成人国产精美视频| 99免费无码精品国产| 亚洲第一福利视频| 日韩精品一区二区在线观看| 久久综合九色综合欧美98r| 色综合天天综合网国产成人网| 无码抽搐高潮喷水流白浆| 精品21国产成人综合网| 视频精品中文字幕一区二区| 亚洲国产品综合人成综合网站| 99久久无码精品一区二区毛片| 97久久人人爽人人爽人人片| 91亚洲无码手机福利网|