Haber señor creo que usted no me entendió esta es una rutina para escanear una matriz de teclas solo abría que reemplazar por las instrucciones 12c espero que así se entienda mejor
' Program KEYPAD16.BAS
' *************************************************************
' * For use with EXPERIMENTING WITH THE PICBASIC PRO COMPILER *
' * *
' * This source code may be freely used within your own *
' * programs. However, if it is used for profitable reasons, *
' * please give credit where credit is due. *
' * And make a reference to myself or Rosetta Technologies *
' * *
' * Les. Johnson *
' *************************************************************
'
' Scan a 16-button keypad using the first four bits of PortA and PortB
' This is the same routine as ASM_KEY, but written in basic.
Include "Modedefs.Bas"
' ** Setup the Crystal Frequency, in MJz **
Define OSC 4 ' Set Xtal Frequency
' ** Setup the Debug Defines **
Define DEBUG_REG PORTB ' Debug PortB
Define DEBUG_BIT 7 ' *** Debug pin Bit-7 ***
Define DEBUG_BAUD 9600 ' *** Debug Baud Rate ***
Define DEBUG_MODE 1 ' Set Serial Mode 1=Inverted
Define DEBUG_PACING 300 ' Delay 'in Us' between characters sent
' ** Define LCD Control Constants **
I Con 254 ' Control Byte
Clr Con 1 ' Clear the display
Line1 Con 128 ' Point to beginning of line 1
Line2 Con 192 ' Point to beginning of line 2
Line3 Con 148 ' Point to beginning of line 3
Line4 Con 212 ' Point to beginning of line 4
Cgram Con 64 ' Point to Cgram within LCD
' ** Declare the Variables **
K_Flag Var Bit
Key Var Byte
Debounce Var Bit ' Flag to indicate a keypress.
D_Flag Var Bit ' Debounce flag used by Inkeys.
Debug I,Clr:Pause 30 ' Clear the LCD
Inc_D_Flag=0 ' Reset the debounce flag, prior to calling the subroutine
Main:
GoSub Keyscan
Debug I,Line1,#Key," "
GoTo Main
' This subroutine Scans the 16 button keypad and returns the key pressed in "KEY"
' If no key is pressed the value returned is 128.
' It also returns a Bit-Flag called DEBOUNCE which is 1 if a key is still in use
' And 0 if not. This acts as a debounce for the Keypad.
Keyscan:
Debounce=1 ' Setup the initial value for Debounce
Key=0 ' Clear the variable KEY, prior to scanning
TRISA.0=0:TRISA.1=0 ' Make the first four bits of PortA Outputs
TRISA.2=0:TRISA.3=0
TRISB.0=1:TRISB.1=1 ' Make the first four bits of PortB inputs
TRISB.2=1:TRISB.3=1
OPTION_REG.7=0 ' Enable Internal PortB Pullup Resistors
PORTA=%0111 ' Pull the fourth row line LOW
GoSub Scancol ' Scan the columns
If K_Flag=1 Then GoTo Map ' If a key is pressed then map it
PORTA=%1011 ' Pull the third row line LOW
GoSub Scancol ' Scan the columns
If K_Flag=1 Then GoTo Map ' If a key is pressed then map it
PORTA=%1101 ' Pull the second row line LOW
GoSub Scancol ' Scan the columns
If K_Flag=1 Then GoTo Map ' If a key is pressed then map it
PORTA=%1110 ' Pull the first row line LOW
GoSub Scancol ' Scan the columns
If K_Flag=1 Then GoTo Map ' If a key is pressed then map it
D_Flag=0 ' No key pressed, so Reset debounce flag
Debounce=0 ' No key pressed, so Reset key Debounce flag
GoTo Exit ' Exit from the subroutine
' Do the following code if a key has been pressed
Map: If D_Flag=1 Then Exit ' Already responded to this press, so exit
D_Flag=1 ' Set Debounce flag
Debounce=0 ' Reset key Debounce flag
Exit: LookUp Key,[15,7,4,1,0,8,5,2,14,9,6,3,13,12,11,10,128],Key ' Map of the keypad legends
Return ' Exit from the subroutine
' This subroutine scans the columns
' The bit, K_Flag returns a 1 if a key is pressed, and 0 if no key pressed
' Also, if no key is pressed the variable KEY will return with the value of 16
Scancol:
K_Flag=1 ' Set K_Flag initially to 1
If PORTB.0=0 Then S_Exit ' Return if a key on the first column is pressed
Key=Key+1 ' Else increment KEY, and try another row
If PORTB.1=0 Then S_Exit ' Return if a key on the second column is pressed
Key=Key+1 ' Else increment KEY, and try another row
If PORTB.2=0 Then S_Exit ' Return if a key on the third column is pressed
Key=Key+1 ' Else increment KEY, and try another row
If PORTB.3=0 Then S_Exit ' Return if a key on the fourth column is pressed
Key=Key+1 ' Else increment KEY, KEY now equals 16
K_Flag=0 ' Set the K_Flag to indicate no key pressed
S_Exit: Return ' And exit the subroutine