//int转string:
char *hex2char(unsigned int val)
{
char str[5];
char *s;
s = str;
str[0] = val/1000+ '0';
str[1] = (val/100)%10+ '0';
str[2] = (val/10)%10+ '0';
str[3] = val%10+ '0';
str[4] = '/';
return s;
}
//UART初始化
void Uart_Init(void)
{
rGPACON=(rGPACON&~(0xff<<0))|(0x22<<0);//A口设置为UART
rGPAPUD=(rGPAPUD&~(0xff<<0))|(0x1<<0);//A口允许下拉
rULCON0=0x03;//设置传输帧格式
rUCON0=(0<<10)|(1<<9)|(1<<8)|(0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(1<<0);//设置访问方式
rUMCON0=0x00;//屏蔽Medom
rUBRDIV0=35;//设置波特率
rUDIVSLOT0=0x80;
}
//传输数据
void Uart_SentByte(char data)
{
while(!(rUTRSTAT0&0x2))
;//等待发送缓冲器空
Delay();
rUTXH0=data;//向发送缓冲器写入数据
}
//发送字符串!
void Uart_SentString(char *s)
{
while(*s)
Uart_SentByte(*s++);
}
//main函数
int main(void)
{
// Port_Init();//端口设置函数调用
Uart_Init();//UART设置函数调用
Uart_SentByte('b');
Uart_SentString(hex2char(26));//发送字符串
}
程序如上,运行Uart_SentString(“hello,world”);串口是能打印的,所以觉得不是串口的问题,问题应该是出在int转string的部分,求各路大神指点一下!!!