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
  • 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..

Reply
  • 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..

Children