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

The following code demonstrate, how to transmit serial data in 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
// proto-types
void WriteData(unsigned char ch);
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!”;
unsigned int index;
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
while(1)
{
for(index=0;index<sizeof(company_name);index++)
{
WriteData(company_name[index]);
}
WriteData(‘\r’); // carriage return ascii char
LED_0 = ~LED_0; // led blinking
Delayms(200);
}
}
void WriteData(unsigned char ch)
{
SBUF = ch;
while(TI == 0);
TI = 0; // reset transmit flag
}
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)