Hi Couldn't find a decent schematic for a matrix keyboard, so I invented my own. I soldered the pull-up resistors on the board before coding, so that's why the negative logic. With pull down resistors you can have positive logic. I should be a function too, but I'm from the FORTRAN dark ages with huge "common blocks". Anyway, here it is: -- -- file : keyb.jal -- author : Eur van Andel, eur@fiwihex.nl -- date : 24-01-2002 -- purpose : matrix keyboard routine -- requires : - -- -- Matrix keyboard connections -- -- 1 2 3 --- D0 row lines connected to D0...D3 PIC pins -- 4 5 6 --- D1 -- 7 8 9 --- D2 -- * 0 # --- D3 -- -- | | | -- D4 D5 D6 column lines connected to D4..D6 PIC pins -- | | | -- / / / 10k pullup resistors -- \ \ \ -- | | | -- |__|__|___ +5V -- -- -- keyb.jal gives you a global byte variable called key that -- will take the value of the key you press, *=10, #=11 -- feel free to modify procedure keyboard to a function -- -- -- Blah, GNU, blah -- var bit R1 is pin_d0 -- row wires are outputs var bit R2 is pin_d1 var bit R3 is pin_d2 var bit R4 is pin_d3 var bit C1 is pin_d4 -- column wires are inputs, pulled-up with 10K var bit C2 is pin_d5 var bit C3 is pin_d6 pin_d0_direction = output pin_d1_direction = output pin_d2_direction = output pin_d3_direction = output pin_d4_direction = input pin_d5_direction = input pin_d6_direction = input var byte key procedure keyboard is port_d_low = 0b1110 -- 123 row low if ! C1 then key = 1 end if if ! C2 then key = 2 end if if ! C3 then key = 3 end if port_d_low = 0b1101 -- 456 row low if ! C1 then key = 4 end if if ! C2 then key = 5 end if if ! C3 then key = 6 end if port_d_low = 0b1011 -- 789 row low if ! C1 then key = 7 end if if ! C2 then key = 8 end if if ! C3 then key = 9 end if port_d_low = 0b0111 -- *0# row low if ! C1 then key = 10 end if if ! C2 then key = 0 end if if ! C3 then key = 11 end if end procedure -- Ir. E.E. van Andel, Fine Wire Heat Exchanger Technology www.fiwihex.com Wierdensestraat 74, NL-7604 BK Almelo, The Netherlands eur@fiwihex.nl phone +31-546-491106 fax +31-546-491107 mobile +31-653-286573 -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.