Display single character using serial comm.

 

 Code : 

#include<reg51.h>                     // Include 8051 library
void ser_init();                            //Initialize serial communications.
void tx(unsigned char w);          // Serial transmission function definition.

void main()                                // Main function starts.
{
ser_init();                          // Serial function calling.
tx('A');                               // Transmit character A
while(1);                           // Infinite loop.
}
void tx(unsigned char w)          // Transmit function.
{
SBUF = w;                    // SBUF temporary buffer location where character is stored.
while(TI==0);               // Wait until transmission completed flag gets high.
TI=0;                             // Once high , make it zero for the next character. 
}
void ser_init()                     // Serial transmission function
{
SCON = 0X50;           // Mode 1 (8-bit UART ) 
TMOD = 0X20;          // Timer 1 in Mode 2.
TH1 = 0XFD;            // Baud rate of 9600.
TR1 = 1;                     // Timer run flag enabled.
}

                                                   

  :  Circuit Diagram


A terminal window is connected to microcontroller 
for serial comm. 


 
 RxD of  8051 is connected to TxD of terminal.
TxD of  8051 is connected to RxD of terminal.


Comments