1

所以,我有一个连接到 TxD0 和 RxD0 引脚的终端。假设我只是想测试写入它是否有效。

我编写了一些函数来使 UART 能够读取和写入字符和字符串。虽然如果我尝试在模拟器中运行它,它会给我一个溢出错误。

以下是 uart.c 文件中的函数:

void uart0_write(unsigned char reg_data)
{
    while((U0LSR & (0x20)) != 0x20);/*wait until holding register is empty*/
    U0THR = (int) reg_data;/*write to holding register*/
}

void uart0_write_str(char str[])
{
    while(*str != '\0')/*check for EOF*/
    {
        uart0_write(*str);/*write a char*/
        str++;
    }
}

UART0初始化函数:

void uart0_init(void)
{
    PINSEL0 = 0x05; /*set pin P0.0 to TXD0 and P0.1 RxD0 (TXD0 - 01; RxD0 - 01; 0101 = 0x05)*/
    U0LCR = 0x83; /*set length for 8-bit word, set the stop bit, enable DLAB*/
    U0IER = (1<<0) | (1<<1);/*enable RBR and THR interrupts*/
    U0FCR = 0xC7; /*enable FIFO; reset Tx FIFO; set interrupt after 14 characters*/

    /*Baud rate configured to 9600 Baud (from lecture notes)*/
    U0DLL = 0x9D;
    U0DLM = 0x0;
    U0LCR = 0x03; /*8-bit character selection; disable DLAB*/
}

主要用途:

int main(void)
{
    char *introMsg;
    introMsg = "Hello World\n";

    systemInit();
    ADC_init();
    timer0_init();
    uart0_init();

    uart0_write_str(introMsg);

    /*or: */
    while(1)
    {
         uart0_write('c');
    }
    return 0;
}

有了这些演示代码片段,UART 应该可以正常工作,就像我在网上其他地方看到的那样。但是当尝试运行它时,它不会打印任何东西并且 OE 会弹出。我究竟做错了什么?我才刚刚开始深入研究裸机编程,所以可能存在一些我没有注意到的错误。

我欢迎任何见解!

呆在家里,

雅各布

4

0 回答 0