Button subfunction 16F628


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2005
    Posts
    18

    Default Button subfunction 16F628

    Here I go again :-)

    I am trying to display some values on an lcd. One that counts from 10 to 20 using up\down buttons. And when I press RB1 the lcd counts from 80 - 90 using the same up\down. I created the dummy functions because I found that having these allowed me to hold the button and have continous incrementation\decrementation (see code below). Ive connected RA4 and RA1 to ground.

    My problem is that I want to solely increment\decrement num2 without interfering with num1. The other problem is that when I press RB1 to go num2 mode, the lcd counts up on its own. If anyone has a look at my grubby code and sees what Im trying to do and where Im doin wrong, can you shead some light please?

    Muchas Gracias


    Juan






    ************************************************** ******
    Include "modedefs.bas" ' Include serial modes
    DEFINE BUTTON_PAUSE 75 ' button debounce delay is 75ms

    I con 254 '254h = 1111 1110 (Sets LCD to command mode)
    ClrScr con 1 '01h = 0000 00001 (Clears Screen & goes to position 1)
    Line2 con 192 'COh = 1100 0000B (sets address to positionn 40 on LCD)
    DispCur con 12 '12h = 0000 1100 (activates display & cursor mode)
    'Commands obtained from LCD article in epemag.com

    B0 var byte
    B1 var byte
    B2 var byte
    B3 var byte
    B4 var byte
    number var word
    number2 var word

    B0 = 0
    B1 = 0
    B2 = 0
    B3 = 0
    B4 = 0

    number = 15
    number2 = 85

    serout PORTB.0,T9600,[i,clrScr] ' Clearscreen
    pause 400

    numSetup:
    serout PORTB.0,T9600,[I,128,"Display num1"] ' Setup display
    serout PORTB.0,T9600,[I,line2," Press button"] ' Setup display
    numMain:
    pause 25
    Button PORTA.7,1,200,255,B0,1,incNum
    Button PORTA.6,1,200,255,B1,1,decNum
    Button PORTA.4,1,200,255,B0,1,dummy1
    Button PORTA.1,1,200,255,B1,1,dummy2
    Button PORTB.1,1,200,255,B2,1,number2Setup
    Serout PORTB.0,T9600,[i,line2,#number]
    goto numMain

    incNum:
    if number > 19 then numMain
    number = number + 1
    pause 100
    Goto numMain ' goes back to main function

    decNum:
    if number < 11 then numMain
    number = number - 1
    pause 100
    Goto nummain ' goes back to main function

    dummy1:
    PAUSE 1000
    GOTO nummain
    dummy2:
    PAUSE 1000
    GOTO nummain

    number2Setup:
    serout PORTB.0,T9600,[i,clrScr] ' Clearscreen
    serout PORTB.0,T9600,[I,128,"Display num2"] ' Setup display
    number2Main:
    pause 25
    Button PORTB.7,1,200,255,B3,1,incNumber2
    Button PORTA.6,1,200,255,B4,1,decNumber2
    Button PORTB.1,1,200,255,B2,1,numsetup
    serout PORTB.0,T9600,[I,line2,#number2]
    goto number2Main

    incNumber2:
    if number2 > 89 then number2Main
    number2 = number2 + 1
    pause 100
    Goto number2main

    decNumber2:
    if number2 < 81 then number2main
    number2 = number2 - 1
    pause 100
    Goto number2main
    Last edited by Jųan; - 11th August 2005 at 01:25.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Jųan,

    The problem might be related to re-using variables in the BUTTON commands.

    Button PORTA.7,1,200,255,B0,1,incNum
    Button PORTA.6,1,200,255,B1,1,decNum
    Button PORTA.4,1,200,255,B0,1,dummy1
    Button PORTA.1,1,200,255,B1,1,dummy2
    Button PORTB.1,1,200,255,B2,1,number2Setup

    Within any single loop each BUTTON command must have it's own variable to count the passes, and that variable can't be used anywhere else in the program.<br><br>
    DT

  3. #3
    Join Date
    Jul 2005
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    Thanks for your reply Darrel, I tried that but the auto repeat function didnt work when using unique Bvariables. Also the displayNum2 still counted on its own. I have attached a diagram of how I've connected the switch.

    Juan
    Attached Images Attached Images  
    Last edited by Jųan; - 11th August 2005 at 01:39.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Did you make ALL of the button commands use a separate variable? There are 8 button commands, you should have B0-7 variables.

    Also, try putting a CLEAR statement at the top of the program. According to the manual... The variable must be initialized to 0 prior to use.<br><br>
    DT

  5. #5
    Join Date
    Jul 2005
    Posts
    18


    Did you find this post helpful? Yes | No

    Thumbs up

    Bingo Bango!

    Yes I placed the Bvariables inside the corresponding loop. This allowed me to get rid of the dummy file call. Thanks Darrel, much appreciated!

  6. #6


    Did you find this post helpful? Yes | No

    Talking Hola Juan

    Hola Juan,

    Veo que hablas español, que bueno encontrar a alguien del mismo idioma me gustaria que me escribieras y me dieras tu mail para comunicarnos en este fabuloso foro mi mail es [email protected]

    Saludos

    Leonardo



    Quote Originally Posted by Jųan
    Here I go again :-)

    I am trying to display some values on an lcd. One that counts from 10 to 20 using up\down buttons. And when I press RB1 the lcd counts from 80 - 90 using the same up\down. I created the dummy functions because I found that having these allowed me to hold the button and have continous incrementation\decrementation (see code below). Ive connected RA4 and RA1 to ground.

    My problem is that I want to solely increment\decrement num2 without interfering with num1. The other problem is that when I press RB1 to go num2 mode, the lcd counts up on its own. If anyone has a look at my grubby code and sees what Im trying to do and where Im doin wrong, can you shead some light please?

    Muchas Gracias


    Juan






    ************************************************** ******
    Include "modedefs.bas" ' Include serial modes
    DEFINE BUTTON_PAUSE 75 ' button debounce delay is 75ms

    I con 254 '254h = 1111 1110 (Sets LCD to command mode)
    ClrScr con 1 '01h = 0000 00001 (Clears Screen & goes to position 1)
    Line2 con 192 'COh = 1100 0000B (sets address to positionn 40 on LCD)
    DispCur con 12 '12h = 0000 1100 (activates display & cursor mode)
    'Commands obtained from LCD article in epemag.com

    B0 var byte
    B1 var byte
    B2 var byte
    B3 var byte
    B4 var byte
    number var word
    number2 var word

    B0 = 0
    B1 = 0
    B2 = 0
    B3 = 0
    B4 = 0

    number = 15
    number2 = 85

    serout PORTB.0,T9600,[i,clrScr] ' Clearscreen
    pause 400

    numSetup:
    serout PORTB.0,T9600,[I,128,"Display num1"] ' Setup display
    serout PORTB.0,T9600,[I,line2," Press button"] ' Setup display
    numMain:
    pause 25
    Button PORTA.7,1,200,255,B0,1,incNum
    Button PORTA.6,1,200,255,B1,1,decNum
    Button PORTA.4,1,200,255,B0,1,dummy1
    Button PORTA.1,1,200,255,B1,1,dummy2
    Button PORTB.1,1,200,255,B2,1,number2Setup
    Serout PORTB.0,T9600,[i,line2,#number]
    goto numMain

    incNum:
    if number > 19 then numMain
    number = number + 1
    pause 100
    Goto numMain ' goes back to main function

    decNum:
    if number < 11 then numMain
    number = number - 1
    pause 100
    Goto nummain ' goes back to main function

    dummy1:
    PAUSE 1000
    GOTO nummain
    dummy2:
    PAUSE 1000
    GOTO nummain

    number2Setup:
    serout PORTB.0,T9600,[i,clrScr] ' Clearscreen
    serout PORTB.0,T9600,[I,128,"Display num2"] ' Setup display
    number2Main:
    pause 25
    Button PORTB.7,1,200,255,B3,1,incNumber2
    Button PORTA.6,1,200,255,B4,1,decNumber2
    Button PORTB.1,1,200,255,B2,1,numsetup
    serout PORTB.0,T9600,[I,line2,#number2]
    goto number2Main

    incNumber2:
    if number2 > 89 then number2Main
    number2 = number2 + 1
    pause 100
    Goto number2main

    decNumber2:
    if number2 < 81 then number2main
    number2 = number2 - 1
    pause 100
    Goto number2main

Similar Threads

  1. Sony SIRC IR Issue
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th August 2015, 08:10
  2. Button problem driving me crazy!! Please help!
    By bearpawz in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 20th November 2007, 14:46
  3. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  4. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  5. Button Push within 3 second Window
    By Tissy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd December 2005, 10:06

Members who have read this thread : 1

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