PDA

View Full Version : MAX7219 Helping Hand Please



isaac
- 19th October 2008, 11:07
Hi All

i am experimenting with MAX7219, seven segment decoder driver
using Les example program MAX_CNT.BAS in his book "EXPERIMENTING WITH THE PICBASIC PRO COMPILER"
the program does work a it suppose to counting to 9999 and decrements a 16-bit number
Question is i want to light up just the g on the four displays to indicate no data
does anyone know how i can do this

Regards
Isaac



' Program: MAX_CNT.BAS
' ************************************************** ***********
' * For use with EXPERIMENTING WITH THE PICBASIC PRO COMPILER *
' * *
' * This source code may be freely used within your own *
' * programs. However, if it is used for profitable reasons, *
' * please give credit where credit is due. *
' * And make a reference to myself or Rosetta Technologies *
' * *
' * Les. Johnson *
' ************************************************** ***********
'
' This Program demonstrates the use of the MAX7219, seven segment decoder driver
' It also incorporates placing of Decimal point.
' ************************************************** *********************

Include "Modedefs.bas"
Define LOADER_USED 1
' ** Set Xtal Value in mHz **

Define OSC 20 ' Set Xtal Frequency

' ** Declare Pins Used **
Clk Var PortB.0 ' Data is clocked on rising edge of this pin
Dta Var PortB.1 ' Bits are shifted out of this pin
Load Var PortB.2 ' Transfers data to LEDs when Pulsed

' ** Declare Constants **
Decode_Reg Con 9 ' Decode register, a 1 turns on BCD decoding for each digit.
Lum_Reg Con 10 ' Intensity register.
Scan_Reg Con 11 ' Scan-limit register.
Switch_Reg Con 12 ' On/Off Register.
Test_Reg Con 15 ' Test mode register (all digits on, 100% bright)

' Max_Digit Con 5 ' Amount of LED Displays being used.

' ** Declare Variables **
Counter Var Word ' Variable used for the Demo Counting routine
Max_Disp Var Word ' 16-bit value to be displayed by the MAX7219
Max_Dp Var Byte ' Digit number to place Decimal point (0-4)
Register Var Byte ' Pointer to the Internal Registers of the MAX7219
R_Val Var Byte ' Data placed in Each Register
Digit Var Byte ' Position of individual numbers within MAX_Disp (0-3)
Position Var Byte ' Position of each LED display (1-4)

' ** INITIALIZE THE MAX7219 **
' Each register address is sent along with its setting data.
' Because the MAX7219 expects to see a packet of 16 bits, then the LOAD pin is pulsed
' Set the scan limit to 3 (4 digits, numbered 0-3)
' Set the Brightness to 5
' BCD decoding to the lower 4 digits
' Switch the display on.
' Turn Off test mode

Register=Scan_Reg ' Point to the Scan Register
R_Val=3 ' send 3, (Four LED Displays 0-3)
Gosub Transfer ' Transfer this 16-bit Word to the MAX7219

Register=Lum_Reg ' Point to the Luminance Register
R_Val=0 ' Send 5, (Value for Brightness)
Gosub Transfer ' Transfer this 16-bit Word to the MAX7219

Register=Decode_Reg ' Point to BCD Decode Register
R_Val=%00011111 ' Decode the first 5 digits
Gosub Transfer ' Transfer this 16-bit Word to the MAX7219

Register=Switch_Reg ' Point to the Switch Register
R_Val=1 ' Set to One, (switches the display ON)
Gosub Transfer ' Transfer this 16-bit Word to the MAX7219

Register=Test_Reg ' Point to the Test Register
R_Val=0 ' Reset to Zero, (turns off Test mode)
Gosub Transfer ' Transfer this 16-bit Word to the MAX7219


' ***** MAIN PROGRAM *****
' This loop increments and then decrements a 16-bit number
' And displays it on Four LED Displays
' The value to be displayed is held in the variable "Max_Disp"
' The Position of the decimal point is held in Max_DP (0-4)

Max_Dp=5 ' Display number for Decimal Point

Again: For Counter=1 to 9999 ' Increment Counter
Max_Disp=Counter ' Load Max_Disp with Value of Counter
Gosub Display ' Display the Value of Counter
Pause 150 ' Delay, so we can see whats happening
Next ' Close the Loop

For Counter=9999 to 1 step -1 ' Decrement Counter
Max_Disp=Counter ' Load Max_Disp with Value of Counter
Gosub Display ' Display the Value of Counter
Pause 150 ' Delay, so we can see whats happening
Next ' Close the Loop
Goto Again ' Do it Indefinately


' ** Subroutines **
' Display the Value held in the Variable "MAX_DISP" on the four LED's
' The value held in "MAX_DP" places the decimal point on that LED (0-3)
' Sending the value 15 blanks the display, this allows Zero suppression
' By setting bit-7 of the value sent to the individual LED displays, the decimal point
' Is illuminated

Display:
Digit=0 ' Start at Digit 0 of Max_Disp Variable
For Position=4 to 1 step -1 ' Start at Farthest Right of Display
Register=Position ' Place Position into Register
R_Val=Max_Disp Dig Digit ' Extract the individual numbers from Max_Disp
If Max_Disp<10 and Position=3 then R_Val=15 ' Zero Suppression for the second digit
If Max_Disp<100 and Position=2 then R_Val=15 ' Zero Suppression for the Third digit
If Max_Disp<1000 and Position=1 then R_Val=15 ' Zero Suppression for the Forth digit
If Max_Disp<10000 and Position=0 then R_Val=15 ' Zero Suppression for the Fifth digit
If Digit=Max_Dp then R_Val.7=1 ' Place the decimal point, held in Max_DP
Gosub Transfer ' Transfer the 16-bit Word to the MAX7219
If Digit>=3 then Digit=0 ' We only need the first four digits
Digit=Digit+1 ' Point to next Digit within Max_Disp
Next Position ' Close the Loop
Return ' Exit from subroutine

' Send a 16-bit word to the MAX7219
Transfer:
Shiftout Dta,Clk,msbfirst,[Register,R_Val] ' Shift Out the Register first, then the data
High Load ' The data is now acted upon
@ Nop
@ Nop ' A small delay to ensure correct clocking times
Low Load ' Disable the MAX7219
Return ' Exit from Subroutine

Acetronics2
- 19th October 2008, 18:15
Hi,

From the datasheet ... Table 5.

did you try sending HEX Characters ??? CBDE i.e ???

Alain

isaac
- 23rd October 2008, 13:54
Hi,

From the datasheet ... Table 5.

did you try sending HEX Characters ??? CBDE i.e ???

Alain

i have tried that but still wont work

Isaac:p

Nicmus
- 23rd October 2008, 19:07
Hi Isaac,

You have two control ways for this device: decode B and no decode.
If you stay in decode mode (and I see you using the device in this mode) you can send character 10 and only segment g will be ON (see table 5 in the data sheet).
If you go in no decode mode you can individually control each segment.

Regards,

Nick

isaac
- 24th October 2008, 11:24
Hi Isaac,

You have two control ways for this device: decode B and no decode.
If you stay in decode mode (and I see you using the device in this mode) you can send character 10 and only segment g will be ON (see table 5 in the data sheet).
If you go in no decode mode you can individually control each segment.

Regards,

Nick

Big Thanks to you Nick
you were correct sending the character 10 and only segment g is ON it works
i used this loop below



Displayg:
Max_Dp=6 ' Display number for Decimal Point
Digit=0 ' Start at Digit 0 of Max_Disp Variable
For Position=6 to 1 step -1 ' Start at Farthest Right of Display
Register=Position ' Place Position into Register
R_Val=Max_Disp Dig Digit ' Extract the individual numbers from Max_Disp
R_Val=10 ' Display ------ only g is on
If Digit=Max_Dp then R_Val.7=1 ' Place the decimal point, held in Max_DP

Gosub Transfer ' Transfer the 16-bit Word to the MAX7219
If Digit>=5 then Digit=0 ' We only need the first 6 digits
Digit=Digit+1 ' Point to next Digit within Max_Disp
Next Position ' Close the Loop
Return


My next problem now is how to display 6 digits like 123456 i have being going round in circles all night as there is greater then a word variable can handle
any ideas would be well appreciated

Regards
Isaac

Jerson
- 24th October 2008, 12:08
Isaac

If you can split the number and have it in RAM as an array, all you need to do is write this out to the 7219 to be displayed. So, I would hazard a guess that your question is more about how to split a number to be displayed. Could you be more specific about your question?

Jerson

skimask
- 24th October 2008, 14:14
My next problem now is how to display 6 digits like 123456 i have being going round in circles all night as there is greater then a word variable can handle
any ideas would be well appreciated
You learned how to do this when you were 5 (give or take), you just don't know it...

You count to ten on your fingers, but you want to keep counting, so what do you do?
You get your brother to HOLD the PLACE of the overflow from your fingers, so every time you go over 10, you reset to ZERO, and he adds another finger, and you keep counting.
Well, now your brother is out of fingers, so what do you do?
You get your sister to count the overflows from your brother.

You overflow, reset, add one to your brother...keep counting...
Your brother overflows, resets, and adds one to your sister...keep counting...
And so on and so on and so on...
So, you are counting ones...
Your brother is counting tens...
Your sister is counting hundreds...

Now, replace the words YOU, BROTHER, and SISTER, with some other digit placeholder that's compatible with PBP... Now what in PBP could possibly hold the value of a digit (or digits) of some sort?

Charles Linquis
- 24th October 2008, 14:40
Or you could use PBPL. Longs could easily handle your 6 digits.

T.Jackson
- 24th October 2008, 15:26
You learned how to do this when you were 5 (give or take), you just don't know it...

You count to ten on your fingers, but you want to keep counting, so what do you do?
You get your brother to HOLD the PLACE of the overflow from your fingers, so every time you go over 10, you reset to ZERO, and he adds another finger, and you keep counting.
Well, now your brother is out of fingers, so what do you do?
You get your sister to count the overflows from your brother.

You overflow, reset, add one to your brother...keep counting...
Your brother overflows, resets, and adds one to your sister...keep counting...
And so on and so on and so on...
So, you are counting ones...
Your brother is counting tens...
Your sister is counting hundreds...

Now, replace the words YOU, BROTHER, and SISTER, with some other digit placeholder that's compatible with PBP... Now what in PBP could possibly hold the value of a digit (or digits) of some sort?

I feel that to be an absolutely excellent abstract explanation Jeremy.

Well done :)

RussMartin
- 25th October 2008, 02:56
You learned how to do this when you were 5 (give or take), you just don't know it...

You count to ten on your fingers, but you want to keep counting, so what do you do?
You get your brother to HOLD the PLACE of the overflow from your fingers, so every time you go over 10, you reset to ZERO, and he adds another finger, and you keep counting.
Well, now your brother is out of fingers, so what do you do?
You get your sister to count the overflows from your brother.

You overflow, reset, add one to your brother...keep counting...
Your brother overflows, resets, and adds one to your sister...keep counting...
And so on and so on and so on...
So, you are counting ones...
Your brother is counting tens...
Your sister is counting hundreds...

Now, replace the words YOU, BROTHER, and SISTER, with some other digit placeholder that's compatible with PBP... Now what in PBP could possibly hold the value of a digit (or digits) of some sort?

IMNSHO:

On the "silly" scale, this rates:

-|--------^-|+ :D

On the "helpful" scale, it rates:

-|^---------|+ :(

I'm glad I didn't learn this way when I was 5, back in 1955, with no sisters and only a brother . . .

. . . and I'm pretty sure isaac, as any one of the rest of us, understands counting in base 10 without a condescending "finger-counting" illustration.

skimask
- 25th October 2008, 04:01
. . . and I'm pretty sure isaac, as any one of the rest of us, understands counting in base 10 without a condescending "finger-counting" illustration.
Maybe so, maybe not...BUT....
For somebody that can't grasp the concept of splitting up numbers into smaller chunks, they might need to be reminded of the basics. And it's obvious to me that, while you might know how to make larger numbers out of a bunch of smaller numbers, didn't get what I was getting at the most basic level.
While some people might think that they can 'think' in base2/base8/base10 and base16 all at the same time, just because they can 'program a PIC', can they really?
'cause that's exactly what the O/P wanted to know...how to keep track (i.e. count, manipulate, etc.) numbers to large to fit in a byte/word (i.e. hand). Think about it. At the most basic level, all we can do is mess with a byte. How does PBP multiply 32bit numbers? It breaks them down to the byte level and plays with them as needed.
Way back in the day, before I had PBP and used to do nothing but assembly work (before I knew what I was doing really) on the PIC and needed to count large numbers to display on an LCD, I'd break the bytes up into BCD, and work with them that way. I could deal with virtually any size number that way, limited only by the amount of ram on the PIC.
So, condescending finger counting example?
Maybe...
If a person takes that example in the negative fashion, then just maybe that person hasn't learned as much as they thought they have.
Another quicky example of what I'm getting at... My wife can (and does) drive a relatively fast car. But she can't do a tune-up, rebuild the engine, or drive in the Indy 500.

In the end though, I think it would just be a lot easier for Isaac to figure out why his system isn't playing well with PBPL and LONG's.

RussMartin
- 25th October 2008, 06:49
Way back in the day, before I had PBP and used to do nothing but assembly work (before I knew what I was doing really) on the PIC and needed to count large numbers to display on an LCD, I'd break the bytes up into BCD, and work with them that way. I could deal with virtually any size number that way, limited only by the amount of ram on the PIC.

That's pretty much the same way I had to do it "way back in the day" . . . in 1969 on an IBM 1130 with a 2310 disk drive using a 2315 "pizza box" removable disk about 14 inches in diameter. Sadly, the LCD had yet to be invented, so the output was to an 1132 chain printer.


. . . it's obvious to me that, while you might know how to make larger numbers out of a bunch of smaller numbers, didn't get what I was getting at the most basic . . .

An exercise in making larger numbers out of much smaller numbers was in June and July, 1967, when I was calculating the values, determining the periods ("rings"), and counting the digit distributions in repeating decimal fractions of the form 1/(10x-1) on a Philco 2000. For x=1, 1/9 is easy, 0.1111 . . . But for x=2, 1/19, the fraction is 0.052631578947368421 before it repeats, beginning again with "0526 . . . " (18-digit period or "ring") and going on, forever repeating. For x=3, 1/29, the procedure is the same, and so on. The objective was to create an algorithm for generating random numbers.

The actual math is all whole numbers, no fractions, and . . . well, I'll let skimask explain how to do it. :)


If a person takes that example in the negative fashion, then just maybe that person hasn't learned as much as they thought they have.

I have in fact learned as much as I think I have . . . but I haven't learned nearly as much as I want to know!

skimask
- 25th October 2008, 07:07
That's pretty much the same way I had to do it "way back in the day" . . . in 1969 on an IBM 1130 with a 2310 disk drive using a 2315 "pizza box" removable disk about 14 inches in diameter. Sadly, the LCD had yet to be invented, so the output was to an 1132 chain printer.
OUCH! Ok, I never had to go thru that (a few years ahead of my time), but I can about imagine. My very very first MCU/CPU type project back in '80, was a Z80 (+1K ram, handful of LEDs, a few HEX switches and pushbuttons, and debouncing for the 'program' switches), programming the code into the RAM with the switches to blink a single LED. Took me 6 hours to program it, a simple loop with a delay, and it actually worked the first time. Got damn lucky. Gave up after that 'cause the school got Apple II+'s.
You didn't even have a 'nixie tube' (sp?) for display or what? :)


An exercise in making larger numbers out of much smaller numbers....
My OBD project has me going out to 15 decimals, not because I have, but because I can. Absolutely no need for it except for error stack up over time.
On a side note, that paragraph just gave me a bit of an idea to help me better randomize more numbers in another project I've got going.


I have in fact learned as much as I think I have . . . but I haven't learned nearly as much as I want to know!
Ok, fair enough... The point being, from this end, was basically, the same as it always is (or at least it always seems to be when somebody has a problem)
Break it (whatever IT is) down, wayyyy down, and build it back up.

RussMartin
- 25th October 2008, 08:02
skimask, sometimes we seem to hijack threads even when we don't intend to.

So how about taking our discussions, disputations, sparring, polysyllabic profundity, rodomontade, thrasonical bombast, and occasional psittaceous vacuity (or even simple one-upsmanship) to "Off Topic"?

Our new thread there should be S&M . . . for skimask and Martin, of course! (Let others read into it what they will . . . )

That way, we can both avoid the embarrassment of contributing to "thread bloat" that doesn't help the original poster, or, as bad or worse, leading the thread into the "Confusion Zone" that Darrel mentioned elsewhere.

I'm willing if you are . . .

Meanwhile, let's both be truly helpful.

skimask
- 25th October 2008, 14:04
skimask, sometimes we seem to hijack threads even when we don't intend to.
So how about taking our discussions, disputations, sparring, polysyllabic profundity, rodomontade, thrasonical bombast, and occasional psittaceous vacuity (or even simple one-upsmanship) to "Off Topic"?
Our new thread there should be S&M . . . for skimask and Martin, of course! (Let others read into it what they will . . . )
That way, we can both avoid the embarrassment of contributing to "thread bloat" that doesn't help the original poster, or, as bad or worse, leading the thread into the "Confusion Zone" that Darrel mentioned elsewhere.
I'm willing if you are . . .
Meanwhile, let's both be truly helpful.
Of course...what a great idea...
http://www.picbasic.co.uk/forum/showthread.php?t=6379

isaac
- 27th October 2008, 18:07
Hi Guys
Please no puching in my name
You guys are all helping to us whom want to learn
the actual problem was not actually how to split the number up but have to write the write it to the Max7219

No Fighting
Isaac

CuriousOne
- 18th July 2013, 12:54
I'm facing almost same problem, but a bit different, I'm also using the same code, but I'd like to:

1. Light two decimal points at same time, while maintaining decode mode on?
2. Enable free mode, when I can light up arbitrary segments, but only for part of display? say I have 4 digit 7 segment display, I want two leftmost chars to display "AC" and remaining two chars to work in decode mode?

CuriousOne
- 24th November 2013, 12:59
Almost half an year passed..... :)

Acetronics2
- 24th November 2013, 14:49
Sooooo ...

have a merry Christmas,
wish you a happy new year,
and
might easter bring you lots of chocolates ...

:rolleyes:

Alain

CuriousOne
- 10th February 2014, 14:49
And problem still with DP :)

Eboggs
- 12th February 2014, 05:05
You still need help?

CuriousOne
- 14th February 2014, 04:49
Actually, I've learned how to modify the code do display more than one decimal point. But I have no idea how to modify code to enable no decode mode and send a pattern to illuminate specific leds.

CuriousOne
- 14th February 2014, 15:07
How to modify this program to display 5 or 6 or 7 digits?

changing the:



Register=Decode_Reg ' Point to BCD Decode Register
R_Val=%00111111 ' Decode the first 6 digits
Gosub Transfer ' Transfer this 16-bit Word to the MAX7219

and

For Position=5 to 1 step -1 ' Start at Farthest Right of Display

and

If Digit>=5 then Digit=0 ' We only need the first four digits



changes nothing, only 4 digits are lit.