我尝试了一下。我运用的14.7456的晶振,想选用9600 8 1 n的方法通讯,其实是与别的的一个板子(s3c6410)那么单片机的串口设置就的有必定的值。计算公式是这样的:
F = 14.7456 Baud = 9600(12T形式)
BELOAD = 256 – INT(14745600/9600/32/12 + 0.5)
= 256 – INT(5.5)
= 256 –4
= 251
Baud = 14745600 /(256 – 254)/ 32 / 12
= 9600
没有任何的差错
我实验过别的的一个,38400,8,N,1的格局此刻
BELOAD = 0xFF,无差错;详细的运用时这样:
voiduart_init(void)
{
EA = 0;
SCON = 0x50;//选用方法1,REN=1,其他位为0 1位,8位,1位,N 38400
AUXR = 0x17;
//PCON = 0x7F;//不能有这个不然将会程序发动不了,
BRT = 0xff;//RELOD = 256 – 1; 差错为0,9600是relod = 256 – 4;差错为0
ES = 1;
EA = 1;
}
uchar uart_1send(unsigned char c)
{
ucharaa=0;
SBUF = c;
while(!TI) //若TI=0,在此等候
{
aa = 1;
return a;
}
TI = 0;
return a;
}
uchar uart_1read(void)
{
ucharaa=0;
aa = SBUF;
while(!RI) //若RI=0,在此等候
{
aa = 1;
return a;
}
RI = 0;
return a;
}
void uart1(void) interrupt 4
{
if(TI == 1)
{
uart_1send(send);
}
else
{
read = uart_1read();
}
}
正确程序应该是这样的,9600,8位,无奇偶校验,1位中止
voiduart_init(void)
{
AUXR = 0x11;
SCON |= 0x50;
//PCON |= 0x80;
BRT = 0xfc;
ES = 1;
EA = 1;
}
void uart_1send(unsigned char c)
{
SBUF = c;
while(TI!=0) //若TI=0,在此等候
{
TI = 0;
}
}
uchar uart_1read(void)
{
uchar aa;
aa = SBUF;
while(RI!=0) //若RI=0,在此等候
{
RI = 0;
}
return aa;
}
int main(void)
{
unsigned char i;
unsigned int n;
alldata_init();
//uart_1send(i);
while(1)
{
//n++;
for(n=0;n<3000;n++)//延时用
{;}
uart_1send(i);
i++;
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/dianzi/259200.html