Archived

This topic is now archived and is closed to further replies.

Making a programm to communicate with a mikrokontroller in visual C++ any tips?

This topic is 5046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I don''t have experience with microcontrollers but you should look for a library that meets your needs and use it. If you can''t find one, then find out how to communicate with whatever port your microcontroller is hooked up to, find out what data to send it, then send it over that port. You will most likely have to use low level programming for this.

Intro Engine

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What microcontroller are you using ? or is that the first problem ? (if you haven''t made any choices yet, it might be worth looking at the PIC series of chips)

Share this post


Link to post
Share on other sites
I could be wrong on this (never coded for microcontrollers before) but I don''t think you can just go ahead and compile code for a microcontroller, especially with MSVC. Microcontrollers usually have their own compilers (someone back me up on this?). Also note that those compilers are usually for straight C, not C++.

Then again I could be wayy off base here... can anyone provide more reinforcement?

Share this post


Link to post
Share on other sites
most controller boards have a com port that you can send data with, and often have a special debugging port that you can plug a customized debugging cable into, which will allow you to control and monitor the cpu.
which controller do you have?

Share this post


Link to post
Share on other sites
you need to find out what type of board you have (then try and find an interface cable for it), or do you just have the chip? (in which case theres not much you can do with it)

Share this post


Link to post
Share on other sites
If you''re using the RS232 port in the processor to interface to the PC, just use whichever c++ serial interface library you like or you can use the raw IO port if you''re not running a unix or WinNT variant. The protocol for communication is up to you and the biggest PITA though google should turn up some existing code.

Share this post


Link to post
Share on other sites
That sounds a bit overkill (but then again, maybe it''ll make things easier; I don''t know anything about ActiveX). Have a look here for some more information on I/O using Win32.

sam

Share this post


Link to post
Share on other sites
If you want just vanilla com port access, write code for the AVR so it understands RS232 (unless it already does? I've usually used Parallax SX-series chips, which don't). Then use Win32 CreateFile()/ReadFile()/WriteFile() using "COMX" as the filename. [edit: "COMX" where X is 1, 2, 3, 4. Of course.]

If you wanna get swanky, FTDI have a neat chip called the FT245BM, which is basically a USB interface on a chip - it talks to your micro through an 8-bit FIFO. Dead simple to use - if you get one of the premade modules, you can get it going in an hour or two.

*waves at aboeing*

[edited by - fractoid on February 25, 2004 6:53:38 AM]

Share this post


Link to post
Share on other sites
As a former EE Major, I''ve done some microcontroller work. I assume that you''re familiar with parallel/serial communications, cause you''re gonna have to pick one.

I specialize in the Microchip Corp "PIC" controller. Some models have an internal UART, which is handy. Still others have usb interfaces. In either case, memory is precious, so be careful on your implementation.

Using Visual C++, I assume you''re using the serial/parallel ports for I/O. Tricky. Windows is a protected universe, one that doesn''t take kindly to direct hardware access. I''m sure the MSDN library has something about opening up serial ports, at least. With work, you may be able to open up COM1/2/3, using high-level functions. In XP, this is your only choice. In earlier versions of windows, you can write a DOS app, and control it (the COM port) directly.

Goodluck.

Share this post


Link to post
Share on other sites
As zarthrag says, you can''t read/write data to the serial port directly using the _inp() and _outp() functions under Windows XP without first unlocking them with something like WinIo.

You can still write to them using standard RS232, through the file IO functions, as I said earlier. I believe it is much better to do it this way than the direct bit-twiddling approach. (WinIo might go away with the next version of Windows, and also if you do it the politically correct way then your code will work over a USB-to-serial converter cable, which is important if you want to run off a laptop.

Share this post


Link to post
Share on other sites