The Trick
Yes, like everything, there's a trick. The trick is that there are never more than 8 LEDs illuminated at one time.
For this to work well, a bit of crafty programming is needed. The concept I have chosen is to use a timer interrupt. Here's how the display interrupt works in plain english:
- Timer counts up to a certain point, when reached the interrupt service routine is run.
- This routine decides which row is the next one to be displayed.
- The information for the next row is looked up from a buffer and shifted into the column driver (this information is not "latched" so it is not yet displayed).
- The row driver is shut off, no LEDs are currently lit.
- The column driver is "latched" make in the information we shifted in two steps ago the current information to display.
- The row driver then provides current to the new row we are displaying.
- The interrupt service routine ends and program returns to normal flow until the next interrupt.
This happens very very quickly. The interrupt is thrown every 1 mSec. This means that we're refreshing the entire display about once every 8 mSec. This means a display rate of around 125Hz. There is some concern regarding brightness because we are essentially running the LEDs at a 1/8 duty cycle (they are off 7/8 of the time). In my case I get an adequately bright display with no visible flashing.
The full LED display is mapped out in an array. In between interrupts the array can be changed (be mindful of atomicity) and will appear on the display during the next interrupt.
The specifics of writing code for the AVR microcontroller and of how to write code to talk to the shift registers is beyond the scope of this instructable. I have included the source code (written in C and compiled with AVR-GCC) as well as the hex file to program directly. I have commented all of the code so you should be able to use this to clear up any questions about how to get data into the shift register and how the row refresh is working.
Please note that I am using a font file that came with the ks0108 universal C library. That library can be found here:
http://en.radzio.dxp.pl/ks0108/Update:Shift Registers: How To
I've decided to add a bit about how to program with shift registers. I hope this clears things up for those who haven't worked with them before.
What they doShift Registers take a signal from one wire and output that information to many different pins. In this case, there is one data wire that takes in the data and 8 pins that are controlled depending on what data has been received. To make things better, there is an outpin for each shift register that can be connected to the input pin of another shift register. This is called cascading and makes the expansion potential an almost unlimited prospect.
The Control PinsShift registers have 4 control pins:
- Latch - This pin tells the shift register when it is time to switch to newly entered data
- Data - The 1's and 0's telling the shift register what pins to activate are received on this pin.
- Clock - This is a pulse sent from the microcontroller that tells the shift register to take a data reading and move to the next step in the communication process
- Enable Output - This is an on/off switch, High=On, Low=Off
Making it do your bidding:Here's a crash course in the operation of the above control pins:
Step 1: Set Latch, Data, and Clock low
- Setting the Latch low tells the shift register we are about to write to it.
Step 2: Set Data pin to the logic value you want to send to the Shift Register
Step 3: Set Clock pin high, telling the Shift Register to read in the current Data pin value
- All other values currently in the Shift Register will move over by 1 place, making room for the current logic value of the Data pin.
Step 4: Set the Clock pin Low and repeat steps 2 and 3 until all data has been sent to the shift register.
- The clock pin must be set low before changing to the next Data value. Toggling this pin between high and low is what creates the "clock pulse" the shift register needs to know when to move to the next step in the process.
Step 5: Set Latch high
- This tells the shift register to take all of the data that has been shifted in and use it to activate the output pins. This means that you will not see data as it is shifting in; no change in the output pins will occur until the Latch is set high.
Step 6: Set Enable Output high
- There will be no pin output until the Enable Output is set to high, no matter what is happening with the other three control pins.
- This pin can always be left high if you wish
CascadingThere are two pins you can use for cascading, Os and Os1. Os is for fast rising clocks and Os1 is for slow rising clocks. Hook this pin to the data pin of the next shift register and the overflow from this chip will be entered into the next.
End of updateAddressing the display
In the example program I have created an array of 8 bytes called row_buffer[]. Each byte corresponds to one row of the 8x8 display, row 0 being the bottom and row 7 being the top. The least significant bit of each row is on the right, the most significant bit on the left. Changing the display is as easy as writing a new value to that data array, the interrupt service routine takes care of refreshing the display.
Programming
Programming will not be discussed in detail here. I would warn you not to use a DAPA programming cable as I believe you will be unable to program the chip once it is running at 12MHz. All other standard programmers should work (STK500, MKII, Dragon, Parallel/Serial programmers, etc.).
Fuses:Make sure to program the fuses to use the 12MHz crystal
hfuse: 0xC9
lfuse: 0xEF
In Action
Once you program the chip the display should scroll a "Hello World!". Here is a video of the LED matrix in actions. The video quality is pretty low as I made this with my digital camera's video feature and not a proper video or webcam.
Attachments