1.配置UART
void uart_configure(uint32_t baud) { // Enable the GPIO Peripheral used by the UART ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Enable UART0 ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // Configure GPIO Pins for UART mode ROM_GPIOPinConfigure(GPIO_PA0_U0RX); ROM_GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // Use the internal 16MHz oscillator as the UART clock source UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); // Initialize the UART for console I/O UARTStdioConfig(0, baud, 16000000); }
2.输出
void uart_printf(const char *pcString, ...) { va_list vaArgP; // // Start the varargs processing. // va_start(vaArgP, pcString); UARTvprintf(pcString, vaArgP); // // We're finished with the varargs now. // va_end(vaArgP); }
uart_printf("demo begin \n"); UC1701CharDispaly(0, 0,"your name:"); UC1701CharDispaly(2, 0,"your number:");
// 从串口得到一个字符 UARTCharGet(UART0_BASE); // 如果PC有发送字符 if(UARTCharsAvail(UART0_BASE)) { } // 清零 memset(name,' ',sizeof(name));