KEYPAD and Interrupt on Changing PORTB


Results 1 to 3 of 3

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    Here's something to play with
    Code:
        DEFINE LCD_DREG PORTA
        DEFINE LCD_DBIT 0
        DEFINE LCD_RSREG PORTA
        DEFINE LCD_RSBIT 4
        DEFINE LCD_EREG PORTE
        DEFINE LCD_EBIT 0
        DEFINE LCD_BITS 4
        DEFINE LCD_LINES 2
    
        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_PORT   PORTB    ' COL port = PORTB
        DEFINE KEYPAD_COL_BIT    1        ' COL0 = PORTB.1
        DEFINE KEYPAD_DEBOUNCEMS 50       ' debounce delay = 50 mSec
        DEFINE SCAN_ONCE         1
    
        OPTION_REG.7=0        ' Enable internal crap pull-up :D
        ADCON1=7              ' disable ADCs
        PORTB = 0             '  
        TRISB = %11110000     '
          
        ByteA var byte        '
    
        INTCON = %10001000    ' Enable global interrupt
                              ' Enable interrupt on PORTB change
        on interrupt goto KeypadInt
        CLEAR
    
    Init:    
        lcdout $FE,1,"Press any Key"
    Start:
        if Bytea then
            LCDOUT $FE,1,"Key=",dec bytea
            bytea=0
            pause 1000
            goto init
            endif
        goto start
        
    disable
    KeypadINT:    
        @ READKEYPAD _ByteA
        TRISB=%11110000
        PORTB=0
        INTCON.0=0
        resume
    enable
    you'll find the Keypad.Bas file in attachement. Don't forget to include it in the same directory.

    Enjoy
    Attached Files Attached Files
    Last edited by mister_e; - 18th December 2006 at 08:42.
    Steve

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

Similar Threads

  1. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 20:02
  2. Using Sleep
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th August 2008, 04:05
  3. I Need Help.. I want to generate controlled pulses
    By alabbadi in forum PBP Wish List
    Replies: 7
    Last Post: - 18th November 2007, 10:42
  4. How can i use Interrupt in my program??
    By alabbadi in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th November 2007, 13:28
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

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