Latched buttons


Closed Thread
Results 1 to 10 of 10

Thread: Latched buttons

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Posts
    130

    Default Latched buttons

    Hi, im building an application with a lot of loops and subroutines and I need to know every now and then if a button has been pressed.

    I know that this can be accomplished by reading the port as often is possible, but I tought that by latching the port, when I have time to look at it and view if it changed from the last time it would be easier for my program structure.

    to be clear, here is the metacode:

    buton state=0
    loop:
    program runs
    button is pressed (new state=1), buttons keeps this state
    program continues
    button is sensed and checked if it changed
    loop

    I know that at any given time the button may be pressed twice and I could miss that. This is something I can live with.

    is there a simple way of accomplishing this?

    thanks

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i still prefer to use interrupts. Once a button is pressed, it jump automatically to a X routine.

    if you want to monitor few button, you can use Interrupt on PORTx change.

    What else the program will do?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    may be in your tight loop you could read all 8 bits of a port, store in a temp_port byte and process it later. The delay is minimum.

    Of course that way you will miss the fast double clicks, but as you said you can tolerate this.

    Best is interrupts as Steve stated.

    Ioannis

  4. #4
    Join Date
    Oct 2005
    Location
    Pinckney, Michigan
    Posts
    91


    Did you find this post helpful? Yes | No

    Default

    I have such a circuit, and can email you a PDF later today. This circuit also handles debouncing, which the other suggestions don't allow time for.

  5. #5
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    good ideas posted here, never tough of implementing that way, maybe because I never used the On Interrupt instruction before...

    Will try, will tell

    J. Mark: can you attach the PDF to a message, so all ppl see it?

    Thanks

  6. #6
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    If you don't need instant response to the button press, you can get away with not using interrupts.
    Just test the appropriate interrupt flag bit when you want to know if the button was pressed.
    Remeber to clear the bit after checking it.

Similar Threads

  1. In Circut Debug (ICD) buttons palet is disable for 18F2620
    By muskut in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th June 2010, 05:21
  2. Button command question
    By aherrera in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 31st August 2009, 08:44
  3. Buttons
    By WarPony in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th May 2008, 01:47
  4. 6 Buttons
    By Johansch in forum General
    Replies: 3
    Last Post: - 4th July 2007, 15:21
  5. Buttons are driving me nuts
    By Doormatt in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st May 2007, 23:09

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