|
我用串口通信发送 字符、字符串、还是空格啥的,pc机串口助手上偶尔会显示第一个字符错误。
程序波特率和串口助手上的都一致,不明白为什么会出现这种情况
单片机源程序如下:
- void UART_Init( void )
- {
- TMOD = 0x20;
- SCON = 0x50;
- TH1 = 0xFD;
- TL1 = 0xFD;
- TR1 = 1;
- }
- void Uart1Send( uchar c )
- {
- SBUF=c;
- while(!TI)
- TI=0;
- }
- void Uart1Sends( const uchar *str )
- {
- for(; *str!='\0'; str++)
- {
- Uart1Send( *str );
- }
- }
- void cktx()
- {
- Uart1Send(0x0d);
- Uart1Send(0x0a);
- Uart1Sends("SET: ");
- Uart1Sends("TempH=");
- Uart1Send(temph/10+'0');
- Uart1Send(temph%10+'0');
- Uart1Sends(" TempL=");
- Uart1Send(templ/10+'0');
- Uart1Send(templ%10+'0');
- Uart1Send(0x0d);
- Uart1Send(0x0a);
- Uart1Sends(" HumiH=");
- Uart1Send(humih/10+'0');
- Uart1Send(humih%10+'0');
- Uart1Sends(" HumiL=");
- Uart1Send(humil/10+'0');
- Uart1Send(humil%10+'0');
- Uart1Send(0x0d);
- Uart1Send(0x0a);
- Uart1Sends("NOW: ");
- Uart1Sends("Temp:");
- Uart1Send(tempvalue%100/10+'0');
- Uart1Send(tempvalue%100%10+'0');
- Uart1Send('.');
- Uart1Send(a*0.625+'0');
- Uart1Sends(" C");
- Uart1Sends(" Humi:");
- Uart1Send(humi/10+'0');
- Uart1Send(humi%10+'0');
- Uart1Sends(" %RH");
- Uart1Send(0x0d);
- Uart1Send(0x0a);
- Uart1Send(0x0d);
- Uart1Send(0x0a);
- delay_ms(10);
- }
复制代码
|
-
捕获.PNG
(14.26 KB, 下载次数: 36)
如图,偶尔会出现多余的字符
|