請在MDK(keil)工程屬性的“Target“-》”Code Generation“中勾
選”Use MicroLIB
前提是你有一個完整keil的工程 比如ADC的調(diào)試的時候很多時候用到串口 這里教你怎么樣使
用Printf 函數(shù)
紅色字句為重點!?。。?!
若使得在程序中使用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個函數(shù) usart配置 和 重定向 C庫的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ù)
上一篇:STM32 在 KEIL 下使用 SWV 輸出調(diào)試信息
下一篇:STM32的ADC多通道采集的實現(xiàn)
推薦閱讀
史海拾趣
設(shè)計資源 培訓(xùn) 開發(fā)板 精華推薦
- 有獎直播:新能源行業(yè)中的電學(xué)測試與校準(zhǔn)應(yīng)用
- 《CoolSiC™英飛凌最佳的伺服驅(qū)動解決方案》白皮書下載
- 有獎直播|PI助力高可靠性與高效率的工業(yè)計量方案
- Littelfuse第2期 | 符合AEC-Q200 車規(guī)的保險絲/熔斷器
- 看視頻贏京東卡 | 泰享實測之水哥秘籍
- 了解keysight汽車電子解決方案,答題贏好禮
- “玄鐵杯”第三屆RISC-V應(yīng)用創(chuàng)新大賽—國產(chǎn)高性能RISC-V Linux開發(fā)板LicheePi 4A報名專場,萬元獎金,邀您奔赴開源設(shè)計盛宴
- 有獎直播|安森美高能效產(chǎn)品在 EV-Charger 市場的應(yīng)用
- Pctolcd2002怎么顯示在msp上啊
- 模塊撥號上網(wǎng),要先設(shè)定模塊嗎?
- 請教能否通過串口控制另一個ATX電源的開關(guān)
- 能否提供虛擬串口例程驅(qū)動的的dll文件與操作的.h文件
- 電源
- WINCE60下基于DirectShow技術(shù)怎么寫Camera相機(jī)的應(yīng)用程序?就像在PC上通過DirectShow技術(shù)做的攝像頭的應(yīng)用程序一樣可以瀏覽,可以拍照
- 今天上午10:00開啟 艾睿電子有獎直播:英特爾?FPGA深度學(xué)習(xí)加速技術(shù)
- xilinx 的開發(fā)軟件有哪些
- 原理圖——這個電路是如何實現(xiàn)開關(guān)自鎖功能的?
- 電組匹配表