手册中有提到M4具有浮点数的支援,我想要利用printf打印出float的数值,UART却没有办法显示该数值。
以下是我用Template测试的代码,想请问要如何正确打印出float值呢?
感谢回覆
#include <stdio.h>
#include "NuMicro.h"
void SYS_Init(void)
{
/* Enable UART module clock */
CLK_EnableModuleClock(UART16_MODULE);
/* Select UART module clock source as HXT and UART module clock divider as 1 */
CLK_SetModuleClock(UART16_MODULE, CLK_CLKSEL3_UART16SEL_HXT, CLK_CLKDIV3_UART16(1));
/* Set GPD multi-function pins for UART16 RXD and TXD */
SYS->GPD_MFPH &= ~(SYS_GPD_MFPH_PD10MFP_Msk | SYS_GPD_MFPH_PD11MFP_Msk);
SYS->GPD_MFPH |= SYS_GPD_MFPH_PD10MFP_UART16_RXD | SYS_GPD_MFPH_PD11MFP_UART16_TXD;
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate SystemCoreClock and CyclesPerUs automatically. */
SystemCoreClockUpdate();
}
/* Main */
int main(void)
{
/* Unlock protected registers */
SYS_UnlockReg();
/* Init System, IP clock and multi-function I/O. */
SYS_Init();
/* Init UART to 115200-8n1 for print message */
UART_Open(UART16, 115200);
float test = 1.5;
printf("test = %f\n", test);
return 0;
} |