Pushbutton code routine suggestions?


Closed Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Smile Use the Button function instead

    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

  2. #2
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Sougata

    Thanks for the suggestion and the sample code, I'll give it a try and see what I can accomplish using the Button command.

    Thanks Again
    jessey

Similar Threads

  1. TSA5512/5511 code for PIC16F877/84
    By Marin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th August 2013, 07:16
  2. PIC BASIC TLC5940 code
    By eletrokat in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2010, 22:01
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  4. Replies: 14
    Last Post: - 26th September 2007, 06:41
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 18:23

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts