$regfile = "2313def.dat" $crystal = 4000000 $baud = 9600 Const Debouncetime = 150 Config Pind.6 = Output Config Pind.2 = Input Config Int0 = Falling Dim Wtime As Byte Dim Keycoderow As Byte Dim Keycodecol As Byte Dim Keycode As Byte Dim Keychar As String * 1 On Int0 Button 'set upper nibble of portb to output, lower to input Ddrb = &B11110000 Portb = &B00001111 Wtime = 255 Print "ready..." Enable Interrupts Enable Int0 Do Set Portd.6 Waitms Wtime Reset Portd.6 Waitms Wtime Loop Button: Waitms Debouncetime 'read portb pins to determine which row is zero Keycoderow = Pinb 'set portb upper nibble to input, lower to output Ddrb = &B00001111 Portb = &B11110000 'give port time to settle Waitms 1 'read portb pins to determine which col is zero Keycodecol = Pinb 'set portb back to original state Ddrb = &B11110000 Portb = &B00001111 'make keycode from portb pins read Select Case Keycoderow Case 7 : Keycode = 12 Case 11 : Keycode = 8 Case 13 : Keycode = 4 Case 14 : Keycode = 0 Case Else : Keycode = 99 End Select 'shift upper nibble to lower nibble Shift Keycodecol , Right , 4 'make final keycode from portb pins read Select Case Keycodecol Case 7 : Keycode = Keycode + 3 Case 11 : Keycode = Keycode + 2 Case 13 : Keycode = Keycode + 1 Case 14 : Keycode = Keycode + 0 Case Else : Keycode = Keycode + 99 End Select 'illegal keycode from bounce effects If Keycode > 15 Then Keycode = 16 Print Keycoderow ; " " ; Keycodecol ; " " ; Keycode Keychar = Lookupstr(keycode , Keycodes) Print Keychar Gifr = 64 Return End Keycodes: Data "1" , "2" , "3" , "A" , "4" , "5" , "6" , "B" , Data "7" , "8" , "9" , "C" , "R" , "0" , "E" , "D" , "?"