Maxc7219 & Hex

marcos.placona

Senior Member
Hi guys,

I've been digging into this forum for all the possible information I can get about the usage of MAX7219.

So far I've got it well wired with my picaxe 18x and a 7segment display CC.

The code I'm trying to use looks like this one:

Code:
  symbol DIN  = 0
  symbol LOAD = 2
  symbol CLK  = 7

  low DIN
  low LOAD
  low CLK

  [B]b1=$09  'decode mode
  b0=$ff  '=yes, all digits=BCD [/B]
  gosub shiftout
  [B]b1=$0a  'intensity
  b0=$0f  '=max[/B]
  gosub shiftout
  [COLOR=Red][B][COLOR=Black]b1=$0b  'scan limit[/COLOR]
  b0=$03  '=4 digits[/B][/COLOR]
  gosub shiftout
  [B]b1=$0c  'shutdown mode
  b0=$01  '=normal[/B]
  gosub shiftout:
  [B]b1=$0f  'display test
  b0=$01  '=all on[/B]
  gosub shiftout
  [B]b1=$0f  'display test
  b0=$00  '=normal[/B]
  gosub shiftout
  [B]b1=1:b0=5  'digit 1 shows "5"[/B]
  gosub shiftout

[COLOR=Silver]  b1=2:b0=0  'digit 2 shows "0"
  gosub shiftout

  b4=76 'number to be displayed 

  b1=3:b0=b4/10   'digit 3 shows "7"
  gosub shiftout

  b1=4:b0=b4//10  'digit 4 shows "6"
  gosub shiftout[/COLOR]

  stop

shiftout:
  for b5=1 to 16
  w6=w0 & $8000
  low DIN
  if w6=0 then bit_is_low
  high DIN  
bit_is_low:
  pulsout CLK,5
  w0=w0*2  '<< (shift bits left) 
  next b5
  pulsout LOAD,5
  return
I know it's been discussed a lot here, specially by MartinM57, who seems to be the MAX7219 master.

The parts I highlighted in bold, are the parts I didn't really understand, even after reading a re-reading the datasheet many times. I know it's using hex, and I also wanted to take this opportunity to ask you guys about which sort of table do you use to know exactly what hex code to use (can you send me a link please?), as well as how to get their values.

There's a part which is highlighted in red, and I'm sure the problem is there, it says:
b0=$03 '=4 digits I wanna know why $03 is equal four digits.

Also, the part in light grey, is the part I removed from the code, as I'm still testing it with just one 7 segment display (will multiplex later).

So, I believe that considering $03 is equal 4 digits, I should use $00 to say that I'll just be using one digit.

I've tried that, but it didn't work, and also tried with $01.

Also, on the display part I have:

b1=1:b0=5 'digit 1 shows "5" So I wanted to display the number five on the first seven segment. On max 7219, you have the digits starting from 0



So I believe that the b1 = 1 corresponds to digit 0, if you consider that it's like an array that has it's first index starting from 0 (my guess).

As it didn't work, I changed the wiring to go to DIG 1 on the max7219, but also no luck.

Every time I program my picaxe with this code, I get a different result. Sometimes it the 7 segment lits itself up as a whole, sometimes I get just parts of it, sometimes nothing and so on.

I'm sure it has something to do with the code, but I still couldn't spot what's wrong.

I can send pictures of the breadboard in case you wanna see it, but I've checked it about 100 times to see if there was nothing wrong.

Any sort of help you can give me would be much appreciated.

Thanks for reading this massive post,
 

westaust55

Moderator
Marcos,
I hope that you have downloaded and read the data sheet.

Below is a portion of the program including the part when you indicated you did not understand.
I have tried to notate withint the code so it is easy to understand.

Code:
  symbol DIN  = 0
  symbol LOAD = 2
  symbol CLK  = 7

  low DIN
  low LOAD
  low CLK

  b1=$09  'decode mode
  b0=$ff  '=yes, all digits=BCD 

w0 = b1, b0
w0 = $09FF = 2556
w0 = %0000 1001 1111 1111

           1001 = decode mode 
             ==>1111 1111 = decode all 8 digits

  gosub shiftout
  b1=$0a  'intensity
  b0=$0f  '=max

w0 = $0A0F = 2575
w0 = %0000 1010 0000 1111

           1010 = intensity

  gosub shiftout
  [B][COLOR="Red"]b1=$0b  'scan limit
  b0=$03  '=4 digits

w0 = $0B03 = 2819
w0 = %0000 [COLOR="Green"]1011[/COLOR]    [COLOR="magenta"]0000  0011[/COLOR]
     not.. addr    8 LED seg&#8217;s 
     used. Decod   dp + G to A  

           [COLOR="green"]1011[/COLOR] = scan limit 
                ==>[COLOR="Magenta"]0000 0011 [/COLOR]= display digits 0,1,2,3 = 4 digits
                               [B]See datasheet table 8[/B] [/COLOR][/B]
  gosub shiftout
 
Last edited:

westaust55

Moderator
and here is more of your code with embedded notations and reference to the relevant datsheet tables . . .

Code:
gosub shiftout
  b1=$0c  'shutdown mode
  b0=$01  '=normal

w0 = $0C01 = =%0000 1100 0000 0001
                    1100 = shutdown mode (Refer datasheet table 2)
                   ==>   0000 0001 = Normal operation (see table 3)   

  gosub shiftout:
  b1=$0f  'display test
  b0=$01  '=all on

w0 = $0F01 = %0000 1111 0000 0001
                   1111 = Display Test mode
                   ==>  0000 0001 = Display test mode ON
                   Refer datasheet table 10
  gosub shiftout
  b1=$0f  'display test
  b0=$00  '=normal

W0 = $0F00 = %0000 1111 0000 0000
                   1111 = Display Test mode
                   ==>  00000001 = Display test mode OFF/Normal
                   Refer datasheet table 10
  gosub shiftout
  b1=1:b0=5  'digit 1 shows "5"

w0 = $0105 = %0000 0001 0000 0101
                   0001 = Setup for Digit 0 (see datasheet table 2)
                   ==>  0000 0101 for decode mode (see table 5)
                       This displays the number &#8220;5&#8221; at digit 0
                       Note that digit 0 is the 1st digit 


  gosub shiftout
 

marcos.placona

Senior Member
Thanks for the excellent explanation, and I did indeed read the datasheet more than one time, but wasn't really understanding everything, and I think that there's no point in getting something to work (not really the case now), if you don't understand what you're doing.

So, according to your explanation, I'm not really far from getting it to work, as most of the code remains the same, except for the fact that I'm just using one display, so b0=$03 '=4 digits really needs to become b0=$00.

This way I should get it to display properly right? Well, I've tried changing this, but still, I get the same results (some flickers, and some parts lit), but never get a 5 :)

The examples you showed me, really got me into it, and now I understand it much better, and will probably find the solution for it sooner or later.

Thanks,

Marcos Placona
 

MartinM57

Moderator
Hi Marcos

It may be worth trying the code I put at http://www.picaxeforum.co.uk/showthread.php?t=4714 .. but you'll have to change the pin numbers for load, din and clk and the pin7 number in send_data_7219 to correspond to your wiring.

It's got a different "shiftout" code but its very high speed and definitely works..famous last words!

It should give you a rock solid number 8 on the display.

You can then send 01 05 to get the number 5 on digit 0 - the one you indicate you have wired up....

Yes, sending 0b 00 sets the scan limit to digit 0 only (i.e. just one digit) - see table 8 of the data sheet. But also see the part below the table that says "If the scan-limit register is set for three digits or less, individual digit drivers will dissipate excessive amounts of power. Consequently, the value of the RSET resistor must be adjusted according...". So I'd keep it simple and send 0b 03 for four digits and it's just that you've only wired up digit 0. It will (should) still work fine.

'7 segment multiplexing
symbol load_7219 = 6
symbol din_7219 = 7
symbol clk_7219 = 5

'max7219 registers
symbol decode_mode = $09
symbol intensity = $0A
symbol scan_limit = $0B
symbol shutdown = $0C
symbol digit_test = $0F

start:

'initialize 7219
gosub initialize_7219

'turn on test mode
b0 = digit_test
b1 = $01
gosub send_data_7219

Main:
goto main
end

initialize_7219:

b0 = decode_mode
b1 = $FF ' code b decode all digits
gosub send_data_7219

b0 = intensity
b1 = $0F
gosub send_data_7219

b0 = scan_limit
b1 = $03
gosub send_data_7219

b0 = shutdown
b1 = $01
gosub send_data_7219

return

send_data_7219:

'send the data
low LOAD_7219
pin7 = bit7
pulsout clk_7219, 1

pin7 = bit6
pulsout clk_7219, 1

pin7 = bit5
pulsout clk_7219, 1

pin7 = bit4
pulsout clk_7219, 1

pin7 = bit3
pulsout clk_7219, 1

pin7 = bit2
pulsout clk_7219, 1

pin7 = bit1
pulsout clk_7219, 1

pin7 = bit0
pulsout clk_7219, 1

pin7 = bit15
pulsout clk_7219, 1

pin7 = bit14
pulsout clk_7219, 1

pin7 = bit13
pulsout clk_7219, 1

pin7 = bit12
pulsout clk_7219, 1

pin7 = bit11
pulsout clk_7219, 1

pin7 = bit10
pulsout clk_7219, 1

pin7 = bit9
pulsout clk_7219, 1

pin7 = bit8
pulsout clk_7219, 1
high load_7219
return
 

westaust55

Moderator
Martin57,

Can I suggest that when publishing program code you use the code markers [ code] and [/ code] – just omit the spaces.



All this is covered in the sticky README post at the top of the Active PICAXE Forum and applies to all new members

Then you get a display like this which fits in a scrolling window:
Code:
Let b0 = b1 + b2
:D
 

MartinM57

Moderator
Yeh - and I really hate it when someone posts decent length code extracts in the silly little scrolly window that means I can only see a teeny bit of it at a time, and have to highlight it, Ctrl-C it and paste it into my favourite text editor to see the whole picture ...

...and applies to all new members
hmmm..387 posts vs 335 posts - I win :)

:D
 

BeanieBots

Moderator
Yeh - and I really hate it when someone posts decent length code extracts in the silly little scrolly window that means I can only see a teeny bit of it at a time, and have to highlight it, Ctrl-C it and paste it into my favourite text editor to see the whole picture ...


hmmm..387 posts vs 335 posts - I win :)

:D
I agree that the "silly scrolly window" is a bit small and frustrating, but it does save having to scroll through all the code to get to the text/question and it does preserve the indent structure. Please use it unless the code is just a few lines.

hmmm.. 387 posts vs 3462 - ....
 

westaust55

Moderator
I agree that the "silly scrolly window" is a bit small and frustrating, but it does save having to scroll through all the code to get to the text/question and it does preserve the indent structure. Please use it unless the code is just a few lines.
I do not disagree either that the window is a bit small. I fact I often write in Word then cut and paste into the small window. It helps me avoid some of the accidental typos caused by the Fiendishly Flailing Fingers :).

To me, it takes as much effort scrolling up and down irrespective when the code is long. But is becomes a nuisance trolling past lengthy code listings when quickly scolling down through many posts to get to the one at the bottom of the page


Strange that the window for a quote is almost full screen width,
whereas the window for code is much narrower leading to need to scroll sideways as well.

Maybe something the forum Administrator can look at.
Make the code window the same width as the quote window and maybe just a bit deeper than presently the case.
 

Dippy

Moderator
"I would never compare myself with those who have more time than I do....mainly as I so badly mis-manage my time so that I can't be like you "

- well I'm sure all that made perfect sense to Martin.

Actually, it would really nice if the SLSWs (which I prefer instead wading past lines of code*) preserved thecolour too - but that's asking a bit much.

* Remember, sometimes, when people ask about a little bit of their code which is giving concern they post the whole thing. Scrolling more than 30 lines has a hypnotic effect on me and sends me into Sleep Mode. I appreciate there can be linked issues elsewhere within the code, so I'll say that to pre-empt a predictable S/A reply.
 

MartinM57

Moderator
See what I mean? I don't even have time to create sensible posts....

..what I was getting at is that I can't manage my time so that I have am able to make 3000-odd posts on the forum ... not that I'm clever enough to be able to answer that broad a range of topics anyway.

Oh I give up - it's Friday, I'm still at work, but going home right now....have a good weekend....
 
Top