Ok, here goes my first attempt at a "write up"
I am currently working on a project using this chip. Most of the information you need to know can be found in the data sheet. Unfortunatly the datasheet can be vauge in some parts so here are the basics:
The first thing you need to know is that on initial power up, all control registers are reset, the display is blanked, and the IC enters shutdown mode. The chip may be programed while in shutdown mode.
The first steps to get the IC to work correctly are initializing the IC. here are the key things you need to tell the chip in your intialization routine.
- how many digits will you be displaying (1 - 8)*
- which digits will use the internal decoder
- intensity of display
* there are special circumstances to take into account if you are using 3 or less digits. Refer to the data sheet.
The next thing (and most important) people are going to want to know is how to actually send the data to the chip. You will need 3 lines from your PIC. A data line, a clock, and a latch enable. To address the IC you need to send 16 bits of data, MSB first, with the upper 8 bits being the address, and the lower bits being the data. Here is an example of how to send out the data to the chip:
Code:
' In your pics initialization code define the pins for Sout, Clk, and LE where:
' Sout = pin for sending data to the data in pin on the max 7219
' Clk = pin for clock
' LE = pin for Load/Enable
SendCommand:
' the spec sheet states "The last 16 bits of data are latched on LOAD's rising edge"
' It also states for the 7221 chip that LOAD/CE must be held low to clock in data
' So for best practice and compatibility the first step is to bring LE low.
' The next step is to clock out the 16 bits of data MSBFIRST. This is easily accomplished
' with the shiftout command. Please be sure to include the "modedefs.bas" file at the
' begining of your code for this code to execute correctly.
' In this example there are two 8 bit variables named Addr, and cmd. Addr is the address
' of the register we want to address. cmd is the data we want to send to the register.
' Finaly, we need to latch the data sent by bringing LE high
Low LE ' Serial data latches on LE high
shiftout Sout,Clk,MSBFIRST, [Addr,cmd] ' Shift out cmd address
High LE ' Latch Data
Return
Now that we know how to send the register/data commands to the MAX7219, Lets examine the registers. The first register we will want to define is how many digits we are using. Looking at the spec sheet we see that the ScanLimit register is where we define the number of digits, and its address is hex 0B (or 11 decimal). Lets say we want to use 4 digits. We will need to send the value of 3 to address hex 0B (Digits are numbered 0 - 7). We can accomplish this with the following code:
Code:
Addr = $0B
cmd = $03
Gosub SendCommand
Lets take another example. This time we will tell the IC which digits we want to use the internal decoder. We will have all 4 digits display numeric data so we look up the value in table 4. We can see by the table we will need to send an 8 bit value from 0 - 255. Each bit in the value represents a digit, and to have the digit use the decoder we set the bit for that digit to 1. To use direct LED addressing, we set the bit for that digit to 0. For clearity, we will write this value in binary format. Since we want the first 4 digits to use the decoder we will send a value of %00001111 to Register $09
Code:
Addr = $09
cmd = %00001111
Gosub SendCommand
So as you can see, the chip is farily simple to use. Its simply a matter of telling the chip what address you want to load what value into and sending the 16 bit data.
To actually display a value, address that digits register and send the value as the data. so for instance, to display a value on our 4 digit example we could use the following routine:
Code:
UpdateDisplay:
' X must contain value to display.
' Y is a byte value
For y = 0 to 3 ' address digits 1 - 4
addr = Y + 1 ' Compensate for address value to digit number drift
Cmd = X Dig y ' Get the numerical value of place value in X
Gosub SendCommand ' Send the command
Next y
Return
The above code will update all 4 digits of the display. Keep in mind that the digits may be addressed individually. For instance, lets say you are displaying a value of 3856 and you want to display a new value of 3456. You would only need to update address 2 (digit 3) to the number 4. the spec sheet also states that these values will be retained so long as V+ exceedes +2VDC
There is a built in lamp test function. VERY usefull for verifying hardware connections. Please see the data sheet for its register and data information
Before the chip will display information you will need to address the ShutDown register and bring it out of shutdown mode. Applying a value of 1 to this register will put the device in normal operation while applying a value of 0 will put the device in shutdown. This is somewhat counter-intuitive based on the name of the register.
Finaly, one more area where people may trip up on the hardware end is the value of Rset. If this is not set correctly you may end up with unpredictable or undesireable results. Looking at table 11 you are presented with values based on segment current and LED Forward Voltage. The values in the chart are resistance values in K-ohms. For example, if our display has a Forward voltage of 2.0 volts, and the desired current is 20mA, we would select a value of
28K for the Rset resistor value. You can determine this if you are aware the spec sheet states Rset should not be less than 9.53K, however with the table alone this is not very clear.
I hope this helps clear up the basics of how to use this IC. Using the chip as a basic numeric display driver is fairly straight forward. I myself have been running into issues with using combined decoder and direct LED addressing modes. I will attempt to do another write up specificaly on this subject when I figure it out myself.
Bookmarks