Electronic – How to control 8 LEDs with a timing delay with only one microcontroller (PIC12) written in Assembly

assemblyledmicrocontrollerpictiming

I can have 5 I/O pins enabled. I'm just confused on how to control them individually.

Best Answer

You don't have enough I/O to drive each one straight from the microcontroller. There's two ways around this.

1) You need an external 3 to 8 (or 4 to 16) decoder which transforms your n I/O lines into 2^n I/O lines. 74154 or 74238 will do the trick. Downside: it's additional hardware, but the upside is it's very very easy to drive. Another option is 74595, which are serial to parallel shift registers that can be daisy chained for effectively infinite I/O.

2) You can scan two banks of 3 LEDs using 2 control lines and 3 data lines. The control lines connect to the negative ends of the LEDs while the data lines connect to the positive. It looks like a grid where your control line are on the X axis, data on they Y axis, and LEDs wherever the two lines intersect. You turn on LEDs 1 to 3 by pulling Control 1 low so there can be a potential difference across them and Control 2 high so LEDs 4-6 stay off. Whatever LEDs you want on you turn high on the data line. You then take control 2 low and control 1 high and you set your data lines to turn on LEDs 4-6 while forcing LEDs 1-3 off. Since you wanted only 5, just don't put in a 6th in the second bank. You alternate fast enough so that it's imperceptible to the eye. This doesn't need anything external but its harder to do in software.

Make sure you have current limiting resistors!