Quote Originally Posted by skimask View Post
If duty is 10 and you subtract 50 from it, you'll end up with a negative number
You are of course right, but I start the program with duty=500 and use only +/-50 steps, so this IF statement is correct in my case.

After some time I found the bug. At first I set all LCDSEn registers and it was a mistake since the LCD uses only few pins, so my button input pins were in segment functionality instead of I/O. Now I only set the segment pins that are actually used by LCD.