MAX7219 (the return, but almost with a happy ending).

marcos.placona

Senior Member
Hi guys,

I've initiated a thread some days ago about the interface between picaxe and the MX7219 7 segment display driver.

I was having some trouble to understand it's inner workings as well as the registers and etc (Ok, I know, I was having trouble to understand the datasheet.)

westaust55 has given me a great help in that telling me how to interpret everything, and fgnash sent me a code sample which really helped me to understand everything.

I've made some changes to fgnash's code, and now I've got it to work properly.

I could have used the same thread, but I thought it'd complicate things, as the code has suffered some big changes along the time.

I just found an issue now, and wanted to know if anybody has encountered the same problem. The display works flawlessly, but it seems to be "caching" data sometimes, specially when I work with ASCII characters such as H, L etc....

On the first power up, it displays it right. If I try to re-program it to display other characters, it will restart, and have all the displays fully lit up.

The datasheet says the following:

On initial power-up, all control registers are reset, the
display is blanked, and the MAX7219/MAX7221 enter
shutdown mode. Program the display driver prior to
display use. Otherwise, it will initially be set to scan one
digit, it will not decode data in the data registers, and
the intensity register will be set to its minimum value.
The bold part is exactly how it happens.

In regards to: "Program the display driver prior to display use."

I believe it's exactly what I'm doing, but still I'm getting this result every now and then....

In regards to it be "caching" information, every time I display a letter (doesn't happen with numbers), I have to go through the process of removing the power from my displays to get it to display again, otherwise it will fall into the condition mentioned by the datasheet. After powering up, even if I try to display numbers, it'll still display the last set of characters I displayed before the power removal.

I can live with that, but it's pretty annoying have to remove the power every time I display letters.

Strangely enough, nothing of that happens if I just use numbers.

I'm putting my code below, and would appreciate if somebody could give me some help with it, or tell me about ways to improve it.

Thanks in advance.

Code:
' IO pins - Output
symbol DIN7219     = 0  '7219 DIN pin0
symbol LOAD7219     = 1  '7219 CS pin1
symbol CLK7219     = 7  '7219 CLK pin7
symbol number     = b9 'the selected number

'------------

' initialize 7219 control pins
low DIN7219
low CLK7219
low LOAD7219

' Registers
b3 = $09 'register = Decode Mode (%00001001)
b2 = $ff 'use BCD code B for all possible digits (%11111111)
gosub Write7219

'Scan Limit
b3 = $0b 'register = Scan Limit (%00001011)
b2 = $01 'scan all digits 0-7 (%00000111)
gosub Write7219

' Intensity
b3 = $0a 'register = Intensity (%00001010)
b2 = $0f
' b2 = %00001110 'intensity = 29/32
' b2 = %00000100 'intensity = 9/32
' b2 = %00000101 'intensity = 11/32
' b2 = %00000111 'intensity = 15/32
gosub Write7219

'Shutdown
b3 = $0c 'register = Shutdown (%00001100)
b2 = $01 'normal operation (%00000001)
gosub Write7219

'------------

b3 = 1 'first digit
b2 = %10001100    'writes H
gosub Write7219


b3 = 2 'second digit
b2 = %10000001    'writes I
gosub Write7219

'------------

' Output a value to the MAX7219 7-segment LED controller.
' b3 contains the register (digit), b2 the data or display value.
'
Write7219:
low LOAD7219 'prepare clean latch transition
for b1 = 1 to 16 'latch the 16 bits in b3 and b2
low DIN7219 'default is current bit = 0
if b3 < 128 then W72A 'skip if default is correct
high DIN7219 'show current bit = 1

W72A:
pulsout CLK7219,50 'set the bit
w1 = w1 * 2 'next bit to test
next 'do all 16 bits
high LOAD7219 'latch this data into 7219 registers
return
 

Technical

Technical Support
Staff member
Add a
stop
command before the Write7219: sub routine.
You are 'falling into' the gosub by mistake at the end of your test program.
 

marcos.placona

Senior Member
Will try it as soon as leave the office Technical. But I'm 95% sure that that's the problem.

Will come back later to say if it worked or not.
 

westaust55

Moderator
Hi Marcos,

as much a question here about your code:

are you intending to turn on the decimal point for each digit/character?
see comment in portion of your code below:

Code:
b3 = 1 'first digit
b2 = %[B][COLOR="Red"]1[/COLOR][/B]0001100    'writes H
      [COLOR="red"][B]1 [/B][/COLOR]  1100
      [COLOR="red"][B]^[/B][/COLOR]   ----
      [B][COLOR="red"]|[/COLOR][/B]    this will output letter "H" as wanted
     [B][COLOR="red"] |[/COLOR][/B]
      [COLOR="red"][B]turn on decimal point[/B][/COLOR] see immediately below table 5 in datasheet

       000
       ---
       | - do not care = not used


gosub Write7219


b3 = 2 'second digit
b2 = %10000001    'writes I  [COLOR="red"][B]= actually the digit One [/B][/COLOR]but looking for "HI" ? or H[B][COLOR="red"].[/COLOR][/B]I[COLOR="red"][B].[/B][/COLOR] ?
gosub Write7219
 
Last edited:

marcos.placona

Senior Member
Hi westaust55, I know that, and in this case it was intentional. I just did it to test that everything was working properly.

I can just replace that one by a 0 and it'll remove the dots in front. I did that 'cause in previous version I was exactly working with the %10000000 to display the dot.

And in regards to displaying 1 instead of I, that's because in the "real version" I set up some symbols such as H, L, I etc, and instead of using binary or hex numbers I'll be using the numbers and the letters.

That makes it easier for me to read. :D

Thanks for the comments
 
Top