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

serial communication 8051 from PC

How can I using C Compiler in order to communication between 8051 with PC via serial port using RS232. I want to have an Example for Keil C for 8051 and an example Visual basic for Receive/transmitter on PC.Thank You very much.

Parents
  • Hmm, you know, UART of PC is able to support 11-bit mode without problems. We use such mode in our API, really (=

    For example, to send ninth bit as zero you should do next (here we define PORT value as 0x3F8 for COM1):

    _outp(PORT+3, (32+16+8+2+1)); //set mode: 8 data bits, 1 stop bit, parity bit always is zero
    _outp(PORT+0, data); //sending one start bit, 8 data bits, parity bit as 0 and one stop bit

    To send ninth bit as 1 do next:
    _outp(PORT+3, (32+8+2+1)); // parity bit always is 1
    _outp(PORT+0, data);

    To read COM port with 11-bit mode you should use next routine:

    int ReadByte (unsigned int time_out)
    {
    unsigned int data, timeout = time_out;
    unsigned char status;

    _outp(PORT+3, (32+8+2+1)); // wait for parity bit as 1

    while (! ((status = _inp(PORT+5)) & 1))
    {
    if (! timeout--) return (-1); // timeout
    }
    data = (int)_inp(PORT+0);
    if (status & 8) return (-2); // frame error

    if (!(status & 4)) data += 256;
    return (data); // ninth bit of data is TB8
    }

    Btw, it is only example; we use different routine (based on COM interrupt). Anyway these examples are worked; we tested it on Win98 with 115200 baudrate.

    Good days!

Reply
  • Hmm, you know, UART of PC is able to support 11-bit mode without problems. We use such mode in our API, really (=

    For example, to send ninth bit as zero you should do next (here we define PORT value as 0x3F8 for COM1):

    _outp(PORT+3, (32+16+8+2+1)); //set mode: 8 data bits, 1 stop bit, parity bit always is zero
    _outp(PORT+0, data); //sending one start bit, 8 data bits, parity bit as 0 and one stop bit

    To send ninth bit as 1 do next:
    _outp(PORT+3, (32+8+2+1)); // parity bit always is 1
    _outp(PORT+0, data);

    To read COM port with 11-bit mode you should use next routine:

    int ReadByte (unsigned int time_out)
    {
    unsigned int data, timeout = time_out;
    unsigned char status;

    _outp(PORT+3, (32+8+2+1)); // wait for parity bit as 1

    while (! ((status = _inp(PORT+5)) & 1))
    {
    if (! timeout--) return (-1); // timeout
    }
    data = (int)_inp(PORT+0);
    if (status & 8) return (-2); // frame error

    if (!(status & 4)) data += 256;
    return (data); // ninth bit of data is TB8
    }

    Btw, it is only example; we use different routine (based on COM interrupt). Anyway these examples are worked; we tested it on Win98 with 115200 baudrate.

    Good days!

Children
No data