版主
注册时间:2021-3-11
在线时间:9 小时
|
发表于 2018-4-22 14:03:49
|
显示全部楼层
来了个奇怪的问题,我串口波特率设置成115200的,结果错误,后来在串口用28800时接收发送正常,是什么原因,附上代码
void U_in() //接收数据
{
//static u8 lent,sta_m;
if(RI==1)
{ RI=0; // UartSend(0xaa);
if(SBUF == 0xa0){f_out=0;c_out=0; UartSend(0x50);} //当收到0xa0,关闭充放电管,并且回送0x50 测试用
else if(SBUF == 0xa1){f_out=1;c_out=1;UartSend(0x51);} //当收到0xa1,开启充放电管,并且回送0x51 测试用
else if(SBUF == 0xa2){pow_off=1;UartSend(0x52);} //当收到0xa2,总电源休眠,并且回送0x52 测试用
else if(SBUF == 0xa3){ly_it=1;UartSend(0x53);} //当收到0xa3,总唤醒蓝牙,并且回送0x53 测试用
/************USART.h********************/
#include "stc8a8k.h"
//#include <USART.h>
#include "intrins.h"
#define FOSC 24000000UL
#define BRT (65536-FOSC/115200)
void UartInit() //串口初始化
{
SCON|=0x5a;
T2L=BRT;
T2H=BRT>>8;
AUXR=0x15;
}
void UartSend(char dat) //发送函数
{
while(!TI);
TI=0;
SBUF=dat;
}
|
|