如下程序实现的是开发板从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);
}
『本文转载自网络,u球体育app下载的版权归原作者所有,如有侵权请联系删除』