PDA

View Full Version : Stopping a roll over when incrementing a count



jmgelba
- 5th May 2011, 22:03
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?


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

tenaja
- 5th May 2011, 22:06
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