6步教你在STM32程序中添加 printf函數_第1頁
6步教你在STM32程序中添加 printf函數_第2頁
6步教你在STM32程序中添加 printf函數_第3頁
全文預覽已結束

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論