本帖最后由 oldzhang 于 2014-2-12 12:00 编辑
#include <reg52.h>
unsigned char sbuf_value;
bit flag_receive;
bit flag_send;
void init_uart(void)
{ EA=1;
TMOD=0X20;
TH1=252;TL1=252;
TR1=1;
SCON=0X50;
ES=1;
flag_receive=0;
flag_send=0;
}
void main(void)
{ init_uart();
while(1)
{
if ( (flag_receive==1 ) && ( flag_send==0) );
{ SBUF = sbuf_value;
flag_receive = 0;
flag_send =1;
}
}
}
void int_uart(void) interrupt 4
{ if(RI)
{ sbuf_value=SBUF;
flag_receive=1;
RI=0;
}
else
{ TI=0;
flag_send=0;
}
} |