How to create 6 buttons?


+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223

    Default How to create 6 buttons?

    Hello everyone!
    I'm trying to develop a basic queuing system, using 2 digit 7 segment. Currently I have 3 buttons to trigger a bell and increment the value display. So far the main functionality are working...but at the moment buttons are on PORTA. The problem I'm facing is when buttons are pressed long enough it continues to increment in which I do not want. My solution is to use DT's interrupt library, using external interrupt (on Pic18F4550).
    For testing I use the following codes...
    Code:
    asm
        __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
        __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
        ;__CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L  & _BORV_2_2L  & _VREGEN_ON_2L   
        __CONFIG    _CONFIG2H, _WDT_OFF_2H 
        __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H 
        __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L  & _XINST_OFF_4L & _DEBUG_OFF_4L 
    endasm
    Define OSC 20
    
    
    INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ; Include if using PBP interrupts
    TRISD = %00000000
    PORTD = %00000000
    Led1 Var POrtD.5
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT0_INT,  _ToggleLED1,   PBP,  yes  
            INT_Handler    INT1_INT,  _ToggleLED1,   PBP,  yes  
            INT_Handler    INT2_INT,  _ToggleLED1,   PBP,  yes 
            endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE   INT0_INT     ; enable external (INT) [email protected]   INT_ENABLE   INT1_INT     ; enable external (INT) interrupts
    @   INT_ENABLE   INT1_INT 
    @   INT_ENABLE   INT2_INT 
    
    
    Main:
      PAUSE 100
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         TOGGLE LED1
    @ INT_RETURN
    Works perfectly for my project...now my question is, I know PORTB has 3 external interrupt. Is there a way I can make the same functionality for 6 buttons? I've read some about interrupt on ANY pins but not really sure how to implement it. Hope anyone can give me an idea/help ..appreciate it very much.
    Name:  targetApplication.gif
Views: 629
Size:  38.4 KB


    Thanks in advance,
    tacbanon

  2. #2
    Join Date
    Sep 2009
    Posts
    721


    Did you find this post helpful? Yes | No

    Default Re: How to create 6 buttons?

    Here is example how to use 1 int to serve button on any input pin of PIC.
    Name:  SCH.JPG
Views: 596
Size:  15.5 KB
    One button also can be attached to INTX pin.
    In your ISR just look which pin is 0, then do whatever you want.
    If all pin is 1, then button on INTX is pressed...

  3. #3
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: How to create 6 buttons?

    @Pedja089
    Thanks so much for sharing...got to try it...feedback here my output later.
    ---------------------------------------
    I have a follow up question, I've tried before to create a 4x4 keypad using Mr_e' s keypad routine...do you think the same concept can be applied to my 6 buttons?

    regards,
    tacbanon
    Last edited by tacbanon; - 7th December 2012 at 10:23.

  4. #4
    Join Date
    Sep 2009
    Posts
    721


    Did you find this post helpful? Yes | No

    Default Re: How to create 6 buttons?

    It probably could...
    Try to pull down all "drive line" And on the top of ISR scan whole keyboard... Then again pull down all "drive lines".

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


    Did you find this post helpful? Yes | No

    Default Re: How to create 6 buttons?

    You could still read the I/O in a Timer based ISR... done fast enough it "give" the feeling of an interrupt. You can even use the Time base as debounce delay... you could even trick the PIC and generate a false INT0 interrupt by writing directly to the according bit.

    No extra hardware needed, free up one I/O.
    Steve

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

  6. #6
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: How to create 6 buttons?

    Hi..something not right, I'm trying to toggle led on PORTB.7 but no success....can you check my code what I'm doing bad?
    Name:  6Buttons.gif
Views: 622
Size:  207.8 KB
    Code:
    asm
        __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
        __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
        ;__CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L  & _BORV_2_2L  & _VREGEN_ON_2L   
        __CONFIG    _CONFIG2H, _WDT_OFF_2H 
        __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H 
        __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L  & _XINST_OFF_4L & _DEBUG_OFF_4L 
    endasm
    Define OSC 20
    TRISB.7 = 0
    PORTB.7 = 0
    TRISD = %00000000
    PORTD = %00000000
    LedD Var POrtD.5
    Led1 var PortB.7
    
    INCLUDE "DT_INTS-18.bas"        ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"      ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,         Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _ToggleLED1,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @    INT_ENABLE   INT_INT     ;RB Port Change Interrupt
    PORTB = %00000000
    Main:
    pause 500
    Toggle LedD 
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         'TOGGLE LED1
         If PortB.1 = 0 then
         Toggle Led1
         else
         If PortB.2 = 0 then
         Toggle Led1
         else
         If PortB.3 = 0 then
         Toggle Led1
         else
         If PortB.4 = 0 then
         Toggle Led1
         else
         If PortB.5 = 0 then
         Toggle Led1
         else
         If PortB.6 = 0 then
         Toggle Led1
         else
         Endif:Endif:Endif:Endif:Endif:Endif
    @ INT_RETURN
    thanks in advance
    tacbanon

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


    Did you find this post helpful? Yes | No

    Default Re: How to create 6 buttons?

    Check the default interrupt edge....that's not what you need

    INTCON2
    Steve

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

  8. #8
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: How to create 6 buttons?

    Hi mister_e,
    Thanks for the time responding...I think the default is INTCON2.6 = 1 so I need to make INTCON2.6 = 0 'interupt on falling edge.
    But either one for me is not working on my setup.

    regards,
    tacbanon

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


    Did you find this post helpful? Yes | No

    Default Re: How to create 6 buttons?

    Have you tried with real hardware or your life depends on How proteus decide to work (assuming it works at all)

    From your schematic you're using led instead of diode and i'm pretty confident proteus is not smart enough to understand this.
    Steve

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

  10. #10
    Join Date
    Sep 2009
    Posts
    721


    Did you find this post helpful? Yes | No

    Default Re: How to create 6 buttons?

    Maybe problem is in D1 - D6.
    Check state of int pin when you press button...
    It square on INT0 should be blue if button is pressed...
    If that isn't case, replace D1 - D6 with 1N4148.

  11. #11
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: How to create 6 buttons?(SOLVED)

    Thank you pedja089 and mister_e...I got it now.

    /tacbanon

Similar Threads

  1. 12F683 + buttons
    By sincity337 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th October 2010, 19:53
  2. Buttons
    By WarPony in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th May 2008, 01:47
  3. 6 Buttons
    By Johansch in forum General
    Replies: 3
    Last Post: - 4th July 2007, 15:21
  4. Buttons are driving me nuts
    By Doormatt in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st May 2007, 23:09
  5. Latched buttons
    By peu in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th January 2006, 00:22

Posting Permissions

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