#include "uart.h"
#define Baud 9600 //定义通讯波特率
#define Cclk 11059200
void init() //初始化串口0。设置为8位数据位,1位停止位,无奇偶校验,波特率为9600
{
int Fdiv;
Uart0->LCR = 0x83; // DLAB = 1,可设置波特率
// Fdiv=Cclk/(Baud*16*4);
// Uart0->DLM=Fdiv/256;
// Uart0->DLL=Fdiv%256;
Uart0->DLM = 0;
Uart0->DLL = 0x48; //11059200/16/9600=72
Uart0->LCR = 0x03; //DLAB=0
Uart0->TER = 0x80;
}
void sendbyte(u32 data)
{
Uart0->THR = data;
while((Uart0->LSR & (1<<6)) == 0); // 等待数据发送完毕
}
void sendstr(u8 const *str)
{
while(1)
{
if(*str == '\0')
break;
sendbyte(*str ++);
}
}
u8 const SENDSTRING[] = "abcdefg";
int main()
{
Pin->SEL0 = 0x05; // 设置I/O连接到UART0
init();
while(1)
{
sendbyte(0x55);
}
return 0;
}