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 Reply Children
  • hi,
    thanks for u r response,i read the link u provided.Am actually a bit confused collecting data bit wise.am suing only 3 line from serial to USB connector.
    1.a sample data collection UART algorithm,sub routine after listening to External interrupt pin(P3.2)

    void recev() routine to recieve
    {
      unsigned char r=0;
      bit sbuff[8];
    
     if(P3.2==0)   //start bit detection
     while(r<8)
     {
        sbuff[r]=P3.2;
        r++;
        TR0=1;
          while(TF0==1);       //delay in between bits Timer 0 is used
        TR0=0;
     }
    if(P3.2==1)    //stop bit condition achieved
     TFLG=1;      //flag to indicate the receive has completed
    }
    void transmit_vir(unsigned char dat)  //a simple transmisson algorithm
    {
       unsigned char tx=0,cp_data;
    
            cp_data=dat;
    
            TX1=0;                                  //start bit
            TR0=1;               //timer start
                                    while(TF0==1);
            TR0=0;
            while(tx<8)
            {
                TX1=(0x80&dat)?1:0;    //8-bit data
                TR0=1;
    
                while(TF0==1);
                TR0=0;
                cp_data=cp_data<<1;
                tx++;
            }
          TFLG=1;                   //transmission flag
          TR0=1;                    //baud rate
    
           while(TF0==1);
            TR0=0;
            TX1=1;                                          //stop bit
    }
    

    while transimisson which only i copiled and burned to my MCU i got a 'FC' data on my hyper-terminal..read so many articles in google they are telling for a simple communication handshaking is not required. that's y i developed like this since my need is urgent Tomorrow is my dead line..

  • If your dead line is to morrow then may be you should consi der stop bits.

    And another thing - are you sure your code uses the same bit order as the other side for your data bits?

  • i need result rather than time.i have provided stop bits there...then one more thing is hyper terminal has a specific code to accept data.i mean whether LSB or MSB which should go out first.is my logic correct which i implemented here..any comments..since no one here to guide me as well

  • Why you ask? Did you read the link I posted?

    You really have stop bits?
    And how many bit times do you hold your stop bits?
    And what is your delay after the while loop, but before your "stop bit" line?

  • while transimisson which only i copiled and burned to my MCU i got a 'FC'
    this could be the result of badly mismatched send and receive.
    set it to transmit 'U' (uppercase U) continously and scope the output.

    No, I am not going to tell you what to look for, If you can't figure that out, you should not have started this project.

    Erik

  • eric am not asking to any one to help me in my code..am askng about for exper opinion..do architechture play any role in it..

    now i rewrote my code:

    here i took ACC^0 to store LSB and send it out..and so on finally MSB..
    and a delay with timer0 in 8 bit auto reload mode..to get bit gap in between..and for start and stop bits as well...

    i referd bit bagging in wiki and followed the same procedure..and implemented in my code..

    is this delay genration relable or i have to put a couple of loops to generate one..

  • am askng about for exper opinion
    you got that
    read the replies above