I'm new to embedded systems so apologies if this is a stupid question.
I am trying to implement a binary counter in the form of 8 LEDs. I want to send an 8-bit binary number through USART and have the 8 LEDs display the number (led off if bit is 0, led on when bit is 1).
What would be the best method to do this?
Best Answer
The built-in UART already decodes the serial signal into bytes. Put another way, the hardware delivers you the byte you want directly. Your question then comes down to how to drive 8 LEDs from the 8 separate bits of a byte somewhere in the processor.
The easiest solution is to use 8 output pins. It would be particularly easy if these are all driven by the same output port register internally. In that case, you simply write the byte to the port register.
If the output lines are scattered among different port registers, then in the worst case you set each bit individually. Test the LSB of the input byte, then set or clear the port bit for that LED. Then test bit 1 and set or clear the port bit for the next LED, etc.
The simplest electrically is to drive each LED directly from its output pin:
If the LED drops 2.1 V (typical for common green), then it will have about 5 mA thru it when the digital signal is high. That will be plenty bright enough with a modern LED to easily see in a typical office environment.