LM3S9B96 UART打印字符串功能
1.UARTprintf函数:这与C语言中的printf函数类似,可以输出一个字符串,可以格式化输出一个变量的数值。用法如下:
UARTprintf("Uart2 is ready -> "); // 输出一句话
char test = 14;
UARTprintf("test is %d\n", test); // 按十进制格式输出变量test的值
2. 下面是一个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
//*****************************************************************************
//
// 延时函数
//
//*****************************************************************************
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 -> ");
}
//*****************************************************************************
//
// 主函数
//
//*****************************************************************************
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 %d\n", test);
while (1)
{
}
}
LM3S9B96UART打印字符 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)