Hi guys have been looking at connecting a 4 x4 matrix keyboard via 1 adc pin on a pic , ( yes i do like to not waist pins if i can help it ) found this around the internet as some one has done it in basic .
It was noted that the on resistance of each key needed be consistent even over time to ensure this to work correctly.
My question is ,
1. has anyone tried this at all , and how would membrane keys pad go with consistency using ACD.
2. has anyone tried using self learn routine on a ACD input such that a keyboard "on" resistance changes over time that it can adjust without input from the user to accommodate for change over time - may be a hard ask of a routine ?
Code:; One keypad (3x4) to one ADC pin, all Atoms ; 28 January 2010 By Ken Jennejohn ; Wiring: check wiring diagram supplied with post (this is now a 3x4 keypad!) ;****** Variable Assignments ******* kpad_in var word old_kpad_in var word old_kpad_in = 0 key var byte old_key var byte result var word result = 0 looper var byte ; for loops less than 256 bigloop var byte pause 1000 ; Needed for PIC to initialize internally serout s_out, i19200,[0, 7] ; clear the screen, sound terminal "bell" MAIN ; Initialize main variables key = "X" result = 0 kpad_in = 0 old_kpad_in = 0 ;Is a key pressed (ADC reading less than 900)? If not, go back to MAIN. ADIN P6, kpad_in IF kpad_in > 900 then MAIN ; Falls thru when key pressed... ; These two loops look for a legit key press, and determine which one. pause 50 ; This allows keypad switch to finish "bounce" FOR bigloop = 1 to 3 ; has to ID same key three times to pass FOR looper = 1 to 10 ; read keypad input 10 times ADIN P6, kpad_in ; keypad switch "bounce" handled next ; Uncomment the next line for troubleshooting ;serout s_out, i19200, [dec (ABS(old_kpad_in - kpad_in)), 13] ; The difference between this key press and the last must be ; less than ten. We use the ABS(olute) modifier to keep results ; positive and avoid negative results. Greater than 10, do it over. IF ABS (old_kpad_in - kpad_in) > 10 then old_kpad_in = 0 looper = 0 result = 0 ENDIF result = result + kpad_in old_kpad_in = kpad_in next ; looper ; get average of readings result = result / 10 ; This next output routine is available for troubleshooting, just uncomment it. ;serout s_out, i19200, ["result: ", dec result,13] ; We next do a gosub to routine that determines which key has been pressed gosub Key_Is_ ; Upon returning, we determine if the key was properly determined IF key = "X" then MAIN ; If key still "X" we failed ; If passed, we save it to check later. Must pass this three times to accept key press value. IF key <> old_key then bigloop = 0 ; If comparison fails, restart bigloop ENDIF old_key = key ; it's OK, save latest key value next ; bigloop ; If key press looks good after three tries we report it here and sound terminal "bell". Report_ serout s_out, i19200, | ; We use pipe symbol (the "|") to continue to the next line [key, 7] ; clear screen, home cursor first ; We wait here for key release stay_here_ ADIN P6, kpad_in IF kpad_in < 900 then stay_here_ ; And then we do it all over again. GOTO MAIN ;****** SubRoutine(s) ****** Key_Is_ ; Uncomment the next line for troubleshooting ;serout s_out, i19200, ["key_is_ result val: ", dec result, 13] IF result > 592 AND result < 602 then key = "1" ENDIF IF result > 615 AND result < 625 then key = "2" ENDIF IF result > 640 AND result < 650 then key = "3" ENDIF IF result > 425 AND result < 435 then key = "4" ENDIF IF result > 465 AND result < 475 then key = "5" ENDIF IF result > 502 AND result < 512 then key = "6" ENDIF IF result > 695 AND result < 705 then key = "7" ENDIF IF result > 710 AND result < 720 then key = "8" ENDIF IF result > 725 AND result < 735 then key = "9" ENDIF IF result > 778 AND result < 782 then key = "0" ENDIF IF result > 0 AND result < 0 then key = "A" ENDIF IF result > 0 AND result < 0 then key = "B" ENDIF IF result > 0 AND result < 0 then key = "C" ENDIF IF result > 0 AND result < 0 then key = "D" ENDIF IF result > 768 AND result < 772 then key = "*" ENDIF IF result > 790 AND result < 801 then key = "#" ENDIF return _________________ kenjj http://blog.basicmicro.com/ http://kjennejohn.wordpress.com/




Bookmarks