We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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!
"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.
HANDLE hSerial; BOOL w_ret; DWORD write = 19;
Thanks....where can I find that sample?
"Thanks....where can I find that sample?" If you need to ask, then you need to start with the uVision Getting Started guide - it'll be in the uVision 'Books' tab, or see the 'Help' menu.
In The sample folder where you installed Keil. 1 - the 8052 and windows programming are different. None of the windows APIs will work. In general Windows APIs are unique to windows. 2 - C and C++ are not the same languge 3 - the 8052 has very limit RAM and ROM Take care or run out.