Thread: c code for led

  1. #1
    Registered User
    Join Date
    Apr 2012

    c code for led


    I am just started to learn embedded c
    how to write c program for LED to turn ON/Off

  2. #2
    Registered User
    Join Date
    Jun 2005
    C is insufficient for that. You need more information.

    Generally, for your program, toggling some bit will toggle whether the LED is on or off. That is trivial to program. The hard bit is the mapping of that bit so that, when it changes, a circuit sees some specified voltage.

    Basically, assuming there is some device with a LED, there will be some circuitry. Essentially, you will need to provide a specified voltage to some wire to turn the LED on, and some other specified voltage to turn it off. For example, at least 4 volts might need to be applied to some pin to light a specified LED, and the LED will be "off" if the voltage on that pin is reduced to (say) 1 volt. The design of the circuit will also limit other electrical properties such as maximum and minimum current (a large current can burn out small wires) and resistance (a LED is usually in series with a suitably selected resistor, as LEDs tend to stop working if too much current is passed through them).

    Then there is the means of connection of that circuit to a computer. That means of connection might be via some computer port, or some dedicated expansion card that is inserted into a PCI slot. Then the problem becomes one of communicating with that computer port or card. The techniques depend on the device - the method of communicating with a device via a USB port differs from the method of communicating with a device via a parallel port, and a different method is involved in communicating with a PCI device.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    while ( 1 ) led ^= 1;

    Minimally, that's all there is to it.

    But without more information about your board, how fast the clock is, how to program a delay, which CPU I/O port the LED is wired to (etc etc), we can't say much else.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-10-2010, 11:28 AM
  2. Replies: 14
    Last Post: 04-01-2008, 02:23 AM
  3. producing c/c++ code from flowcharts,pseudo code , algorithims
    By rohit83.ken in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2008, 07:09 AM
  4. Having trouble translating psudeo-code to real-code.
    By Lithorien in forum C++ Programming
    Replies: 13
    Last Post: 10-05-2004, 07:51 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM