


下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- GB/T 45498.2-2025中華人民共和國社會保障卡一卡通規范第2部分:應用規范
- GB/T 45454-2025壓縮模和注射模澆注系統零件
- 課題申報書超字怎么辦
- 證券分析師的職責與技能試題及答案
- 高通過率:微生物檢驗技師試題及答案
- 項目管理中的法律合規要求試題及答案
- 微生物檢驗技師證書考試中備考的試題
- 微生物檢驗新研究成果的試題與答案
- 小班兒童安全守則教育計劃
- 創造思想的碰撞計劃
- 養殖業勞動合同樣本
- 保險公司增額終身壽主講課件
- 上海市2023-2024學年五年級下冊第1-3單元期中模擬測試數學試卷(滬教版)
- 廠房屋頂分布式光伏電站工程日常質量巡查記錄表
- 中考語文真題雙向細目表
- 老年護理中的跌倒風險評估與干預計劃
- 《小兒支氣管炎肺炎》課件
- 基于時序數據的深度學習異常檢測技術
- 第六章 內輪廓加工
- 工程力學答案
- 2023年新高考生物江蘇卷試題真題答案解析版(精校打印)
評論
0/150
提交評論