Button, some test.


+ Reply to Thread
Results 1 to 5 of 5

Thread: Button, some test.22 days old

  1. #1
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    195
    Thumbs Up
    Received: 8
    Given: 5
    Total Downloaded
    331.75 MB

    0 Not allowed!

    Default Button, some test.

    Hello forum, wishing all well.

    I stumble on this case

    Code:
    Device = 16F877A
    Declare Xtal  20                           ' ensure the correct clock
    
    Config FOSC_HS, WDTE_OFF, PWRTE_OFF, BOREN_ON, LVP_OFF, CPD_OFF, _
    WRT_OFF, DEBUG_OFF, CP_OFF
    
    Declare Hserial_Baud 57600          ' baud rate 57600
    Declare Hserial_Clear = On
    
    
    Symbol TAREBTN 4                    ' pin number assigned to set current zero
    Symbol UPBTN   5                    ' pin number assigned to input
    Symbol DOWNBTN 6                    ' pin number assigned to input
    Symbol SETTBTN 7                    ' pin number assigned for the setting
    Symbol TARE  PORTD.TAREBTN          ' assigned to tare button (TM1637 like)
    Symbol LNGPRESS 1                   ' Name the button period lenght
    Symbol PRESSED 2
    '==========================INITIATION===========================================
    TRISA = 0                           ' All output
    TRISB = 0                           ' all output
    TRISD = 110000                   ' high nibble for buttons input
    TRISC = 000010                   ' serial data input on RC1 and RC7 input RX
    OPTION_REG = 0                ' setting the timer0 prescaler, No pullup
    PORTB = 0
    INTCON = 0
    
    Proc testbutton(port As Byte, pin As Byte, longpress As Byte), Byte
    ' special procedure to see how the PORT button is pressed for long or less
      While GetBit port,pin = 0         ' checking whether the button is held
        Inc Result                      ' put a counter
        DelayMS 20                      ' one cycle wait for about 20 mSec
        If Result > longpress  Then     ' if is long enough, will collect the data
          Result = LNGPRESS             ' equal to 1
          Return
        End If
      Wend
      If Result > 10 Then                 ' a short press
        Result = PRESSED                  ' equal to 2
      Else
        Clear Result
      End If
    EndProc
    
    main:
    Do
      HSerOut ["."]
      DelayMS 1000
      Select testbutton(PORTD, TAREBTN,80)
        Case LNGPRESS
          HSerOut ["longpress OK", 13, 10]
        Case PRESSED
          HSerOut ["pressed OK", 13, 10]
      End Select
    Loop
    End
    The result is only the first case. Even when I press for a short it will fall onto the While loop. It looks like that after the first test the comparison status remains always the same.

    I found that's because of not addressing the port correctly. If I change the testbutton(PORTD, pin), then the result comes as expected, but this will be beyond the procedure flexibility.

    Anyways I'd rather prefer to use the Button command, but I can't figure out how to set the repetition in a style of which will count similarly to my procedure.
    Last edited by keytapper; 9th May 2020 at 02:34.

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,749
    Thumbs Up
    Received: 51
    Given: 96
    Total Downloaded
    1.33 GB

    0 Not allowed!

    Default Re: Button, some test.

    Hi,

    Unless you have nothing to do in your code waiting on a button in single loop is a waste of time. IMHO

    The way I handle it is either pass the button press detection of to an interrupt routine or a sub that is run at a set period. Depending on how accurate you want to be and what else you have going the "test period" can be either a delay at the end of your main loop or flags generated by an interrupt routine or actually in the interrupt routine as you know it was x period between the last one.

    Once you have a known reference clock you can test the keys and count the number of times you see it depressed. No need for debouncing as that is taken care of by the delay between periods.

    Now back to your code and my thoughts
    Do not bother with getbit, I'm sure you will have enough code space to test each button individually. That way you can track issues down to individual buttons.
    I would not use the Proc as part of a function. Its one line of code to call it first then test the result.
    Tim

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    195
    Thumbs Up
    Received: 8
    Given: 5
    Total Downloaded
    331.75 MB

    0 Not allowed!

    Default Re: Button, some test.

    Quote Originally Posted by Tim View Post
    Unless you have nothing to do in your code waiting on a button in single loop is a waste of time.
    Well the snippet is just a working test. Just to figure that it might be involved to react to the operator action and to have a display for the purpose.

    Quote Originally Posted by Tim View Post
    detection of to an interrupt routine or a sub that is run at a set period.
    The hardware is not fully my design, so I stuck with the original one.
    Anyways the detection of 4 keys is effectiver when there are lines going high/low and one input to external input interrupt pin. The lines might be used in conjunction to a LCD or 7 segment display cathodes.

    About the mentioned procedure I thought to take advantage of its flexibility so it may be reuse in future. But the passed in variable don't trigger the condition to check which RAM back (for 14bit core) might involved so the result is not the correct memory position. The pin is not easy to be considered as such because even the assembler accepts only constants.

    I concluded to change to the wanted port address and disregarding the procedure flexibility.

    Testing Button command , it might be worth to use as much as the rate is set to the wanted number of cycles and the target label will jump back when the button is on the wanted state.
    But for GetBit and Button the code is rather voluminous.
    If the wanted result is to have the most optimized code, then a very simple btfs? PORT,PIN will give that. Definitely the two value are constants.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,749
    Thumbs Up
    Received: 51
    Given: 96
    Total Downloaded
    1.33 GB

    0 Not allowed!

    Default Re: Button, some test.

    Hi

    What you will find with proton is that the code is so tight there really is no need to drop to asm unless its just for a tiny delay like NOP.
    If you want to capture all the lines then just grab the whole port into a variable and test the variable. All that though I'm sure you will be aware of.

    Are you still having issues? Its hard to actually answer the question sometimes as ideas of what the issue is do not match what the real issue is. I'm lazy have dyslexia and never read the post properly which never helps.

    Tim
    Tim

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    195
    Thumbs Up
    Received: 8
    Given: 5
    Total Downloaded
    331.75 MB

    0 Not allowed!

    Default Re: Button, some test.

    Quote Originally Posted by Tim View Post
    Are you still having issues?
    No more, thanks.
    I had to drop the idea to use such procedure style.

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Test
    By KrysG in forum Test Postings
    Replies: 2
    Last Post: 24th August 2019, 08:50
  2. test
    By Graham61 in forum Test Postings
    Replies: 0
    Last Post: 13th February 2019, 12:56
  3. Just a test
    By RogeMan in forum Test Postings
    Replies: 0
    Last Post: 12th February 2019, 22:56
  4. another test
    By Heiko in forum Test Postings
    Replies: 0
    Last Post: 25th December 2017, 17:44
  5. [SOLVED !] Test
    By ProtonUser in forum Test Postings
    Replies: 0
    Last Post: 3rd May 2017, 08:19

Tags for this Thread

Posting Permissions

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