Can a C program under windows talk to a microcontroller through RS232 - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Can a C program under windows talk to a microcontroller through RS232

Hi

I'm really a beginner with programming so I need some technical advise on this matter. I'm trying to build a system such that when a person enter some parameter values in a C program, it will determine a voltage that would be applied to a load. I'm guessing that the data would be transmitted to a microcontroller for the control of the voltage across the load resistor. The voltage is a DC voltage and Pulse Width Modulation would be used to get the desired DC voltage. Having these problems, I'm still uncertain whether a computer in Windows environment can talk to a microcontroller through RS232. I've talked to some computer guru and they told me that in Windows the C compiler will never be able to talk to a hardware directly. It must go through some API or something (I really don't know what he means by that!). Is that true or are there some ways to work around it? Is using C under Windows a wise choice?

My project is quite simple, the computer program will do some math to determine the DC voltage across the load, then tell the microcontroller what the DC value of the voltage should be and the microcontroller set the output voltage to that value. So hopefully, some kind person would be able to help me out with this.

Thank you very much.

Clement Ng

Comments

  • korkor Posts: 198Member
    : Hi
    :
    : I'm really a beginner with programming so I need some technical advise on this matter. I'm trying to build a system such that when a person enter some parameter values in a C program, it will determine a voltage that would be applied to a load. I'm guessing that the data would be transmitted to a microcontroller for the control of the voltage across the load resistor. The voltage is a DC voltage and Pulse Width Modulation would be used to get the desired DC voltage. Having these problems, I'm still uncertain whether a computer in Windows environment can talk to a microcontroller through RS232. I've talked to some computer guru and they told me that in Windows the C compiler will never be able to talk to a hardware directly. It must go through some API or something (I really don't know what he means by that!). Is that true or are there some ways to work around it? Is using C under Windows a wise choice?
    :
    : My project is quite simple, the computer program will do some math to determine the DC voltage across the load, then tell the microcontroller what the DC value of the voltage should be and the microcontroller set the output voltage to that value. So hopefully, some kind person would be able to help me out with this.
    :
    : Thank you very much.
    :
    : Clement Ng
    :
    :

    You're really overcomplicating things by throwing a microcontroller in the mix, but you can talk to one through the rs232 port.
    What that person was telling you was that you can't just write out to a port, you have to ask windows to do it for you, via some api (application programming interface, I believe). It should be in a library you can call.
    You should use an adc resistor network, commonly called an r2r adc, and run that through an opamp or single transistor wired for a gain of whatever, to convert the digital signal to an appropriate voltage. You'd probably want to use a transistor, since opamps don't have great current capabilities. If there's any problems with this, just ask, and I'll see if I can help figure it out more.
  • AsAdiAsAdi Posts: 117Member
    : : Hi
    : :
    : : I'm really a beginner with programming so I need some technical advise on this matter. I'm trying to build a system such that when a person enter some parameter values in a C program, it will determine a voltage that would be applied to a load. I'm guessing that the data would be transmitted to a microcontroller for the control of the voltage across the load resistor. The voltage is a DC voltage and Pulse Width Modulation would be used to get the desired DC voltage. Having these problems, I'm still uncertain whether a computer in Windows environment can talk to a microcontroller through RS232. I've talked to some computer guru and they told me that in Windows the C compiler will never be able to talk to a hardware directly. It must go through some API or something (I really don't know what he means by that!). Is that true or are there some ways to work around it? Is using C under Windows a wise choice?
    : :
    : : My project is quite simple, the computer program will do some math to determine the DC voltage across the load, then tell the microcontroller what the DC value of the voltage should be and the microcontroller set the output voltage to that value. So hopefully, some kind person would be able to help me out with this.
    : :
    : : Thank you very much.
    : :
    : : Clement Ng
    : :
    : :
    :
    : You're really overcomplicating things by throwing a microcontroller in the mix, but you can talk to one through the rs232 port.
    : What that person was telling you was that you can't just write out to a port, you have to ask windows to do it for you, via some api (application programming interface, I believe). It should be in a library you can call.
    : You should use an adc resistor network, commonly called an r2r adc, and run that through an opamp or single transistor wired for a gain of whatever, to convert the digital signal to an appropriate voltage. You'd probably want to use a transistor, since opamps don't have great current capabilities. If there's any problems with this, just ask, and I'll see if I can help figure it out more.
    :
    ***********************************************************************
    Surely you can talk to your micro controller via Rs232 port,you can use
    a simple program,I have written in VC++6.0,on this site,its name is TxRx
    and includes source code for sending and receiving bytes via serial port.you can use some parts of its code,or send your binary file using it's exe file.If you can't find it,let me know and send it for you directly,via my mail box on this site,or [email protected]

    You can use Max232 chip,a TTL/CMOS<--->RS232 voltage convertor on the micro controller side using 5V,can provide your circuit RS232 standard voltages.

    hope you success:))
  • XsirAubreyXsirAubrey Posts: 75Member
    I recently got into microcontrollers such as the BASIC Stamp or ATOM-40M. You can get thier board that connects to the RS232 port of your PC and the board has a RS232 port.

    But microcontrollers, at least the BASIC Stamp and ATOM are designed to be self-contained. Meaning you download a program code to it and it runs. A good example of this, and what they are primarily used for, is robotics, the 'brains'. Not really designed for back and forth communication with a PC. But really all ya need to read analog voltages to digital is to feed a A/D converter through a MAX232 chip (for the simpliest form of analog voltage reception to a PC). You could make your Voltage Sensor activate (transmit the digital form of the voltage) on the activation of the RTS pin of the RS232.

    XsirAubrey
    The search for knowledge is endless.

  • quicksightsquicksights Posts: 15Member
    check out iguanalabs.com and boondog.com you can use both circuits at the best of your interests. experiment using the best possible circuit for your application use a breadboard for testing adc and dac circuits.
    the microprocessor used in this kind of projects are programmed for digital signal processing. for example computations or conversions on your desired data and processing it for transmission for communication to pc. for communicating using the rs232 you need a rs232 traslator and driver ic. the signal must be +10v and -10v unlike the +5v and 0v by the printer port.

    oh yeah that codeguru must be sick I think he was talking about visual basic. c is the best way to communicate to hardware using outport, inport, outp, inp, outportb, inportb commands. you can communicate and make appreciable user friendly softwares with interface.

    you can also make your software using visual basic and if you need some speed and you still have some homoerectus, java man, or peking man genes use the prehistoric software . . use "ASSEMBLY"

    the best advice that i could give you is go to the basics when designing devices and softwares. make a block diagram take all the time you need. from the diagram you can already make codes for one block. peice it all together. ask for second opinions from your colleagues verify and verify same with the hardware.

    VIOLA . . . youll finish your project in no time thats what i do im not a 100 percent expert and i dont know everything but this helps





Sign In or Register to comment.