I need to get a "HPWM 1, 255, 1000" final command with a Duty value of 255.
When this FOR...NEXT loop is completed, the HPWM command will be correct ("HPWM 1, 255, 1000" - see first read of Duty) BUT Duty's value will be 0 (see second read of Duty).Code:... Duty VAR BYTE Duty = 0 FOR Duty = 0 TO 255 HPWM 1, Duty, 1000 LCDOUT $FE, 2, DEC Duty 'First read of Duty NEXT LCDOUT $FE, $C0, DEC Duty 'Second read of Duty ...
Even if the count is completed (Duty has reached 255), passing the last NEXT command will increment Duty by 1 and make it a 0.
This is what happens with my 16F88 programmed with PBP. I never expected such a result.
In my program, I use Duty as a reference to check if my LCD-backlight is fully OFF (Duty = 0) or if it is fully ON (Duty = 255).
If Duty is 0, I'm allowed to press only button 'A'; if Duty's value is 255, I'm allowed to press only button 'B'.
In other words, if Duty is 0, I don't want to allow a second press on button 'A'; I will only accept button 'B' and vice-versa if Duty is 255.
The solution I found now is this one:
Code:... SUBROUTINE: REPEAT Duty = Duty + 1 HPWM 1, Duty, 1000 UNTIL Duty = 255 RETURN ...




Bookmarks