给电脑终端发送一个字符串“hello word”,接收到“hello worldhello worl”这样多出来一些字符,代码如下:
void Uart_Init(void)
{
// UART I/O port initialize (RXD0 : GPA0, TXD0: GPA1)
rGPACON = (rGPACON & ~(0xff<<0)) | (0x22<<0); // GPA0->RXD0, GPA1->TXD0
rGPAPUD = (rGPAPUD & ~(0xf<<0)) | (0x1<<0); // RXD0: Pull-down, TXD0: pull up/down disable
// Initialize UART Ch0
rULCON0 = (0<<6)|(0<<3)|(0<<2)|(3<<0); // Normal Mode, No Parity, 1 Stop Bit, 8 Bit Data
rUCON0 = (0<<10)|(1<<9)|(1<<8)|(0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(1<<0); // PCLK divide, Polling Mode
rUFCON0 = (0<<6)|(0<<4)|(0<<2)|(0<<1)|(0<<0); // Disable FIFO
rUMCON0 = (0<<5)|(0<<4)|(0<<0); // Disable Auto Flow Control
rUBRDIV0 = 35; // Baud rate
rUDIVSLOT0 = 0x80;//aSlotTable[DivSlot];
}
void Uart_SendByte(int data)
{
while(!(rUTRSTAT0 & 0x2)); //Wait until THR is empty.
Delay();
WrUTXH0(data);
}
void Uart_SendString(char *pt)
{
while(*pt)
{
Uart_SendByte(*pt++);
}
}
main函数就是先初始化然后调用字符串发送函数,小弟新手,还望大神们不吝赐教,先谢谢了