1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

8051 serial port interrupt for half duplex operation

Discussion in '8051/8951' started by mesamune80, Nov 21, 2004.

  1. mesamune80

    mesamune80 New Member

    Joined:
    Oct 14, 2004
    Messages:
    117
    Likes:
    0
    Location:
    Malaysia
    Hi, everyone i wonder how am i going to do a multiprocessor half duplex.operation with 8051 using C to write it.i want to send 5 bytes to another micro(B) then it will send back to me 5 bytes,to indicate that it received the previous 5 bytes from the 1st micro,i need a switch for the micro(A) to start transmit the 5 bytes,and when miro(A) received the 5 bytes that send by micro(B) then a LED will flash ON.Anybody has any idea how to accomplish this task?Thanks for your help i really appriciate it.
    and i need to check whether the bytes send are correct or not let say i want 1,2,3,4,5
    i have to ensure that 1,2,3,4,5 are transmitted.
     
  2. bmcculla

    bmcculla New Member

    Joined:
    Sep 5, 2003
    Messages:
    898
    Likes:
    0
    Location:
    California, USA
    Just use the UART. Its a full duplex serial interface using 2 wires. Just connect the TX on one controller to RX on the other. You might have to invert the bytes you recieve
     
  3. mesamune80

    mesamune80 New Member

    Joined:
    Oct 14, 2004
    Messages:
    117
    Likes:
    0
    Location:
    Malaysia
    :) Yes,thanks for ur information ,but do u know how to write this program using C instead of ASM ?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. bmcculla

    bmcculla New Member

    Joined:
    Sep 5, 2003
    Messages:
    898
    Likes:
    0
    Location:
    California, USA

    Code (text):


    __bit RecievedFlag = 0;
    __bit BusyFlag = 0;
    unsigned char SerialData;

    while(1)
    {
       if (RI)
       {
           RI = 0;
           SerialData = SBUF;
           RecievedFlag = 1;
       }
       if (RecievedFlag & (!BusyFlag))
       {
           SBUF = SerialData;
           BusyFlag = 1;
        }
       if (TI)
       {
           TI = 0;
           BusyFlag = 0;
          ReceivedFlag = 0;
       }
    }
    I heven't tested this code - i don't have any code on hand that just reads the UART so I just slapped this together. This code gives the general idea for reading and writing the UART. The code as is should echo characters received from the UART.
     
  6. mesamune80

    mesamune80 New Member

    Joined:
    Oct 14, 2004
    Messages:
    117
    Likes:
    0
    Location:
    Malaysia
    Thanks for the codes that u had posted!!! Now i may have some idea how to do it ^^
    Thanks for Bmcccula!!
     

Share This Page