Hello
I am just started to learn embedded c
how to write c program for LED to turn ON/Off
Printable View
Hello
I am just started to learn embedded c
how to write c program for LED to turn ON/Off
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.
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.