How to Use RS232 Receiver in AT89C1051 (Single Baud-Rate)

The following code demonstrate, how to receive data from UART of AT89C1051. The code is written in Keil uVision2 IDE and simulation is done with Proteus 8.0. At the end of code, you can find complete project files for download.

Code Using Keil uVision2

#include
#include “stdio.h”
// proto-types
void WriteData(unsigned char ch);
unsigned char ReadData(void);
void Delayms(unsigned int x_time);
// port pin labling
sbit LED_0 = P1^0;
void main(void)
{
code char company_name[] = “Engineering and Technology Education!\rWrite any Character in Transmitter Window:\r”;
unsigned int index;
char get_char;
LED_0 = 0; // as output
SCON = 0x50; // SCON: mode 1, 8-bit UART, enable rcvr
TMOD |= 0x20; // TMOD: timer-1, mode 2, 8-bit auto reload
TH1 = -3; // reload value for 9600 baud
//TH1 = -6; // reload value for 4800 baud
//TH1 = -12; // reload value for 2400 baud
//TH1 = -24; // reload value for 1200 baud
TR1 = 1; // TR1: timer-1 run
for(index=0;index<sizeof(company_name);index++)
{
WriteData(company_name[index]);
}
while(1)
{
get_char = ReadData();
WriteData(get_char);
LED_0 = ~LED_0; // led blinking
Delayms(200);
}
}
void WriteData(unsigned char ch)
{
SBUF = ch;
while(TI == 0);
TI = 0; // reset transmit flag
}
unsigned char ReadData(void)
{
return _getkey();
}
void Delayms(unsigned int x_time)
{
unsigned int x,y;
for(x=0;x<x_time;x++)
for(y=0;y<122;y++);
}

Download Files

For download Keil project and Proteus 8.0 simulation files, click here.

Comments

Popular posts from this blog

How to Program Interrupts in PIC16F877A

How to Program Parallel Slave Port (PSP) in PIC16F877A

How to Program SPI in PIC16F877A (Slave Mode)