在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 6步教你在STM32程序中添加 printf函數(shù)

            6步教你在STM32程序中添加 printf函數(shù)

            作者: 時(shí)間:2016-11-13 來源:網(wǎng)絡(luò) 收藏
            前提是你有一個(gè)完整的keil工程 比如ADC的

            本文引用地址:http://www.biyoush.com/article/201611/316409.htm

            調(diào)試的時(shí)候很多時(shí)候用到串口 這里教你怎么樣使用Printf 函數(shù)

            在程序中添加Printf
            1,
            #include
            2,
            /* Private functions ---------------------------------------------------------*/ 下添加

            void USART_Configuration(void);

            #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__ */

            3,添加如下2個(gè)函數(shù) usart配置 和 重定向 C庫的printf函數(shù)
            void USART_Configuration()
            {
            /* USARTx configured as follow:
            - BaudRate = 9600 baud
            - Word Length = 8 Bits
            - One Stop Bit
            - No parity
            - Hardware flow control disabled (RTS and CTS signals)
            - Receive and transmit enabled
            */
            USART_InitTypeDef USART_InitStructure;
            GPIO_InitTypeDef GPIO_InitStructure;
            /* Configure USART1 Tx (PA9) as alternate function push-pull */
            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
            GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
            GPIO_Init(GPIOA, &GPIO_InitStructure);

            /* Configure USART1 Rx (PA10) as input floating */
            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
            GPIO_Init(GPIOA, &GPIO_InitStructure);


            USART_InitStructure.USART_BaudRate = 9600;
            USART_InitStructure.USART_WordLength = USART_WordLength_8b;
            USART_InitStructure.USART_StopBits = USART_StopBits_1;
            USART_InitStructure.USART_Parity = USART_Parity_No;
            USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
            USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

            USART_Init(USART1, &USART_InitStructure);
            /* Enable USART1 */
            USART_Cmd(USART1, ENABLE);
            }

            /**
            * @brief Retargets the C library printf function to the USART.
            * @param None
            * @retval None
            */
            PUTCHAR_PROTOTYPE
            {
            /* Place your implementation of fputc here */
            /* e.g. write a character to the USART */
            USART_SendData(USART1, (uint8_t) ch);

            /* Loop until the end of transmission */
            while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
            {}

            return ch;
            }
            4,

            void RCC_Configuration(void) 添加
            /* Enable GPIOA and USART1 clocks */
            RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE);
            5,
            STM32F10x.CONF.H

            去掉/* #include "stm32f10x_usart.h" */ 的注釋
            6,
            在Main()中添加

            void USART_Configuration()

            然后就可以在main()調(diào)用

            printf("The is a example!" );

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

            之類的輸出函數(shù)



            關(guān)鍵詞: STM32程序printf函

            評(píng)論


            技術(shù)專區(qū)

            關(guān)閉