Monday, January 9, 2017

8x8 LED Matrix

After having a LED matrix kicking around in my electronics bin for a few years I figured I should get it working. Using my experience from my EE classes I realized I could toggle the LED's by adressing the rows and columns. I first wrote code to be able to shift data into each shift register. I used 74hc595 shift registers. I figured I could use one shift register for the column and another one for the rows. The LED matrix is a common anode. To make a led light up it requires a 1 to be written on the row and a 0 to be written on the column. If a 1 is written to a column then the led will not turn on. My function to dump the data into the register first takes an 8x8 int array and then scans the column using a pattern of shifting a 0 over a line of 1's. So the first pattern it shifts in goes like:
1111 1110 0000 0000 
1111 1101 0000 0000 
1111 1011 0000 0000 
1111 0111 0000 0000 
...
The 8 zeros on the right are for the row pattern. Those will get shifted into the last shift register.

The code is essentially just going through each one of those in a for loop. The for loop has a variable called J it counts up. I also have a slice of code to take the row of the array and turn it into an integer and then I OR the array with the integer with the number above to get the data into a full binary pattern. Then I use the code I wrote to latch, load, and clear the shift register. The data is first written into the shift register. The problem with the shift register is that you need to display pattern all at once instead of doing it while the data is shifted down. So first you clock in the 1's and 0's. Then you latch the register to actually output the data in the registers. All in all it sounds simple but it was a little tough to do. It does not even use any interrupts. The next micro-controller class I will take will utilize interrupts and more advance timing techniques.  I was able to control this matrix that was comprised of 28 pins with only 3 pins of a micro-controller. A video can be found here:

Here is a video below of a simple 4x4 multiplexed pattern I did to make sure I knew what I was doing before I went on to design the 8x8 configuration:




No comments:

Post a Comment