Keypad and DT's Instant Interrupts


+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Oct 2005
    Posts
    35

    Question Keypad and DT's Instant Interrupts

    DOH! I had a detailed question but it got cleared. So here's the short-short version.

    Has enybody included a 4x4 keypad routine in with DT's instant interrupts? It would most likely use port B change to trigger. I found forum references to keypad and interrupts but since I'm using the elapsed timer routine anyway I think I should stick with the "instant interrupts" technique. Can it be done with a change in variable value?



    (Flanders hippie dad) "We tried nothing, and nothing ain't working"?
    Thanks,
    Homerclese

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

    Default

    You can still use a Timer interrupt with my KEYPAD.BAS routine. Just use the DEFINE SCAN_ONCE 1 in your settings.

    Thread:
    http://www.picbasic.co.uk/forum/showthread.php?t=3250

    i've attach the latest version... just in case of.
    Attached Files Attached Files
    Steve

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

  3. #3
    Join Date
    Oct 2005
    Posts
    35

    Default

    Thanks for the quick response.
    I have tried the code and it works. However there is an issue. I have a 4x4 setup but it acts like a 4x3 keypad. I can get digits 1 through 12. If I change the define as below to 4 col then nothing works. Im still checking but I think this is the same hardware setup I had before and it worked as a 4x4. Any suggestions?

    TRISB = %11110000 'PortB first four bits outputs second four bits inputs

    include "KeyPad.bas"

    DEFINE KEYPAD_ROW 4 ' 4 ROW keypad
    DEFINE KEYPAD_ROW_PORT PORTB ' ROW port = PORTB
    DEFINE KEYPAD_ROW_BIT 4 ' ROW0 = PORTB.4
    'DEFINE KEYPAD_COL 3 ' 3 COL keypad
    DEFINE KEYPAD_COL 4 ' 4 COL keypad
    DEFINE KEYPAD_COL_PORT PORTB ' COL port = PORTB
    DEFINE KEYPAD_COL_BIT 1 ' COL0 = PORTB.1
    DEFINE KEYPAD_DEBOUNCEMS 20 ' debounce delay = 20 50 mSec
    DEFINE SCAN_ONCE 1

    OPTION_REG.7=0 ' Enable internal crap pull-up
    ADCON1=7 ' disable ADCs
    PORTB = 0 '

    ByteA var byte '
    Thanks,
    Homerclese

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

    Default

    mmm, it's working here as suppose to. Using your code above on a 16F877, i tried with...
    Code:
    <font color="#000000">    @       __CONFIG _XT_OSC &amp; _LVP_OFF
        
        <font color="#000080">INCLUDE </font>&quot;C:\PBP_PROG\INCLUDE_ROUTINES\KeyPad.bas&quot;
        <font color="#000080">INCLUDE </font>&quot;c:\PBP_PROG\EASYPIC4\LCD4.bas&quot;           
        
        <font color="#000080">DEFINE </font>KEYPAD_ROW 4 	 <font color="#008000">' 4 ROW keypad
        </font><font color="#000080">DEFINE </font>KEYPAD_ROW_PORT PORTB <font color="#008000">' ROW port = PORTB
        </font><font color="#000080">DEFINE </font>KEYPAD_ROW_BIT 4 	 <font color="#008000">' ROW0 = PORTB.4
        </font><font color="#000080">DEFINE </font>KEYPAD_COL 3 	 <font color="#008000">' 4 COL keypad
        </font><font color="#000080">DEFINE </font>KEYPAD_COL_PORT PORTB <font color="#008000">' COL port = PORTB
        </font><font color="#000080">DEFINE </font>KEYPAD_COL_BIT 1 	 <font color="#008000">' COL0 = PORTB.0
        </font><font color="#000080">DEFINE </font>KEYPAD_DEBOUNCEMS 20  <font color="#008000">' debounce delay = 20 50 mSec
        </font><font color="#000080">DEFINE </font>SCAN_ONCE 1
        
        OPTION_REG.7=0 	         <font color="#008000">' Enable internal crap pull-up
        
        </font>ByteA <font color="#000080">VAR BYTE
    
        PAUSE </font>500
        <font color="#000080">LCDOUT </font>$FE,1,&quot;PRESS ANY KEY&quot;
    
    Start:
        @ READKEYPAD _ByteA
        <font color="#000080">IF </font>ByteA <font color="#000080">THEN 
            LCDOUT </font>$FE,$C0,<font color="#000080">REP </font>&quot; &quot;\2,$FE,$C0, <font color="#000080">DEC </font>ByteA
            <font color="#000080">ENDIF
            
        GOTO </font>Start
    make sure you have disable the LVP mode and there's no faulty I/Os
    Steve

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

  5. #5
    Join Date
    Oct 2005
    Posts
    35

    Default

    I will check further. I am using the f877 pic. Note that I tried changing this line to "4". Is that wrong?

    DEFINE KEYPAD_COL 3 ' 4 COL keypad

    Looking at it now I realize that its probably 0 to 3 which is 4 states or columns. So the above line should stay as it is?
    Thanks,
    Homerclese

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

    Default

    using the previous but changing KEYPAD_ROW or KEYPAD_COL number it always work for me. Yeah, even a 1X1 keypad work... wooohoo how handy it is

    Now, using a TIMER0 interrupt and DT-INT14, it looks like
    Code:
    <font color="#000000">    @       __CONFIG _XT_OSC &amp; _LVP_OFF
        
        <font color="#000080">INCLUDE </font>&quot;C:\PBP_PROG\INCLUDE_ROUTINES\KeyPad.bas&quot;
        <font color="#000080">INCLUDE </font>&quot;c:\PBP_PROG\EASYPIC4\LCD4.bas&quot;  
        <font color="#000080">INCLUDE </font>&quot;C:\PBP_PROG\INCLUDE_ROUTINES\DT_INTS-14.bas&quot;
        <font color="#000080">INCLUDE </font>&quot;C:\PBP_PROG\INCLUDE_ROUTINES\ReEnterPBP.bas&quot;            
        
        <font color="#000080">DEFINE </font>KEYPAD_ROW 4 	 <font color="#008000">' 4 ROW keypad
        </font><font color="#000080">DEFINE </font>KEYPAD_ROW_PORT PORTB <font color="#008000">' ROW port = PORTB
        </font><font color="#000080">DEFINE </font>KEYPAD_ROW_BIT 4 	 <font color="#008000">' ROW0 = PORTB.4
        </font><font color="#000080">DEFINE </font>KEYPAD_COL 3 	 <font color="#008000">' 4 COL keypad
        </font><font color="#000080">DEFINE </font>KEYPAD_COL_PORT PORTB <font color="#008000">' COL port = PORTB
        </font><font color="#000080">DEFINE </font>KEYPAD_COL_BIT 1 	 <font color="#008000">' COL0 = PORTB.0
        </font><font color="#000080">DEFINE </font>KEYPAD_DEBOUNCEMS 20  <font color="#008000">' debounce delay = 20 50 mSec
        </font><font color="#000080">DEFINE </font>SCAN_ONCE 1
        
        
    <font color="#000080">ASM
    INT_LIST  macro    
            INT_Handler   TMR0_INT,  _TMR0Interrupt,   PBP,  yes
        endm
        INT_CREATE               
    ENDASM
        
        </font>OPTION_REG=%00000100    	 <font color="#008000">' Enable weak-pull ups
    </font>                            	 <font color="#008000">' Prescaler assigned to Timer0
    </font>                            	 <font color="#008000">' rate 1:32
    
        </font>ByteA <font color="#000080">VAR BYTE
        </font>TMR0IF <font color="#000080">VAR </font>INTCON.2
        
        <font color="#000080">PAUSE </font>500
        <font color="#000080">LCDOUT </font>$FE,1,&quot;PRESS ANY KEY&quot;
    
        @ INT_ENABLE  TMR0_INT
    
    Start:
        <font color="#000080">IF </font>ByteA <font color="#000080">THEN 
            LCDOUT </font>$FE,$C0,<font color="#000080">REP </font>&quot; &quot;\2,$FE,$C0, <font color="#000080">DEC </font>ByteA
            <font color="#000080">ENDIF
        GOTO </font>Start
        
    
    TMR0Interrupt:
        @ READKEYPAD _ByteA
        TMR0=0
        @ INT_RETURN
    and it's still working.

    do a I/O test with LEDs and push button to see if there's any faulty.

    KEYPAD_COL 3 really set the KeyPAd to 3 column, DEFINE KEYPAD_COL_BIT 1 will imply you're connected to PORTB.1, PORTB.2, PORTB.3

    same for rows, DEFINE KEYPAD_ROW 4, 4 rows, DEFINE KEYPAD_ROW_BIT 4, so PORTB.4, PORTB.5, PORTB.6 and PORTB.7.
    Last edited by mister_e; - 26th April 2007 at 16:13.
    Steve

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

  7. #7
    Join Date
    Oct 2005
    Posts
    35

    Default

    The problem is that PORTB.0 not detecting

    I swapped B.o and B.1 keypad lines - problem remains with B.0

    Changed to another 16f877 chip - problem remains with B.0

    I noticed your last post about
    DEFINE KEYPAD_COL_BIT ' COL 1 = PORTB.1.


    I am connected to PORTB pins 0 through 3. I had the setting above and changed it to:
    DEFINE KEYPAD_COL_BIT 0 ' COL0 = PORTB.0

    PORTB.0 now works but B.3 now does not.
    It's like I'm scanning only 3 bits
    Thanks,
    Homerclese

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

    Default

    0-3 is 4 bits, so you have to configure to 4 COLUMNs.

    maybe 4 colums and 3 row now?

    on the other hand my comments in the code above are not right... sorry

    for a whole 4X4 keypad it should be
    Code:
        DEFINE KEYPAD_ROW 4 	 ' 4 ROW keypad
        DEFINE KEYPAD_ROW_PORT PORTB ' ROW port = PORTB
        DEFINE KEYPAD_ROW_BIT 4 	 ' ROW0 = PORTB.4
        DEFINE KEYPAD_COL 4 	 ' 4 COL keypad
        DEFINE KEYPAD_COL_PORT PORTB ' COL port = PORTB
        DEFINE KEYPAD_COL_BIT 0 	 ' COL0 = PORTB.0
        DEFINE KEYPAD_DEBOUNCEMS 20  ' debounce delay = 20 mSec
        DEFINE SCAN_ONCE 1
    i have this setup on a EASYPIC4 board and their 4X4 keypad like this


    And using the internal pull-up.

    their keypad schematic is bellow
    http://www.mikroe.com/pdf/keypad_board_schematic.pdf
    Last edited by mister_e; - 26th April 2007 at 19:18.
    Steve

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

  9. #9
    Join Date
    Oct 2005
    Posts
    35

    Thumbs up

    Corrected to:

    DEFINE KEYPAD_COL 4 ' 4 COL keypad (0-3)

    DEFINE KEYPAD_COL_BIT 0 ' COL 0 = PORTB.0 (wires start at PORTB bit 0)

    Keypad is now working properly.

    Many thanks for your attention and efforts.
    Thanks,
    Homerclese

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

    Cool

    Cool!

    Highlighted Code.
    Instant Interrupt Examples.
    And the solution to a problem with DT in the title.

    I think I'll just sit back and enjoy life for awhile.
    <br>
    DT

  11. #11
    Join Date
    Oct 2005
    Posts
    35

    Question

    I have noticed that the keypad display output occurs on the release of the keypress. The setup I have which is like a "musical chairs" type of game requires variable index capture of the first player to be detected on "keypress". Can I change this?
    Also, in my old kepad routine I would lockout a team of 4 players who jumped the gun by removing that column from the scan, bit 0 in the example portion below.

    If penaltyflagA = 0 then ' good start
    PortB=%00001111
    butn = butn +4
    Goto PlayerB ' Pull the first row line LOW
    Else ' penalty for this player
    PortB=%00001110 ' remove this col from keypad scan for round

    Where is the best place in this keypad code to do the same?
    Last edited by Homerclese; - 27th April 2007 at 03:22.
    Thanks,
    Homerclese

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

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Cool!

    Highlighted Code.
    Instant Interrupt Examples.
    And the solution to a problem with DT in the title.

    I think I'll just sit back and enjoy life for awhile.
    <table><tr><td>Yeah, everything in the same post... but... hum hum, you forgot Macro and INCLUDE :which i'm now converted to... it's all your fault </td><td></td></tr></table>

    Homer, can you post your whole code?
    Last edited by mister_e; - 27th April 2007 at 06:58.
    Steve

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

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