本帖最后由 alaic123 于 2013-1-7 15:25 编辑
想做到单片机接受一组固定长度字符串,再将字符串通过串口助手发出来,如果我发123456 结果是612345 请各位大神帮我指点指点
#include<reg52.h>
//#include<stdio.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char *p,a[6];
unsigned char flag,c,i;
void init()
{
TMOD=0X20;
TH1=0xFD;
TL1=0xFD;
TR1=1;
SM0=0;
SM1=1;
REN=1;
EA=1;
ES=1;
}
void main()
{
init();
while(1)
{
if(flag==1)
{
ES=0;
p=&a;
while(*p!='\0')
{
SBUF=*p;
p++;
while(!TI);
TI=0;
}
ES=1;
flag=0;
}
}
}
void ser()interrupt 4
{ int i;
RI=0;
a[i++]=SBUF;
if(i==6)
{i=0;
flag=1;
}
}
|