#include <reg52.h>
sbit P3_4 = P3^4;
sbit P3_5 = P3^5;
void RecDat(void)
{
unsigned char dat;
RI = 0; // this is a flag set by hardware and cleared by software
dat = SBUF; // SBUF it's a 8 bit buffer that contains the 8 bit data received by uart
P2 = 0xFF; // i set ths port to this value to turn on the display
if( dat == 'a' )
{
P3_4 = 0; // turn on the correct led
P3_5 = 1; // turn off the wrong led
}
else
{
P3_4 = 1; // turn off the correct led
P3_5 = 0; // turn on the wrong led
}
}
void InitSerial(void) // Simply setting for UART and BaudRate MCU
{
TMOD |= 0x20; // Timer 1 in mode 2 (auto reload)
TL1 = 0xFD; // 9600 baud rate
TH1 = 0xFD;
SCON = 0x50; // Setup UART mode 2
TR1 = 1; // Start Timer1 and UART
}
void main (void) {
P2 = 0x00;
InitSerial();
while (1)
{
if (RI) { // if a receive the data by Serial RI it's setting by hardware to 1
RecDat ();
}
}
}