max 7219 display driver
jonw
Posts: 67
I am using the max 7219 to drive a 4 digit·counter (like scott edwards book)MAXDEMO. The multiplexed display driver program.
··· How·can·I·build a program to go with the max7219· to be a·hour/min/sec· display.·· It does not have to be accurate as a clock. and I would like to keep it as simple as possible as this is my·1st project.
Post Edited (jonw) : 10/8/2006 7:26:34 PM GMT
··· How·can·I·build a program to go with the max7219· to be a·hour/min/sec· display.·· It does not have to be accurate as a clock. and I would like to keep it as simple as possible as this is my·1st project.
Post Edited (jonw) : 10/8/2006 7:26:34 PM GMT
Comments
·
·· The MAX7219 isn’t going to do any of those things.· It is only going to display numbers.· You have to program your BASIC Stamp to do the other stuff and send that information to the MAX7219.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
1-Take out the leading zero blanking
2-Use SHIFTOUT once to send both address and digit
·
·· I found an old example I converted from my Digital Alarm Clock Code and made a simple count down timer.· Since the clock only showed hours and minutes, the minutes are shown as seconds in this one and the hours are minutes.· But it gives you the concept of a simple countdown timer using the MAX 7219.· The first four digits are used in this example.· I hope this helps.·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
·
·· The code was adapted from my old Digital Clock Project (which I still need to post).· I had someone ask me about a timer once so I just hacked out what I didn’t need to give a quick example.· So the variable you asked about isn’t used in this code.· If you look I believe it is used in the Binary Digital Clock project I referred you to.· Is there something specific you need to know?· The code is pretty straight forward.· There are only two subroutines, initialization and the main loop.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Lets look at the clock you want to build. Starting at it's simpleist form you would describe it in one word.
1. Clock
Going one step down from there you would break it apart and say for example
1. A timer circuit
2. A display
From there you can break apart the Timer function and the display function
Lets simplify one of the components, the display. Instead of a driver and multi digit display lets use two LED's to represent 1/10 of a second and one to represent one second. With these two LED's you can write your own code instead of using someone elses code that you don't understand.
So now we have a very simple circuit to build, 2 LED's and 2 Resistors connected to 2 Stamp Pins.
Set up a time loop to blink the 1/10 second LED first. Use a stop watch to measure 10 blinks per second. You now have a 1/10 timer working.
Add to the program another variable to count to 10. WHen that variable gets to 10 turn on the second led, reset the variable to 0 and continue counting, when it gets to 10 again, turn off the second LED.
Look up how to toggle a pin, otherwise your program would have to know to turn the LED on or off when it got to 10.
Another programming algorithm could let the second's variable go to 20 instead of 10. Turnning the led ON at 10 and off at 20 and then resetting the variable to 0. You may have a third method there are many ways to write code that give you the same output.
Work on the code for the interface to the MAX7219 as a separate program, once it is working you can plug it into your timer code as a subroutine. You will need a number to character subroutine to convert the internal numbers your program uses to the proper format to send to the display.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think outside the BOX!
·· I'm not sure I attached it sucessfully
··· so here it is
counter VAR Byte
For Counter = 0 to 9
Do
HIGH 0·············· 1/10· led is pin0·· and the one sec led is pin1
PAUSE 50
LOW 0
PAUSE 50
NEXT
Toggle 1
Out1=In1
Loop····
················ Jonw
You will see a bracket [noparse][[/noparse] with the word code inside and another bracket at the end of your code when you press the code button again you will se the same thing but it will also have a slash /code these two things will block your code into a window.
Here is what I have written to get the point across:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think outside the BOX!
' {$STAMP BS2}
' {$PBASIC 2.5}
·minutes VAR Byte
seconds· VAR Byte
tenths VAR Byte
Minutes = 0
Seconds=0
tenths=0
OUTPUT 13
OUTPUT 14
OUTPUT 15
MAINLOOP:
PAUSE 40
tenths = tenths+1
TOGGLE 15
·IF tenths< 11 THEN exit_tenths_test
·seconds =seconds+1
·TOGGLE 14
·tenths=0
·exit_tenths_test:
·IF seconds < 60 THEN exit_sec_test
·minutes =minutes+1
·TOGGLE 13
·seconds =0
·exit_sec_test:
·GOTO MAINLOOP
Curious why you chose pause 40
Ok now it's time to test drive your max7219
Write some new code dealing with just the serial communication between that chip and the basic stamp
Start by reading the datasheet and tell us what you come up with as far as connecting the wires, after that we can test it, and then work on the final sending of your seconds and minutes variables to display the time.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think outside the BOX!
··············· ·I came up with pause 40 because I reasoned that if 60 time units are wasted on the minute loop then that left·40 to be wasted on the pause loop. Is that ok? (I don't know what I'm going to do when I add hours).
········ The interesting thing I found is, when the tenths loop terminated at 10 counts, the scope shows a waveform on the 60 second LED of·25 seconds off and·25 seconds·on,·giving· 50 seconds to the minute,
··········· ·And at 11 counts the LED was 27.8 sec off·and 27.8 on (giving 55.6 sec/min)· So 11 counts was more accurate.·I think it is because of the program overhead, as talked about in the book "what's a microcontroller" by Andy Lindsay Page 94.· Is this the reason?
··· Now on the max· driver program· I will give you what I have.· I will study the Data sheet in more detail now, But my first impression is it will look like this.· I am not clear on the odd even bit 0 area of tricking it into thinking its talking to a 16 bit register.·· Also when you put a underscore in the program, what is that doing?
I rushed so you could see what I have so I can work over the weekend.· The wiring will be as the· drawing on page 134 of "Programming the basic stamp" by Scott E.· I will also post that.· I can draw in autocad,circuitmaker, or Electronics work bench (EWB)· which is the best format for posting?···· Thank so much·· appreciate you help· jonw
······ I also came to understand the fault in what I posted with 3 leds on 3 outputs.
Thats the whole idea of this project is to send the info down one wire.
·· I am unsure if the display can count up with just pulses or should i be just trying to light some segments up for now with decode off.···· johw···· I have come quite far in a short time· thanks for your help sir.
What I was trying to get across is your project is a complex system.
It incorporates programming to keep track of time, programming to talk to the external device, programming to convert data to send to the device, hardware connections etc. I like to break apart the complex system to simple components. Basically make little black boxes or function components that have input and outputs and then tie them together. If you are unsure of how to display characters using a serial driver chip it is easier to work with just that part of the system without the complexity of everything else going on. I say make a complete new program dealing with just the output of some static characters to the display.
Make the output to the display function a subroutine that has a set number of variables for input so once you write that subroutine it is easy to just plug it into any program project you have in the future.
As you work on displaying some static data if you have a problem with part of it you just can't figure out, post that specific question to get you over the hump. Looks like you have it well in hand finish it up now (that's my problem I tend to not finish things I start as I am only interested in it when I don't understand it, once I do I just start something else.)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think outside the BOX!
Here is what I have for code,·
··· 1.·· Its a counter.
····2.· Under the variables why do we assign BIT0· for odd,VAR, index.BIT0
··· 3.· I would like to practice communicating to the 7219. How do I send it say $0407
····· (with decode off), to·turn on segments E,F,G,· on the 4th digit.· Do I need the subroutine that organizes pairs for this·example?
···· 4. I do not understand the subroutine well, on return do we go to mainloop or dispval=...·········· Thanks Everyone··· jonw.
········
Post Edited (jonw) : 10/16/2006 9:55:13 PM GMT
2. DIG gets a digit from a 16-bit value...16 bit numbers can be up to 65535, and DIG returns digits from 0 through 4 as per the Help File/Manual.· As a number is represented within a variable you can grab a specific digit from that variable for display purposes.
3. No, arrays are specified by an index element within parenthesis after the variable name.· The period means that a modifier follows the variable.· In this case I am setting d7219 to whatever is in the lower nibble of the variable min.· I hope this helps.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
How many bits is this (that are shifted out per pulse out)? Its 8 correct, four for the nibble of time to be shown and 4 bits for index. ie I thought the MAX chip needed 16 at a time, or is that only for initialization?
I am not sure,I even understand what index =1 and down to index =4 is doing?
Also talking about index once we initialized the max 7219 then its done for the rest of the program correct?
( ie the loop does not need to go back to it) and so when we use the name index as a variable we are over writing the initialization index but because it only needs to be initializated once then its ok to use the same name index again. Is this right? Thanks a million chris
·
·· index is a byte variable, as is d7219.· Also note that unless you specify the number of bits to be shifted out, the SHIFTOUT instruction defaults to 8, making that 16 bits being shifted out.· Bear in mind it doesn’t matter if you’ve only assigned a bit or bit variable to index or d7219, they’re still 8 bits anyway.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
·· And the first byte is the address, followed by the data.· Are we doing that in this case?··Is the·index·then, the address for· that data.
·· (Or is that address/data· pairs only for initialization?)
·· · Thank you for your help.·· jonw
·
·· I would tend to think of it as Command/Register followed by the data.· The index variable is being used for more than one thing.· I tend to re-use variables so you don’t run out trying to define a unique variable for everything you do.· In the initialization code the index variable is merely a counter and its value is not being sent to the MAX7219.· In the other piece of code it is being set with the register we want and the variable d7219 is being set with the data or value we want for that register.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Now my question. In your simple timer code, How many alais's are there?
Only one I see is Index.
So what I do not understand is how can we use the modifier for Mins and Hrs when they are not declared as alais's. Am I missing something? thanks jonw
·
·· I’m not sure what you mean…mins and hrs are declared as variables.· They don’t need to be declared as an alias.· The modifiers are part of the PBASIC syntax to access various portions of a variable without requiring an alias to a part of the variable.· That could be done too I suppose but would only add to the complexity and make it more difficult to follow in my opinion.· In fact I originally did things that way by example when I first learned, then decided it is much clearer to work with the variable directly, without an alias.· It really isn’t that difficult if you break it down into the subroutines and what they do.· For the most part it’s just a bunch of subroutines being called in a certain order.· With the timer it’s a counter counting up/down and simply calling a routine to display the current results.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
http://forums.parallax.com/forums/default.aspx?f=5&m=94508&g=94637#m94637
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think outside the BOX!
·
·· No, if you had an alias in most cases you would no longer need the modifier, since the return value would already be what you wanted.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
········ I am getting ahead of myself now but should I proceed with this idea.
······· A word could only represent 4 digits,and I want to have 6 digits. (ie 12 hour clock with seconds).· Would·a (24)· bit array help?
························ Thanks· jonw
·
·· Originally you indicated a counter and perhaps I assumed incorrectly that you meant a decimal counter.· For time where you have hours, minutes and seconds you can use BCD and the data will fit into 3 bytes (2 digits per byte).· This is how the DS1302 deals with time and therefore how all of my clock projects work.· As for packing it into a single Word variable, you could if you didn’t need seconds or if your count didn’t exceed 18 hours.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
··········· I can see some light at the end of the tunnel.··I know I have much work yet·to do but I·can·see now·I can do it.··Extremely thankfull for your help. Now·my question.
············ I will post the code (for my 24 hour clock with seconds)·later. It is very similiar to your counter. But the problem is, it will not show the last (sixth) digit.
·· I think that is because I can not set the, For work = 0 to 86400· loop higher than 65535. Am I misunderstanding your reply to use BCD to be able to go higher than this?·
If I add a gosub to increase the time count I do not know what to say in it.
····· Also I need code to stop the count at 5 and 9.· Can· I say·If DIG 0·=9 then secs.LOWNIB = 0 and use this kind of statement· over and over.···And where do I place this type of statment?·
·I know its hard to know what I mean without the code posted. But just give me some general idea where to work next.
······ One· other question chris Can I refer to Secs.LOWNIB·· and· workDIG 0 as one and the same?·············· thanks· jonw
····
····
· ····
·
·· You are correct you cannot count that high in a single word variable since the limit is 16 bits or 65535.· However as I was saying if you use a byte value for hours, minutes and seconds you could do it.· An RTC would also make the timing more accurate and reduce code overhead.
·
·· As to you other question…Secs.LOWNIB would grab the lower 4 bits of the variable Secs.· However that’s not to say it will be a valid digit…What is Secs was at a value of 45?· Then grabbing the lower 4 bits would give you a value of 13, which wouldn’t be a valid digit.· That code was used for reading BCD values from the DS1302 RTC.· This is why I was referring to packing two decimal digits into a byte variable.
·
·· The work DIG 0 is going to grab the right-most digit of the variable work.· Unless you had assigned the contents of the Secs variable to it they wouldn’t be the same thing.· I guess I’m not clear on exactly what you’re trying to do and I wondering if maybe you’re over complicating things for yourself.
·
·· There may be a simple way to do what you want, but if you don’t understand the simple operations that make up the more complex stuff you certainly won’t get the complex stuff to work and you may be stuck trying to figure out why.· Or worse, you may post the code and we won’t be able to figure it out either because it won’t be clear what you’re trying to do.
·
·· You should have a clear definition of what you want to do and an idea of how to do it before you write any code.· Then, as advised earlier by someone, break it down into simpler routines and integrate them once they’re working on their own.· Do this one step at a time and you’ll have a lot less to debug and it will be easier since you know everything worked up to that point.· It becomes easy to identify the routine/code responsible.· I hope this helps.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I do not know what you mean to use 1 byte per 2 digits. Do you mean I can make 3 For ... next loops. one for seconds. ie for counter= 0 to 60 then another for minutes ie For counter = 0 to 60.
Could you give me a idea how to break up the project into Blocks. jonw