Skip to main content

Interfacing UART with 8051

The interfacing of serial communication (UART) with 8051 micro controller, with the baud rate of 9600bps.

 Code:

#include <reg51.h>
#include <stdio.h>

unsigned char c;

void Serial_Init()
{
    TMOD = 0x20;
    SCON = 0x50;
    TH1  = 0xFD;
    TR1  = 1;
    TI   = 1;
    RI   = 0;
     
}


void delay(unsigned int i)
{
    unsigned int j,k;
    for(j=0;j<=i;j++)
    {
        for(k=0;k<256;k++);
    }
}

void main(void)
{
    Serial_Init();
    printf("Hello World \n");
    while(1)
    {
       
        delay(5);
        c = getchar();
        delay(5);
        //putchar(c);
        delay(5);       
    }                   
}


Design Proteus:


Comments

Post a Comment

Popular posts from this blog

P89V51RD2 Interfacing with the UART Serial Communication

P89V51RD2 Interfacing with the UART Serial Communication Description                     Interfacing the UART Serial Communication with the P89v51rd2 Micro controller, with the baud rate of 9600bps. The Source code and Simulator Model of this Communication is listed Below. Source : #include <reg51.h> unsigned char var; unsigned char var1; void Serial_Init() {     TMOD = 0x20;     SCON = 0x50;     TH1  = 0xFD;     TR1   = 1;       } void Transmit_Char(unsigned char x) {     SBUF =  x;     while(!TI)     {     ;        }     TI = 0; } void Transmit_String(unsigned char *s) {     unsigned char i;     while((s[i]) != 0)     {         Transmit_Char(...

ADC interfacing with 8081

Interfacing the AD0803 to the 8051 micro controller       This is the parallel port connector to the micro controller. The adc reading is transmitted to the serial port. Code: #include <reg51.h> #include <stdio.h> #define     adc_port    P1 sbit     rd = P2^0; sbit    wr = P2^1; sbit    cs = P2^2; sbit    intr = P2^3; //unsigned int adc; float adc1; void serial_init() {     TMOD = 0x20;     SCON = 0x50;     TH1  = 0xFD;     TR1  = 1;     TI   = 1;     RI   = 0;       }                    void delay(unsigned int i) {     unsigned int j,k;     for(j=0;j<=i;j++)     {         for(k=0;k...