Device = 18F452
Clock = 20
#option LCD_DATA = PORTC.4
#option LCD_RS = PORTC.2
#option LCD_EN = PORTC.3
#option KEYPAD_PORT = PORTD
Include "keypad.bas"
Include "convert.bas"
Include "LCD.bas"
Function Convert_Key() As Byte // Function to convert the key pressed to the
// actual number (* = 10 # = 11)
Select Keypad.Value
Case 5
Result = 4
Case 6
Result = 5
Case 7
Result = 6
Case 9
Result = 7
Case 10
Result = 8
Case 11
Result = 9
Case 13
Result = 10
Case 14
Result = 0
Case 15
Result = 11
Else
Result = Keypad.Value
EndSelect
End Function
Sub Debounce()
DelayMS(10) // Simple debounce routine
While Keypad.Value <> 0 // Wait for key to be depressed
Wend //
End Sub
// Start Of Program...
DelayMS(150) // Allow LCD to warmup
Cls // and clear the screen
WriteAt(1,1,"Press any key...") // Send some text to the LCD
Main: // Main program start
While Keypad.Value = 0 // Loop until a key is pressed
Wend
WriteAt(2,1, DecToStr(Convert_Key,2)) // Convert the Key to a string and display it
Debounce // Call the debounce routine
GoTo Main // Loop forever