This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Software for 8051 Uart communcation

Hi .

I am doing a Project in 8052 McU.i need to have two serial port so i thought of writing soft UART with any two GPIO..i selected P3.2,P3.3 of 8052..can anyone help me...i got some rough idea about the Software..but for a fully complted one i need ur help..can any one have sample code..am confused with serial data controlling i mean how to mimic the functionalit of SCON regster..i dnt even knw wheter it s required or not..pls help someone..

Parents
  • #include<reg52.h>
    #include<stdio.h>

    sbit TX1=P3^3;

    unsigned char SBUFF;
    bit TFLG;

    void delay(unsigned char num)
    { unsigned char i,j; for(i=0;i<num;i++) for(j=0;j<1275;j++) ;
    } void transmit_vir(unsigned char dat)
    { unsigned char tx=0,cp_data;

    cp_data=dat; TX1=0; TR0=1; while(TF0==1); TR0=0; while(tx<8) { TX1=(0x80&dat)?1:0; TR0=1; while(TF0==1); TR0=0; cp_data=cp_data<<1; tx++; } TFLG=1; TR0=1; while(TF0==1); TR0=0; TX1=1;
    } void main()
    { TMOD=0x02; TH0=0xFD; while(1) { delay(25); transmit_vir('a'); while(TFLG==1); TFLG=0; delay(25); }

    }

    Half duplex communication for virtual serial port..only TX is being implemented.is this correct

Reply
  • #include<reg52.h>
    #include<stdio.h>

    sbit TX1=P3^3;

    unsigned char SBUFF;
    bit TFLG;

    void delay(unsigned char num)
    { unsigned char i,j; for(i=0;i<num;i++) for(j=0;j<1275;j++) ;
    } void transmit_vir(unsigned char dat)
    { unsigned char tx=0,cp_data;

    cp_data=dat; TX1=0; TR0=1; while(TF0==1); TR0=0; while(tx<8) { TX1=(0x80&dat)?1:0; TR0=1; while(TF0==1); TR0=0; cp_data=cp_data<<1; tx++; } TFLG=1; TR0=1; while(TF0==1); TR0=0; TX1=1;
    } void main()
    { TMOD=0x02; TH0=0xFD; while(1) { delay(25); transmit_vir('a'); while(TFLG==1); TFLG=0; delay(25); }

    }

    Half duplex communication for virtual serial port..only TX is being implemented.is this correct

Children