Shop OBEX P1 Docs P2 Docs Learn Events
max 7219 display driver — Parallax Forums

max 7219 display driver

jonwjonw Posts: 67
edited 2006-11-12 05:21 in BASIC Stamp
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
«13

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-10-06 05:01
    jonw,
    ·
    ·· 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
  • Mohamed RefkyMohamed Refky Posts: 47
    edited 2006-10-06 12:55
    To run code faster:
    1-Take out the leading zero blanking
    2-Use SHIFTOUT once to send both address and digit
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-10-08 20:41
    Hello,
    ·
    ·· 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
  • jonwjonw Posts: 67
    edited 2006-10-09 19:12
    Can any one give me a helping hand. See the Attachment Simple Timer in the previous post by chris. I am new to programing Stamp. Can any one explain in words how the Program and subroutines work. Also I don't understand the variable old Secs. Thanks Jonw
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-10-09 22:04
    jonw,
    ·
    ·· 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
  • metron9metron9 Posts: 1,100
    edited 2006-10-10 14:40
    Hi JonW, Perhaps for a first project instead of going with a full display using the max7219 and multi digit output you should simplify the project. When you are having a problem with any hardware or software you should simplify the components and the code, build from a small working example to a larger more complex system but keep the simple component structures in place. You build block by block.

    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!
  • jonwjonw Posts: 67
    edited 2006-10-12 00:31
    Yes Here it· Keep up the good work Thanks··
    ·· 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
  • metron9metron9 Posts: 1,100
    edited 2006-10-12 03:32
    Use the post reply button and then Just use the code button above then paste your code and then hit the code button again.

    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:



    ' {$STAMP BS2}
    ' {$PORT COM2}
    
    'Variables
    
    seconds VAR Byte
    tenths  VAR Byte
    
    'Pin 14 =  1sec LED
    'Pin 15 =  1/10 sec LED
    
    'Initialize Variables
    
    seconds=0
    tenths=0
    
    'Initialize ports
    
    OUTPUT 14  'make the BS pin 14 an output pin
    OUTPUT 15  'make the BS pin 15 an output pin
    
    mainloop:
    PAUSE 100       ' pause for 100 mS 1/10 of a second
    tenths=tenths+1 'increment the tenths variable
    TOGGLE 15       'toggle the LED on or off
    
    ' Test TO see IF tenths has incremented 10 times
    IF tenths<10 THEN exit_tenths_test
     seconds=seconds+1
     TOGGLE 14
     tenths=0  'reset the tenths variable to zero to start over
    exit_tenths_test:
    
    'We dont really need seconds above
    ' but I have provided it so you can add additional code
    ' to keep track of minutes
    
    'If we had a third led we could count minutes
    ' create a variable for minutes
    ' use pin 13 and another led and toggle it each minute
    
    GOTO mainloop
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think outside the BOX!
  • jonwjonw Posts: 67
    edited 2006-10-12 19:44
    This is what I have created, I know I need more comments.· Jonw
    (replace this text with your code)
    

    ' {$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
  • metron9metron9 Posts: 1,100
    edited 2006-10-12 20:45
    Ahh Jonw you did not catch my mistake, the if then logic should be if tenths < 10 not 11, my mistake I corrected it above.

    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!
  • jonwjonw Posts: 67
    edited 2006-10-13 20:16
    Metron9

    ··············· ·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
  • jonwjonw Posts: 67
    edited 2006-10-14 04:07
    Is This close?· A dwg is coming·· jonw
         ' {$STAMP BS2}
         ' {$PBASIC 2.5}
    '----------{I/O Definitions}---------
    DataIO     PIN 2    'MAX7219.1
    Clock      PIN 1    'MAX7219.13
    Load_n      PIN 0    'MAX7219.12
     'pin 13 1 min led
     'pin 14 1 sec led
     'pin 15 1/10  led
    '-------------{Constants}------------
    Decode     CON   $09         ' BCD Decode Register
    Brite      CON   $0A         ' Intensity Register
    Scan       CON   $0B         ' Scan Limit Register
    ShutDn     CON   $0C         ' Shutdown Register
    Test       CON   $0F         ' Display Test Mode
    DecPnt     CON   %10000000   ' Decimal Point
    Blank      CON   %1111       ' Blank A Digit
    '---------------{ Variables }--------------
    index               VAR    Byte
    maxdata             VAR    Byte
    odd                 VAR  index.BIT0 'not sure what this is?
    minutes             VAR    Byte
    Seconds             VAR    Byte
    Tenths              VAR    Byte
    '-----------------{ Initialization }--------------
    Init:
       FOR index = 0 TO 7
       LOOKUP index, [noparse][[/noparse] Scan,5, Brite, 9, Decode, $FF, ShutDn, 1],  maxdata
       SHIFTOUT DataIO, Clock, MSBFIRST, [noparse][[/noparse]maxdata]
       IF odd=0 THEN NoLoad
       PULSOUT Load_n,5
       NOLoad:
       NEXT
    ' ------------{Main program}-----------------
     ' initialize variables
     minutes=0
     seconds=0
     tenths=0
     OUTPUT 13
     OUTPUT 14
     OUTPUT 15
     mainloop:
     PAUSE 40
     tenths=tenths+1
     TOGGLE 15
     IF tenths<10 THEN exit_tenths_test
     seconds=seconds+1
     TOGGLE 14
     tenths=0
     exit_tenths_test:
     IF seconds<60THEN exit_sec_test
     minutes=minutes+1
     TOGGLE 13
     seconds=0
     exit_sec_test:
     GOTO mainloop
    
    (replace this text with your code)
    
  • jonwjonw Posts: 67
    edited 2006-10-14 19:50
    ·Metron9· I revised the initialization part after understanding it better.
    ······ 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.
    (' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '--------I/O Definitions------
    DATA_n    CON 2   'max7219.1
    CLK_n     CON 1   'max7219.13
    LOAD_n    CON 0   'max7219.12
    
    '------------Constants-----------
    Decode   CON   $09
    Brite    CON   $0A
    Scan     CON   $0B
    Shutdn   CON   $0C
    Test     CON   $0F
    DecPnt   CON   %10000000
    Blank    CON   %1111
    '----------Variables---------
    index     VAR   Byte
    maxdata   VAR   Byte
    odd       VAR   index.BIT0
    minutes   VAR   Byte
    seconds   VAR   Byte
    tenths    VAR   Byte
    '---------initialization--------
    Init:
    FOR index = 0 TO 7
    LOOKUP index,[noparse][[/noparse]Scan,5,Brite,9,Decode,$00,Shutdn,1],maxdata
    SHIFTOUT DATA_n,CLK_n,MSBFIRST,[noparse][[/noparse]maxdata]
    IF odd=0  THEN noload
    PULSOUT LOAD_n,5
    noload:
    NEXT
    '-----------main program---------
    'initialize variables
    Minutes = 0
    Seconds=0
    tenths=0
    
    MAINLOOP:
    PAUSE 40
    tenths = tenths+1
    'WAS TOGGLE 15 display digit o tenths
     IF tenths< 10 THEN exit_tenths_test
     seconds =seconds+1
     'WAS TOGGLE 14  needs to display digit 1  seconds
     tenths=0
     exit_tenths_test:
     IF seconds < 60 THEN exit_sec_test
     minutes =minutes+1
     ' WAS TOGGLE 13   needs to display dig 2 min
     seconds =0
     exit_sec_test:
    
     GOTO MAINLOOP)
    
  • metron9metron9 Posts: 1,100
    edited 2006-10-15 02:17
    "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"

    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!
  • jonwjonw Posts: 67
    edited 2006-10-15 02:47
    · Thanks to metron9·For the help.·· Can any one further ·my understanding of the code for the max 7219?
    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.
    (' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '--------I/O Definitions------
    DATA_n    CON 2   'max7219.1
    CLK       CON 1   'max7219.13
    LOAD_n    CON 0   'max7219.12
    
    '------------Constants-----------
    Decode   CON   $09
    Brite    CON   $0A
    Scan     CON   $0B
    Shutdn   CON   $0C
    Test     CON   $0F
    DecPnt   CON   %10000000
    Blank    CON   %1111
    '----------Variables---------
    index     VAR   Byte
    maxdata   VAR   Word
    odd       VAR   index.BIT0
    temp      VAR   Nib
    nonZ      VAR   Bit
    dispval   VAR   Word
     dpoint   VAR   Nib
     zblank   VAR   Bit
    '---------initialization--------
    Init:
    FOR index = 0 TO 7
    LOOKUP index,[noparse][[/noparse]Scan,5,Brite,9,Decode,$FF,Shutdn,1],maxdata
    SHIFTOUT DATA_n,CLK,MSBFIRST,[noparse][[/noparse]maxdata]
    IF odd=0  THEN noload
    PULSOUT LOAD_n,5
    noload:
    NEXT
    '-----------main program---------
    MAINLOOP:
     GOSUB MaxDisplay
     dispval=dispval+1
     GOTO MAINLOOP
     '------------Subroutines----------
     Maxdisplay:
     
     FOR index = 4 TO 1
       SHIFTOUT data_n,CLK,MSBFIRST,[noparse][[/noparse]index]
       temp=dispval DIG(index-1)
       
       SHIFTOUT Data_n,CLK,MSBFIRST,[noparse][[/noparse]temp]
       PULSOUT Load_n,5
       NEXT
       RETURN)
    

    ········

    Post Edited (jonw) : 10/16/2006 9:55:13 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-10-17 19:36
    jonw said...
    Chris :·
    ············· ·I am building a clock with the max 7219·I· know the Max7219 protocol, much better now.
    ·········· Can you help on a few points?
    ·········· In your Attachment· called Simple Timer, in the basic stamp forum: Topic Max 7219 Display Driver: started by myself, jonw· I do not understand,

    ············· 1.· under variables...· idxodd·· VAR· index BIT0······ why· bit0
    ····· I think its defining a 1 bit array· that is used for two things, one is to initialize the max,two, for the subroutine. If this is correct could you shed some light on it. thanks

    ············· 2.· I do not understand the command DIG· Your parallax basic stamp syntax and reference manual Ver 2.2· pg 117· says· To return the decimal digit of a 16 bit value.
    ······· Digits are numbered from· 0 to 4· right to left···This part I can't understand. Can you explain.

    ············· 3.· And last, under subroutines.
    ·················· ·ie· d7219 = min.LOWNIB···
    ·Does the period here mean its a array?···And also· upper case·LOWNIB is it· then part of the array?···· And I guess I have to ask.· NIB·· are we organizing the data into nibbles?···
    ·················· Thanks chris···············jonw
    1. That is actually code I borrowed from the original Stamp Works Manual to make it easy to do a LOOKUP to initialize the MAX7219.· Since you have to specify a register an a value you actually need to SHIFTOUT two bytes before pulsing the LOAD/LATCH line.· This makes sure that two bytes are sent before it loads the data by checking the LSB of index.

    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
  • jonwjonw Posts: 67
    edited 2006-10-18 18:55
    Chris: I am making progress. ·Thanks.·· ·In your attachment file, Simple timer, the last SHIFTOUT is [noparse][[/noparse]index,d7219].
    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-10-18 19:10
    jonw,
    ·
    ·· 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
  • jonwjonw Posts: 67
    edited 2006-10-18 22:13
    Chris,·· Everybit is helping slowly.·· just one question.· We used to say the max needed 16 bits ( and it does).

    ·· 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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-10-18 22:57
    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
  • jonwjonw Posts: 67
    edited 2006-10-19 19:20
    Chris, I am almost ready to start my clock code. It's more complicated that it appears.
    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-10-19 19:38
    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
  • metron9metron9 Posts: 1,100
    edited 2006-10-19 19:51
    Hey Jonw, I found the clock program I made with an RC timer. This will allow you to keep time without worry of how much code gets executed (No Pause Commands needed)

    http://forums.parallax.com/forums/default.aspx?f=5&m=94508&g=94637#m94637

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think outside the BOX!
  • jonwjonw Posts: 67
    edited 2006-10-19 21:51
    Chris,··· thats the answer I needed.··· I had assumed (after reading the·stamp manual) that to use a·modifier, that it had to be used on a alias. I see now it can be used on any variable.·· Thank you·· jonw
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-10-19 22:24
    jonw,
    ·
    ·· 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
  • jonwjonw Posts: 67
    edited 2006-10-19 23:45
    Chris,·· What I had in mind for my time clock is this.·· I need to stop counting at 9 (or somtimes 5)···· If I used a modifier to see the bit change at 9. (or· even can I use DIG to return 9), then I can use this information to increment the next column or digit.

    ········ 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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-10-19 23:52
    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
  • jonwjonw Posts: 67
    edited 2006-10-20 19:16
    Chris,·

    ··········· 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



    ····

    ····

    · ····
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-10-20 21:38
    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
  • jonwjonw Posts: 67
    edited 2006-10-20 23:45
    Chris. I want to build a 6 digit display that displays time. I know I am stumbling along but I am willing to learn.
    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
Sign In or Register to comment.