#define ULCON0 (*(volatile unsigned *)0X50000000) //UART线控制寄存器
#define UCON0 (*(volatile unsigned *)0X50000004) //UART控制寄存器
#define UFCON0 (*(volatile unsigned *)0X50000008) //FIFO控制寄存器
#define UTRSTAT0 (*(volatile unsigned *)0X50000010) //UART状态寄存器
#define UBRDIV0 (*(volatile unsigned *)0X50000028) //波特率
#define UTXH0 (*(volatile unsigned *)0X50000020)
#define URXH0 (*(volatile unsigned *)0X50000024)
#define GPBDAT (*(volatile unsigned *)0X58000054)
#define TXD0READY (1<<2)
void putc(unsigned char c)
{
/* 等待,直到发送缓冲区中的数据已经全部发送出去 */
while (!(UTRSTAT0 & TXD0READY));
/* 向UTXH0寄存器中写入数据,UART即自动将它发送出去 */
UTXH0 = c;
}
int TSmain()
{
char buf;
ULCON0 &=0XFFFFFF00;
ULCON0 |=0X03; //1位起始位,8位数据位
UCON0 =0X0805; //串口时钟PCLK,查询方式 1000 0000 0101
UBRDIV0 =0X1A; //波特率115200
while(1)
{
/*if(UTRSTAT0 & 0X01) //接收是否完毕 =1结束
{
buf=URXH0; //读取数据
while(!(UTRSTAT0 & 0X04));//是否允许发送 =1允许
UTXH0=buf;
} */
putc('T');
putc('e');
putc('s');
putc('t');
}
return 0;
}
|