Dear Jessey,
You can do the job more easily using the button function. It handles the debounce , and has an autorepeat feature. Autorepeat delay , and rate are also programmable. You need to create a variable for the button and also make sure that the routine runs in a loop.
Here is a code example:
'************************************************* ******************************
SPEEDSET:
B1 = 0 : B2 = 0 : LED1 = 0 : LED2 = 0 : LED3 = 0 ' TURN OFF ALL LEDS
LCDOUT $FE, 1 ' CLEAR THE LCD
LCDOUT "SET SERVO SPEED" ' SHOW THE SUB-MENU ITEM
PAUSE 2000 ' CHECK FOR VALID SPEED
IF SPEED > 127 THEN SPEED = 0
SPEED_PRESET_LOOP: ' PRESET LOOP
LCDOUT $FE, $C0,"TRACKSPEED=",DEC SPEED," "
PAUSE 1 ' SHORT DELAY TO REDUCE LCD FLICKER
IF HALT = 0 THEN QUIT ' CHECK IF STOP BUTTON HIT THEN QUIT TO MAIN MENU
BUTTON INCR, 0, 200, 30, B1, 1, SPEED_PLUS ' IF THE INCREMENT BUTTON IS PRESSED (PULLED-UP)
BUTTON DECR, 0, 200, 30, B2, 1, SPEED_MINUS ' IF THE DECREMENT BUTTON IS PRESSED (PULLED-UP)
GOTO SPEED_PRESET_LOOP
SPEED_PLUS: ' ROUTINE TO INCREASE THE SPEED VARIABLE
SPEED = SPEED + 1
IF SPEED > 127 THEN SPEED = 0
GOTO SPEED_PRESET_LOOP
SPEED_MINUS: ' ROUTINE TO DECREASE THE SPEED VARIABLE
SPEED = SPEED - 1
IF SPEED > 127 THEN SPEED = 0
GOTO SPEED_PRESET_LOOP
'************************************************* ******************************
The speedset routine is practically a sub-menu in my application and is entered from a menu choice. B1 and B2 are button variables (byte). Speed is the variable that is modified through the buttons. INCR is an alias for the increment button normally high (pulled- up) and DECR is an alias for the decrement button. Halt is an alias for the Stop button (that lets one quit from the sub-menu or the main-menu)
Regards
Sougata




Bookmarks