I have my LCD-backlight controlled with two buttons; this is why it is in the main loop.

The HPWM command accepts the duty value from 0 to 255.

Actually, when the FOR...NEXT cycle is completed with a count up to 255, the value "wraps" from 255 to 0.

But I track this value to prevent a second press on the same button (it's not nice to see the backlight switched OFF instantaneously and dimm up again when it was already ON - looks like a bug to the user).

To get the HPWM at full range, I would count from 0 to 254 in the FOR...NEXT cycle and, when completed, add one more command to set the duty value to 255. This is not very "clean".

Actually I found another way around. I use REPEAT...UNTIL. Now it works.

I was just suprised to see how the FOR...NEXT cycle affects the count.