incrementing up to ... then reset

Status
Not open for further replies.

johnl69

Member
Hi

I cant seem to work out how to increment a registry value from 0 to 24 and then have this registry reset to 0 and to display this on a lcd screen.

What im trying to do is to enter a time into a pic to be compared for an alarm, the problem I have is as I press the button to increment the time the display goes from 0 - 9 then through the whole ascii code.

Any help would be appreciated

john
 
What language are you programming it in and wich pic?
But you have to convert your HEX code to a BCD code, there are examples galore of that around here I bet.
 
Sorry I forgot to put I right in assembly and pic 16f877

I can do the bcd to hex conversion but my problem is getting the value to stop at 24 and then reset to 0 at the next button press
 
Last edited:
Euhm, long time since I worked in asm for pics, but do they have a compare function?
Or else you could decrement a register every time you increment and when that hits 0 you can do whatever... BTFSZ i believe that was?
 
To reset the count back to zero if "reg" increments higher than 24:

Code:
    incf    reg,F               ;Inc the reg
    movlw    D'25'            ;load with 25 to check against reg
    xorwf    reg,W            ;Xor but dont affect the reg yet
    btfsc    STATUS,Z       ;Skip if not 25
    clrf    reg                   ;Reached 25 so set reg back to 0
    movf    reg,W            ;Get the new value of reg into w to send to your display
 
btfsC it was appearantly
xor'ing it will work too I guess, and then when they are equal, the Z flag gets cleared or something? Pff i need to get back into my PicASM, it's all 8051 at our school now, and there are WAYY too many instructions, wich is nice too mind you, but a risc is a little different eh :d
 
Shouldn't you be counting from 0 to 23 or 1 to 24. Counting from 0 to 24 will result in a 25 hour day!!

Mike.
 
Thanks alot guys for your help,

Pommie, Yes it should be 0 - 23 and then 0 - 59 but it was late and I was still feeling the effects from the anastetic
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…