|
发表于 2013-5-20 20:14:38
|
显示全部楼层
楼主的波特率不是115200吧!!UBRDIV0 = 34是115200不知道你的串口助手是不是设置的波特率和程序的一样!而且你贴的代码不全,send函数在哪找的呢?我给你贴一个代码,是我已经调试通过了的你参考下void Uart_Init()
{
rGPACON = (rGPACON & ~(0xff<<0)) | (0x22<<0);
rGPAPUD = (rGPAPUD & ~(0xf<<0)) | (0x1<<0); // RXD0: Pull-down, TXD0: pull up/down disable
rULCON0=rULCON0&(0xFFFFFFFF)|(0<<6)|(0<<3)|(0<<2)|(3<<0);;
rUCON0=rUCON0&(0xFFFFFFFF)|(0<<10)|(1<<9)|(1<<8)|(0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(1<<0);
rUFCON0=rUFCON0&(0xFFFFFFFF)|(0<<6)|(0<<4)|(0<<2)|(0<<1)|(0<<1);
rUMCON0 = (0<<5)|(0<<4)|(0<<0);
rUBRDIV0=34;
rUDIVSLOT0=0xDDDD;
}
void Uart_SendByte(int data)
{
while(!(rUTRSTAT0&0x02));
WrUTXH0(data);
}
void Uart_Sendstring(char *str)
{
while(*str)
Uart_SendByte(*str++);
}
void Uart_Printf(char *fmt,...)
{
va_list ap;
char string[256];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
Uart_Sendstring(string);
va_end(ap);
} |
|