串口初始化程序:
void UARTa_Init(Uint32 baud)
{
unsigned char scihbaud=0;
unsigned char scilbaud=0;
Uint16 scibaud=0;
scibaud=37500000/(8*baud)-1;
scihbaud=scibaud>>8;
scilbaud=scibaud&0xff;
EALLOW;
SysCtrlRegs.PCLKCR0.bit.SCIAENCLK = 1; // SCI-A
EDIS;
InitSciaGpio();
//Initalize the SCI FIFO
SciaRegs.SCIFFTX.all=0xE040;
SciaRegs.SCIFFRX.all=0x204f;
SciaRegs.SCIFFCT.all=0x0;
SciaRegs.SCICCR.all =0x0007;
SciaRegs.SCICTL1.all =0x0003;
SciaRegs.SCIHBAUD =scihbaud;
SciaRegs.SCILBAUD =scilbaud;
SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}
void UARTa_SendByte(int a)
{
while (SciaRegs.SCIFFTX.bit.TXFFST != 0);
SciaRegs.SCITXBUF=a;
}
void UARTa_SendString(char * msg)
{
int i=0;
while(msg[i] != '\0')
{
UARTa_SendByte(msg[i]);
i++;
}
}
主程序如下:
void main()
{
int i=0;
char *msg;
Uint16 ReceivedChar=0;
InitSysCtrl();
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
LED_Init();
TIM0_Init(150,200000);//200ms
UARTa_Init(115200);
msg = "Hello World!\n";
while(1)
{
UARTa_SendString(msg);
}
串口调试助手中也将波特率改为115200,但是发送过来的乱码。