LED Display Matrix – Code

Code Initialization Block and First Frame

The code for this project was created entirely in Assembly. The Xplained Mini ATmega328P served as a matrix driver for a 9×9 grid, 18 pinout of two cathode, common anode Red-Green LEDs. The LEDs were designed to have two addresses in mind, one for each combination of cathode and anode. With 81 LEDs, this created 162 addresses. To activate a single LED, the cathode bit was written to sink and the anode was written to source current using the PINB, C and D pins as outputs. The Xplained Mini ATmega328P requires the DDRn and PORTn registers to be assigned before the pinouts PINB, PINC, and PIND can be used.  The DDRn register designates PINn as an input or output. Writing to PORTn determines what PINn outputs—even if it is designated as an input. When both a DDRn and PORTn bit are 0, the output becomes a high-impedance tristate value. This effectively cuts off any connection to the LED inputs, leaving all 18 inputs driven high to VCC, and no LEDs turned on. Activating DDRn to set PINn to an output, and writing PORTn to 0 turns a PINn to sink, activating cathodes on the line. When PORTn is 1 while an output, PINn becomes a source activating any anodes on the line.

In configuring the LED frames, the mapping of the LED pinouts was crucial. Due to programming in Assembly, knowing which bits of the DDRn and PORTn registers was required for every frame to be displayed on the final matrix. An excel mapping of LED pinouts for desired frame animations was created. This map allowed for groupings of LED addresses that could be turned on at the same time without activating other LEDs connected in series.  Combining LEDs for activation reduced the code from a theoretical 894 lines of code to 272 (not including repetitive lines for subroutine calls or testing code).

In total, 4 unique frames were programmed in their own subroutines.  A 5th subroutine was created to act as a loop between the others, displaying the 4 frames as an animation cycle to an observer of the LED Display Matrix.