c code for led

This is a discussion on c code for led within the C Programming forums, part of the General Programming Boards category; Hello I am just started to learn embedded c how to write c program for LED to turn ON/Off...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    4

    c code for led

    Hello

    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
    Posts
    6,261
    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%.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,497
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-10-2010, 10: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, 06: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, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21