Min, max
chick
Posts: 16
I have been working on a program that needs to use the instruction MIN. But it doesn't seem to work.
N is a var (8 bit) from 0-255. At one piont in the program I need to lower n from its midpiont of 128 in increments of 40.
The line is written: n=n-40 min 3
Yet what happens is that n goes from 128 to 88 to 48 to 8, then instead of stopping at 3 it jumps to 255 and keeps subtracting. 8 gets it to 0 or 255 and subtrackt the remaining 32 and ends up at 223 and then 183, etc.
Any thoughts on the fix.
Thanks in advance.
Lou
N is a var (8 bit) from 0-255. At one piont in the program I need to lower n from its midpiont of 128 in increments of 40.
The line is written: n=n-40 min 3
Yet what happens is that n goes from 128 to 88 to 48 to 8, then instead of stopping at 3 it jumps to 255 and keeps subtracting. 8 gets it to 0 or 255 and subtrackt the remaining 32 and ends up at 223 and then 183, etc.
Any thoughts on the fix.
Thanks in advance.
Lou
Comments
n=n-40
IF n > 128 THEN n=3
This catches the situation when a negative occurs and forces it to the value 3.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Many thanks, that solved the problem.
Lou