


下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、6步教你在STM32程序中添加 printf函數6步教你在STM32程序中添加 printf函數 前提是你有一個完整的可以運行的 keil工程 比如ADC的 調試的時候很多時候用到串口 這里教你怎么樣使用Printf 函數 在程序中添加Printf.txt 1, #include <stdio.h> 2, /* Private functions -*/ 下添加 void USART_Configuration(void); #ifdef _GNUC_ /* With GCC/RAISONANCE, small printf (optio
2、n 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個函數 usart配置 和 重定向 C庫的printf函數 void USART_Configurat
3、ion() /* USARTx configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - One Stop Bit - No parity
4、 - 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.GP
5、IO_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_
6、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_HardwareFlo
7、wControl = 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 */ PUTCH
8、AR_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) 添加 /* E
9、nable 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()調用 printf("The is a example!" ); printf("%s%c%c%c%c%c%s", "#*", Value/256,Value%256,
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 學生互評對提升表達能力的心得體會
- 商品混凝土攪拌站現場安全管理制度范文
- 大學生英語趣配音競賽計劃
- 檔案保管及管理機構職責說明
- 小學美術教師藝術素養計劃
- 新人教版八年級歷史下冊教學計劃
- 幼兒美術教育實習總結范文
- 抗菌藥物合理使用管理工作流程
- 鄉鎮小學道德法治教學工作計劃
- 隧道工程文明施工管理體系與措施
- 建材公司成立策劃方案
- 廣告法法律培訓課件
- 肢體離斷傷的護理
- 電子審圖系統行業深度研究分析報告(2024-2030版)
- 彩繪臉部兒童課件
- 小學出入庫管理制度
- ISO28000:2022供應鏈安全管理體系
- 三下開采規范2019版
- 歐式宗譜模板
- 《汽車座椅制造工藝》PPT課件
- 衛星通信地球站設備安裝工程施工及驗收技術規范YD5017
評論
0/150
提交評論