Module Keypad12rev
{
Column1 = PORTX.0
Column2 = PORTX.1
Column3 = PORTX.2
PORTX.3 NC
Row1 = PORTX.4
Row2 = PORTX.5
Row3 = PORTX.6
Row4 = PORTX.7
}
// validate data port...
#option KEYPAD_PORT = PORTc //port B for pullups
#if IsOption(KEYPAD_PORT)
#if Not IsValidPort(KEYPAD_PORT)
#error KEYPAD_PORT, "Invalid option. Keypad must be connected to a valid port name."
#endif
#option _KEYPAD_PORT_TRIS = GetTRIS(KEYPAD_PORT)
#endif
// bring PORT and TRIS options into the module
Dim
FKeyPort As KEYPAD_PORT,
FKeyPortTris As _KEYPAD_PORT_TRIS
Public Function Value() As Byte
Dim Counter As Byte
Dim RowData As Byte
Dim ColData As Byte
Result = 0
Counter = 0
For Counter = 0 To 2 //
FKeyPortTris = $FF // Make all pins inputs
FKeyPortTris.Bits(Counter) = 0 // Make a single Column an output
FKeyPort.Bits(Counter) = 1 // and set it high
If (FKeyPort >> 4) <> 0 Then // Check if any Rows are "High"
rowdata = Counter
If FKeyPort.4 = 1 Then
colData = 1
ElseIf FKeyPort.5 = 1 Then
colData = 4
ElseIf FKeyPort.6 = 1 Then
colData = 7
ElseIf FKeyPort.7 = 1 Then
colData = 10
EndIf
Result = Coldata + rowData
Break
EndIf
Next
End Function
Public Sub Debounce()
While Keypad12rev.Value <> 0 // Check if key is pressed
DelayMS(10) // Wait for 10mS
Wend
End Sub
FKeyPortTris = $FF // Make all pins inputs
End