zoukankan      html  css  js  c++  java
  • 单片机TM4C123学习(五):UART的使用

    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 
    ");
    
    UC1701CharDispaly(0, 0,"your name:");
        
    UC1701CharDispaly(2, 0,"your number:");
        
    // 从串口得到一个字符
    UARTCharGet(UART0_BASE);
    // 如果PC有发送字符
    if(UARTCharsAvail(UART0_BASE))
    {
    }
    // 清零
    memset(name,' ',sizeof(name));
  • 相关阅读:
    parseInt()的用法
    报文
    express的中间件与next()
    前后端分离与前后端不分离
    jQuery中四个绑定事件的区别 on,bind,live,delegate
    TCP传输的三次握手四次挥手策略
    报文
    HTTP和HTTPS以及两者的区别
    前后端不分离与分离
    express中间件的next()方法
  • 原文地址:https://www.cnblogs.com/pursuit1996/p/4923273.html
Copyright © 2011-2022 走看看