基于s3c2410开发板的UART测试程序
扫描二维码
随时随地手机看文章
如下程序实现的是开发板从PC端口接受一个字符,并把该字符加1后发送会PC端口。(在本开发板测试成功)对于不同的主频要设置好UBRDIV0的值,在技术文档中有这个值的计算公式。
#define ULCON0 (*(volatile unsigned *)0x50000000) //UART 0 Line control
#define UCON0 (*(volatile unsigned *)0x50000004) //UART 0 Control
#define UFCON0 (*(volatile unsigned *)0x50000008) //UART 0 FIFO control
#define UMCON0 (*(volatile unsigned *)0x5000000c) //UART 0 Modem control
#define UTRSTAT0 (*(volatile unsigned *)0x50000010) //UART 0 Tx/Rx status
#define UBRDIV0 (*(volatile unsigned *)0x50000028) //UART 0 Baud rate divisor
#define UTXH0 (*(volatile unsigned char *)0x50000020) //UART 0 Transmission Hold
#define URXH0 (*(volatile unsigned char *)0x50000024) //UART 0 Receive buffer
#define GPHCON (*(volatile unsigned *)0x56000070)
#define GPHDAT (*(volatile unsigned *)0x56000074)
#define GPHUP (*(volatile unsigned *)0x56000078)
int Main()
{
unsigned long TXH0READY = 0x2;
unsigned long RXH0READY = 0x1;
//init uart
GPHCON |= 0xa0;
GPHUP |= 0x0c;//PULLUP is enable;
//init uart controllor
ULCON0 = 0x03;
UCON0 = 0x245;
UFCON0 = 0x00;
UMCON0 = 0x00;
UBRDIV0= 26;
while(1)
{
while(!(UTRSTAT0 & RXH0READY));
c = URXH0;
while(!(UTRSTAT0 & TXH0READY));//wait
UTXH0 = c+1;
}
while(1);
return(0);
}