Submitted by:
Glenn Clark
VersaTech Electronics
The programs and drawings shown below are taken from the examples section of the manual.
In the last examples, we used the I2C bus to communicate to peripheral ICs. The I2C bus is sometimes called the 2-wire bus. In this example we will use a 3-wire bus, another serial standard, to communicate with a MAXIM IC designed for driving multiplexed numeric LED displays. The IC is the MAX7219 8-Digit LED Display Driver. This IC drives a matrix of LED's so that 256 individual LED's can be driven from a single 24 pin IC. The magic of this technique is called multiplexing (time multiplexing to be exact). This means that at any given point of time, only 8 LED's are being driven, but each 8 LED's is driven in quick succession over time. Our eyes interpret this blur as the desired pattern; all LED's which received any drive appear to be on continuously. This is similar to our first example where two LED's blinked alternately, when there was no delay in the loop, both LED's appeared to be on continuously. This IC is called a digit driver because 7 segment LED digits contain 8 LED's (7 segments and a decimal point) that share a common cathode or anode. By connecting all the same segments together and calling them rows, and using each of the 8 digits common cathodes at columns, an 8 x 8 matrix of diodes is created. If you just want to control LED's and not digits, you can electrically arrange your diodes in groups of 8 that share a common cathode. This has been done often for Christmas displays. The circuit for this example is shown below. There are no real surprises here, multiple 7219s can be daisy chained for more LED drivers yet. The program simply lowers the "load /CS" line, shifts 16 bits of data into the Din pin using the clk pin, and the communication is complete. A resistor is used with the Iset pin to Vdd. This sets the maximum drive for any segment
The program for interfacing to the 7219 is also elementary. Each communication sends 16 bits which is comprised of 8 data bits and 4 bits of register address. The remaining 4 bits are unused. The 16 bits are sequentially shifted out the D2 pin and clocked into the 7219 using the D3 pin. The 16th bit shifts out first and each bit is latched in on the rising edge of clk. A subroutine takes care of shifting out the 16 bits. DEF statements define constants used to refer to each of the registers in the 7219. The program simply lights every LED in each row then every LED in each column in succession.
DEF tic62_c LIB fbasic.lib DEF max7219_data pin_d2 DEF max7219_clk pin_d3 DEF max7219_load pin_d1 DEF max7219_dig0 0x0100w DEF max7219_dig1 0x0200w DEF max7219_dig2 0x0300w DEF max7219_dig3 0x0400w DEF max7219_dig4 0x0500w DEF max7219_dig5 0x0600w DEF max7219_dig6 0x0700w DEF max7219_dig7 0x0800w DEF max7219_decode 0x0900w DEF max7219_intens 0x0A00w DEF max7219_limit 0x0B00w DEF max7219_shutdn 0x0C00w DEF max7219_test 0x0F00w GLOBAL word cur_row GLOBAL byte cur_col FUNC none max7219_send PARAM word max_comm PARAM byte max_data LOCAL word max_result LOCAL byte bit_counter 16b BEGIN =( max_result, +( max_comm, max_data )) pin_low( max7219_clk ) pin_low( max7219_load ) REP IF >=( max_result, 0x8000w ) pin_high( max7219_data ) ELSE pin_low( max7219_data ) ENDIF pin_high( max7219_clk ) --( bit_counter ) pin_low( max7219_clk ) =( max_result, <<( max_result )) UNTIL ==( bit_counter, 0b ) pin_high( max7219_load ) ENDFUN
FUNC none main BEGIN ; start by initializing the display max7219_send( max7219_decode, 0y00000000b ) ; numeric decode max7219_send( max7219_intens, 0y00001111b ) ; full brightness max7219_send( max7219_limit, 0y00000111b ) ; all rows (digits) on max7219_send( max7219_shutdn, 0y00000001b ) ; normal operation max7219_send( max7219_test, 0y00000001b ) ; test in progress delay( 500 ) ; one half second of LED test max7219_send( max7219_test, 0y00000000b ) ; no test in progress REP ; test rows independently =( cur_row, max7219_dig0 ) REP max7219_send( cur_row, 0y11111111b ) ; All 8 LED's on delay( 250 ) ; wait 1/4 second max7219_send( cur_row, 0y00000000b ) ; all 8 LED's off =( cur_row, +( cur_row, 0x0100w )) ; next row UNTIL ==( cur_row, max7219_dig7 ) ; test columns independently =( cur_col, 0y00000001b ) REP max7219_send( max7219_dig0, cur_col ) max7219_send( max7219_dig1, cur_col ) max7219_send( max7219_dig2, cur_col ) max7219_send( max7219_dig3, cur_col ) max7219_send( max7219_dig4, cur_col ) max7219_send( max7219_dig5, cur_col ) max7219_send( max7219_dig6, cur_col ) max7219_send( max7219_dig7, cur_col ) ; turn of col LED's delay( 250 ) max7219_send( max7219_dig0, 0b ) ; turn off col LED's max7219_send( max7219_dig1, 0b ) max7219_send( max7219_dig2, 0b ) max7219_send( max7219_dig3, 0b ) max7219_send( max7219_dig4, 0b ) max7219_send( max7219_dig5, 0b ) max7219_send( max7219_dig6, 0b ) max7219_send( max7219_dig7, 0b ) =( cur_col, <<( cur_col )) UNTIL ==( cur_col, 0b ) LOOP ENDFUN
Protean Logic Inc. Copyright 05/06/04 Top of Page