新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > LM3S9B96 UART打印字符串功能

LM3S9B96 UART打印字符串功能

作者: 時(shí)間:2016-11-11 來(lái)源:網(wǎng)絡(luò) 收藏
調(diào)試的時(shí)候,可以觀察某個(gè)變量的值,前提是需要用JLINK進(jìn)行調(diào)試。其實(shí),程序全速運(yùn)行時(shí),可以看某個(gè)變量值是多少。這就用到UART打印字符串的功能。
1.UARTprintf函數(shù):這與C語(yǔ)言中的printf函數(shù)類似,可以輸出一個(gè)字符串,可以格式化輸出一個(gè)變量的數(shù)值。用法如下:

UARTprintf("Uart2 is ready -> "); // 輸出一句話

本文引用地址:http://butianyuan.cn/article/201611/317006.htm

char test = 14;
UARTprintf("test is %dn", test); // 按十進(jìn)制格式輸出變量test的值

2. 下面是一個(gè)UART2打印功能的例子:

#include "inc/hw_memmap.h"
#include "inc/hw_types.h"

#include "driverlib/gpio.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "driverlib/sysctl.h"

/* 寄存器地址 ---------------------------------------------------------------*/
#define GPIO_PORTJ_APB_DIR_R 0x4003D400
#define GPIO_PORTJ_APB_DEN_R 0x4003D51C
#define GPIO_PORTJ_APB_PUR_R 0x4003D510
#define SYSCTL_RCGC2_R 0x400FE108

//*****************************************************************************
//
// 延時(shí)函數(shù)
//
//*****************************************************************************
void Delay(volatile signed long nCount)
{
for(; nCount != 0; nCount--);
}

//*****************************************************************************
//
// This function sets up UART2 to be used for a console to display information
// as the example is running.
//
//*****************************************************************************
void InitConsole(void)
{
// Enable GPIO port D which is used for UART2 pins.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

// Select the alternate (UART) function for these pins.
GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);

// Configure the pin muxing for UART0 functions on port A0 and A1.
// This step is not necessary if your part does not support pin muxing.
GPIOPinConfigure(GPIO_PD0_U2RX);
GPIOPinConfigure(GPIO_PD1_U2TX);

// Initialize the UART for console I/O.
UARTStdioInit(2);

UARTprintf("Uart2 is ready -> ");
}


//*****************************************************************************
//
// 主函數(shù)
//
//*****************************************************************************
int main(void)
{
// Set the clocking to run directly from the crystal.
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

InitConsole(); // UART2初始化

char test = 14;

UARTprintf("test is %dn", test);

while (1)
{
}
}




關(guān)鍵詞: LM3S9B96UART打印字符

評(píng)論


技術(shù)專區(qū)

關(guān)閉