3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

How to drive a lot of LEDs from a few microcontroller pins.

Step 6Software

The software gets a bit messy for serveral reasons:

1) for the PCBs shown, the LEDs are laid out in a way that is convenient
to the PCB layout, rather than in "correct" bit order. IMO, this is the
way to do things, but it does mean that Row 1 doesn't necessarilly mean
bit 1, or coluimn 3 doesn't mean bit 3. This requires a level of mapping
between the usual row/column addressing and the bits that need setting.

2) Since the same bits are used for anodes and cathodes, the common
(row) connection for some bits can be in the middle of driven (column)
bits. That means you have to shift column bits around depending on whether
they are before or after the row bit for that set of columns.

3) You have to derive output words for both the ioport and the port direction
register.

The attached ASM code for ATtiny11 is a "proof of concept." It's embarassingly
un-optimized and poorly commented, but it's all I've got written so far.
« Previous StepDownload PDFView All StepsNext Step »
1 comment
Jan 2, 2012. 9:21 PMbpark1000 says:
You mention the trick of re-arranging the bits to make the circuit board simpler. Good plan! The way to do it easily is to first write the software as if the bits didn't need switching. Instead of writing the output byte directly to the port, you first write it to the index register. Then you use a "scramble table" to re-arrange the bits. You index into the table, then write that byte to the port. The advantage of this scheme is if you need to change the bit order, no change is needed to the code; only the table.

(I'm not familiar with this processor. My comments are based on the ability to do indexed addressing mode.  Index into a table. For example, for the "noadjust" routine, you would have:
TABLE: .byte 0b00100, 0b00010, 0b00001, 0b10000, 0b01000

copy TEMP to index register
load accumulator TABLE,index
copy accumulator to ANODE
...
You can have separate tables for the port and the direction register. The tables can be large (256 bytes for an 8-bit scramble function) without needing a compare for each value possible. The code becomes compact and easy to debug. You can stack tables. For example, one set to give the port/direction drives, and one to do the bit scrambling (used twice: once to scramble the port bits, again to scramble the direction bits)).

Table lookup is the key to fast processing!

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
157
Followers
29
Author:westfw
Middle aged geek username also works at yahoo.com, mac.com, comcast.net, wharton-10.arpa