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

How to write to COM port with Cx51

Does anyone know how I can write to the COM port on the 8051? I know how to do so in Visual C++ but I'm not sure if its the same way. In Visual C++, I would use the following code:

HANDLE hSerial;
BOOL w_ret;
DWORD write = 19;
char buf[20] = {0};

hSerial = CreateFile("COM1",GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);

COMMTIMEOUTS cto = {MAXDWORD, 0, 0, 0, 0 };

w_ret = WriteFile(hSerial,buf,write,&write,NULL);

Thanks!

Parents
  • "Does anyone know how I can write to the COM port on the 8051?"

    An 8051 does not have a "COM Port" - that is an IBM-PC term.

    On an 8051, you have to deal directly with the UART - that's the hardware that does asynchronous serial comms (which is what a "COM Port" does on a PC).

    In fact, almost everything on an 8051 will require you to deal directly with the hardware - you do not have a massive Operating System, Object Frameworks, Foundation Classes, etc, etc...
    Just the good ol' ANSI 'C' standard library.
    (well, most of it).

    Look at the "Hello, World" sample Project - it writes "Hello, World" to the 8051 serial port.

    The uVision Getting Started guide takes you through the project step-by-step.

Reply
  • "Does anyone know how I can write to the COM port on the 8051?"

    An 8051 does not have a "COM Port" - that is an IBM-PC term.

    On an 8051, you have to deal directly with the UART - that's the hardware that does asynchronous serial comms (which is what a "COM Port" does on a PC).

    In fact, almost everything on an 8051 will require you to deal directly with the hardware - you do not have a massive Operating System, Object Frameworks, Foundation Classes, etc, etc...
    Just the good ol' ANSI 'C' standard library.
    (well, most of it).

    Look at the "Hello, World" sample Project - it writes "Hello, World" to the 8051 serial port.

    The uVision Getting Started guide takes you through the project step-by-step.

Children