Greetings all,

Too many interests and hobbies have kept me away from electronics for a while, but I'm back again and trying to re-learn what little I knew about PICs....

Todays question is how to easily limit a number to "not less than zero".

I have a number... lets call it "volume" and I want to increment or decrement that number by "step", which could be from 1 to 9.
I want to limit "volume" to no more than 350 at the upper end and no "less" than zero at the low end.

So if I press buttonA then volume increments by the step amount, and if I press buttonB then volume decrements by step amount.

Here's a simple example (of what doesn't work):
Code:
 
 volume = 100        'set a default level
 step = 3               'This could be ANY NUMBER FROM 1 TO 9

 
 main:

 if buttonA  then volume = (volume + step) min 350     'this works fine to limit the top end to 350

 if buttonB  then volume= (volume - step)  max 0        'but of course THIS fails, because it's hard to go lower than zero

 LCDOUT $fe, $c0, dec volume

 pause 50
 goto main

 end
So I'm sure that there must be an easy way to limit a number from decrementing "below" zero... ?
Help please?


Thanks much!

Steve