51單片機(jī)串口通信中字符發(fā)送的總結(jié)
/*字符發(fā)送方式一*/
#includereg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar flag,a,i;
uchar code table[]="I get ";
void init()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SM0=0;
SM1=1;
REN=1;
//TI=1;
EA=1;
ES=1;
}
void main()
{
init();
while(1)
{
if(flag==1)
{
ES=0;
for(i=0;i6;i++)
{
SBUF=table[i];
while(TI==0);
TI=0;
}
SBUF=a;
while(TI==0);
TI=0;
ES=1;
flag=0;
}
}
}
void ser() interrupt 4
{
a=SBUF;
RI=0;
P1=~P1;
flag=1;
}
/*字符發(fā)送方式二*/
#includereg52.h>
#includestdio.h>
#includeintrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar flag,a,i=0;
uchar code table[]="I get ";
void init()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SM0=0;
SM1=1;
REN=1;
//TI=1;
EA=1;
ES=1;
}
void main()
{
init();
while(1)
{
if(flag==1)
{
ES=0;
while(table[i]!='