How to Use RS232 Receiver in AT89C1051 (Double Baud-Rate)
The following code demonstrate, how to receive data from UART of AT89C1051 with double baud-rate. 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;
#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[] = “eTechEd.com: Engineering and Technology Education!\r”;
code char baud_info[] = “Transmission with double baud-rate 9600 x 2 = 19200\rType in Transmitter Window->:”;
unsigned int index;
char get_char;
LED_0 = 0; // as output
PCON |= 0x80; // PCON: SMOD=1 for double baud rate
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]);
}
for(index=0;index<sizeof(baud_info);index++)
{
WriteData(baud_info[index]);
}
WriteData(‘\r’); // carriage return ascii char
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++);
}
{
code char company_name[] = “eTechEd.com: Engineering and Technology Education!\r”;
code char baud_info[] = “Transmission with double baud-rate 9600 x 2 = 19200\rType in Transmitter Window->:”;
unsigned int index;
char get_char;
LED_0 = 0; // as output
PCON |= 0x80; // PCON: SMOD=1 for double baud rate
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]);
}
for(index=0;index<sizeof(baud_info);index++)
{
WriteData(baud_info[index]);
}
WriteData(‘\r’); // carriage return ascii char
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
Post a Comment