用串口调试助手给单片机发送一串字符串,单片机接受完之后向串口助手回显,但出现勒问题,求大神帮忙
#include<reg52.h>#include<intrins.h>#include<absacc.h>#defineucharunsignedchar#define...
#include <reg52.h>
#include <intrins.h>
#include <absacc.h>
#define uchar unsigned char
#define uint unsigned int
uchar temp;
inits(void)
{ //波特率115200
T2MOD=0x01;
T2CON=0x30;
TH2=0xff;
TL2=0xfd;
RCAP2H=0xff;
RCAP2L=0xfd;
SCON|=0x50;
TR2=1;
EA=ES=1;
}
int uart;
t1int() interrupt 3
{
TH1=(65536-2000)/256;
TL1=(65536-2000)%256;
uart++;
}
uchar shu[100];
void set_usrat(uchar count)
{
ES=0;
SBUF=count;
while(TI==0);
TI=0;
ES=1;
}
uchar i,j;
serial() interrupt 4
{
ES=0;
if(RI==1)
{
RI=0;uart=0;
shu[i]=SBUF;
i=i+1;
}
ES=1;
}
main()
{
EA=ET1=TR1=1;
TH1=(65536-2000)/256;
TL1=(65536-2000)%256;
TMOD=0x10;
i=j=0;
inits();
while(1)
{
if(uart>100)
{
if(i>0)
{
for(j=0;j<i;j++)
{
set_usrat(shu[j]);
}
i=0;
set_usrat('\n');
}
}
}
例如:
如果我连续发123
发多几次就变成 1123 貌似混乱勒一样!!!!求教师傅 展开
#include <intrins.h>
#include <absacc.h>
#define uchar unsigned char
#define uint unsigned int
uchar temp;
inits(void)
{ //波特率115200
T2MOD=0x01;
T2CON=0x30;
TH2=0xff;
TL2=0xfd;
RCAP2H=0xff;
RCAP2L=0xfd;
SCON|=0x50;
TR2=1;
EA=ES=1;
}
int uart;
t1int() interrupt 3
{
TH1=(65536-2000)/256;
TL1=(65536-2000)%256;
uart++;
}
uchar shu[100];
void set_usrat(uchar count)
{
ES=0;
SBUF=count;
while(TI==0);
TI=0;
ES=1;
}
uchar i,j;
serial() interrupt 4
{
ES=0;
if(RI==1)
{
RI=0;uart=0;
shu[i]=SBUF;
i=i+1;
}
ES=1;
}
main()
{
EA=ET1=TR1=1;
TH1=(65536-2000)/256;
TL1=(65536-2000)%256;
TMOD=0x10;
i=j=0;
inits();
while(1)
{
if(uart>100)
{
if(i>0)
{
for(j=0;j<i;j++)
{
set_usrat(shu[j]);
}
i=0;
set_usrat('\n');
}
}
}
例如:
如果我连续发123
发多几次就变成 1123 貌似混乱勒一样!!!!求教师傅 展开
2个回答
展开全部
#include <reg52.h>
#include <intrins.h>
#include <absacc.h>
#define uchar unsigned char
#define uint unsigned int
uchar temp,pget,pput,shu[16];
uint uart;
inits(void)
{ //波特率115200
T2MOD=0x01;
T2CON=0x30;
TH2=0xff;
TL2=0xfd;
RCAP2H=0xff;
RCAP2L=0xfd;
SCON|=0x50;
TR2=1;
EA=ES=1;
}
t1int() interrupt 3
{
TH1=(65536-2000)/256;
TL1=(65536-2000)%256;
uart++;
}
serial() interrupt 4
{
if(RI==1)
{
RI=0;uart=0;
shu[pput]=SBUF;
pput++;
pput&=0x0f;
}
}
main()
{
EA=ET1=TR1=1;
TH1=(65536-2000)/256;
TL1=(65536-2000)%256;
TMOD=0x10;
pput=pget=0;
inits();
while(1)
{
if(uart>100)
{
if(pput!=pget)
SBUF=shu[pget];
pget++;
pget&=0x0f;
}
}
}
#include <intrins.h>
#include <absacc.h>
#define uchar unsigned char
#define uint unsigned int
uchar temp,pget,pput,shu[16];
uint uart;
inits(void)
{ //波特率115200
T2MOD=0x01;
T2CON=0x30;
TH2=0xff;
TL2=0xfd;
RCAP2H=0xff;
RCAP2L=0xfd;
SCON|=0x50;
TR2=1;
EA=ES=1;
}
t1int() interrupt 3
{
TH1=(65536-2000)/256;
TL1=(65536-2000)%256;
uart++;
}
serial() interrupt 4
{
if(RI==1)
{
RI=0;uart=0;
shu[pput]=SBUF;
pput++;
pput&=0x0f;
}
}
main()
{
EA=ET1=TR1=1;
TH1=(65536-2000)/256;
TL1=(65536-2000)%256;
TMOD=0x10;
pput=pget=0;
inits();
while(1)
{
if(uart>100)
{
if(pput!=pget)
SBUF=shu[pget];
pget++;
pget&=0x0f;
}
}
}
2014-02-25
展开全部
可以先用 proteus 仿真一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询