程序: #include <reg51.h> #include <string.h> void init_serialcomm(void) { SCON = 0x50; //SCON: serail mode 1, 8-bit UART, enable ucvr TMOD |= 0x20; //TMOD: timer 1, mode 2, 8-bit reload PCON |= 0x80; //SMOD=1; TH1 = 0xFB; //Baud:4800 fosc=11.0592MHz IE |= 0x90; //Enable Serial Interrupt TR1 = 1; // timer 1 run // TI=1; } void send_char_com(unsigned char ch) { SBUF=ch; while(TI==0); TI=0; } main() { init_serialcomm();
send_char_com('a'); }
结果如下图所示:
|