Stopping a roll over when incrementing a count


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default Stopping a roll over when incrementing a count

    I have a small loop that if a button is pressed it increments a count and if another button is pressed it decrements the count. If the count is 0, how do I stop it from rolling over to 255, and if the count is 255, how do I stop it rolling over to 0?

    Code:
    SETUP:
    LCDOUT $FE, 1, "SET LED CURRENT"
    LCDOUT $FE, $C0, DEC3 IOUT
    IF PORTC.1 = 1 THEN
    IOUT = IOUT + 1
    PAUSE 75
    ENDIF
    IF PORTC.2 = 1 THEN
    IOUT = IOUT - 1
    PAUSE 100
    ENDIF
    pot0.lowbyte = IOUT
    low     CS                         
            pause   1                          
            shiftout    sdo,sck,5,[pot0\16]    
            high    CS                          
            pause   1                          
    
    
    WRITE 10, IOUT
    IF PORTC.0 = 1 THEN test
    PAUSE 75
    
    GOTO SETUP

  2. #2
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Post Re: Stopping a roll over when incrementing a count

    Replace this...
    IF PORTC.2 = 1 THEN IOUT = IOUT - 1

    ...with this...
    IF PORTC.2 = 1 THEN if IOUT > 0 then
    IOUT = IOUT - 1
    endif

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts