Complete Keypad Example


Results 1 to 19 of 19

Threaded View

  1. #14
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Complete Keypad Example

    No more posts here...but hope to find help !
    I try to build this device ; on pushing on different button - having one different result !
    But...nothing happens ... Something's wrong ! Any advice ? Thanks !
    Code:
       @ DEVICE pic16F628A, INTRC_OSC, WDT_OFF, PWRT_OFF, BOD_OFF, MCLR_ON, LVP_OFF, CPD_OFF, PROTECT_OFF 
    
       
       Include "modedefs.bas"   ' Serial Protocol
       Define   OSC 4           ' 4MHz crystal used
       CMCON = 7                ' Disable on-chip comparator, PORTA in digital mode
                  
       '// Define port pins as inputs and outputs ...
       TRISA  = %00001000
       TRISB  = %00001100
                     
       '// Declare Variables...
       Col_A     VAR PORTB.1
       Col_B     VAR PORTA.2 
       Row_A     VAR PORTA.3
       Row_B     VAR PORTB.3
       Row_C     VAR PORTB.2
      
       Buzzer    VAR PORTB.5
        
       Scan_Col  VAR BYTE       ' Counter - denoting current col in scan 
       Key_Press VAR BYTE       ' Contains value of key (0-9) & * + #
       Key_Down  VAR BYTE       ' Flag set true when key is depressed
       Allow_Key VAR BYTE       ' Flag - disallow multiple keys being pressed
       I         VAR byte       ' General working var
    
       Scan_Keypad:
       
       '// Scan cols 
          @ incf _Scan_Col, 1   ' Inc col pos...
        
          SELECT CASE Scan_Col  ' Col (1-2)
                 
                 CASE 1
                      Col_A = 0 ' Switch on col (active low)    
                      Col_B = 1 ' Col off    
                               
                      '// 3 Key
                               IF Row_A = 0 THEN        ' Key down? ... 
                                  IF Allow_Key = 0 THEN ' Any other key down?
                                     Key_Press = 3      ' Load var w/value of key           
                                     Allow_Key = 1      ' Disallow other keys
                                  ENDIF   
                               ENDIF                          
                      '// 6 Key
                               IF Row_B = 0 THEN
                                  IF Allow_Key = 0 THEN 
                                     Key_Press = 6                 
                                     Allow_Key = 1
                                  ENDIF   
                               ENDIF
                      '// 9 Key
                               IF Row_C = 0 THEN
                                  IF Allow_Key = 0 THEN 
                                     Key_Press = 9                 
                                     Allow_Key = 1
                                  ENDIF   
                               ENDIF
                      
                 CASE 2
                      Col_A = 1    
                      Col_B = 0    
      
                               
                      '// 2 Key
                               IF Row_A = 0 THEN
                                  IF Allow_Key = 0 THEN 
                                     Key_Press = 2                 
                                     Allow_Key = 1
                                  ENDIF   
                               ENDIF
                      '// 5 Key
                               IF Row_B = 0 THEN
                                  IF Allow_Key = 0 THEN 
                                     Key_Press = 5                 
                                     Allow_Key = 1
                                  ENDIF   
                               ENDIF
                      '// 8 Key 
                               IF Row_C = 0 THEN
                                  IF Allow_Key = 0 THEN 
                                     Key_Press = 8                 
                                     Allow_Key = 1
                                  ENDIF   
                               ENDIF
    
       Scan_Col = 0   
       END SELECT
       
       '// Ouput key 
       IF Key_Down <> Key_Press THEN                    ' Key already been sent? 
          IF Key_Press <> 255 THEN                      ' 255 denotes no key press
             IF Key_Press = 42 OR Key_Press = 35 THEN   ' Numerical key?
           
             '// Brief chrip of the piezo & flash of the LED
             for i = 0 to 20
                 toggle buzzer
                 pause 5
             next
          gosub result_key    
          ENDIF
          Key_Down = Key_Press                          ' Copy of key just sent 
          Buzzer = 0                                    ' Make sure LED is off
       ENDIF
       endif
       '// Check for key release, all cols on (active low) ...
       Col_A = 0     
       Col_B = 0     
    
       '// Reset flags allowing other keys to be processed if no keys are depressed
       IF Row_A = 1 THEN
          IF Row_B = 1 THEN
             IF Row_C = 1 THEN
                   Allow_Key = 0
                   Key_Down = 0
                   Key_Press = 255
             ENDIF
          ENDIF
       ENDIF
                   
       GOTO Scan_Keypad                                 ' Loop back                   
    
       Result_key :
       SELECT CASE key_press
       case 3
       high buzzer
       pause 1000
       low buzzer
       case 6
       high buzzer
       pause 2000
       low buzzer
       case 9
       high buzzer
       pause 3000
       low buzzer
       end select
       return
    Attached Images Attached Images

Similar Threads

  1. 4x4 keypad Help
    By aaliyah1 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 5th October 2010, 16:34
  2. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  3. Keypad input test
    By Kalind in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th October 2008, 04:00
  4. Need help in matrix keypad coding
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th May 2008, 13:16
  5. novice need help for a security keypad
    By davleo in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 17th November 2003, 21:54

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