Serial Communication
serial communication expirements
hardware
- STC89C52RC
- SComAssistant
code
/************************
Serial Communication
Monitor the serial console
Baud Rate: 9600bit/s
*************************/
#include <reg52.h>
void UsartConfiguration()
{
SCON = 0x50; // Set mode to 1
TMOD = 0x20; // Set timer mode to 2
PCON = 0x00; // SMOD = 0
TH1 = 0xfd; // init counter
TL1 = 0xfd;
ES = 1; // open receiver interrupt
EA = 1; // open general interrupt
TR1 = 1; // open counter
}
void main()
{
UsartConfiguration();
while (1);
}
void uart() interrupt 4
{
unsigned char date;
date = SBUF; // take received data
RI = 0; // clean receiver interrupt mark
SBUF = date; // put received data to buffer register
while (!TI); // waiting sending data complete
TI = 0; // clear send interrupt mark
}
Page Source