Cmn=Am2/Pn=M!/(n!(m-n)!)=Cm(m-n) 由于是键盘操作,故取n=2,m>=2
m=2时. C22=2!/2!/0!=1 即最小组合键需要2个IO.即2线1键 设2个IO为Pin0,Pin1. 组合扫描为Key1=Pin0,Pin1
m=3时. C32=3!/2!/1!=3 即3线3键. 设3个IO为Pin0,Pin1,Pin2. 组合扫描为Key1=Pin0,Pin1 Key2=Pin0,Pin2 Key3=Pin1,Pin2
m=4时. C42=4!/2!/2!=4*3/2=6 即4线6键. 设4个IO为Pin0,Pin1,Pin2,Pin3. 组合扫描为Key1=Pin0,Pin1 Key2=Pin0,Pin2 Key3=Pin0,Pin3 Key4=Pin1,Pin2 Key5=Pin1,Pin3 Key6=Pin2,Pin3
m=5时. C52=5!/2!/3!=5*4*3/6=10 即5线10键. 设5个IO为Pin0,Pin1,Pin2,Pin3,Pin4. 组合扫描为Key1=Pin0,Pin1 Key2=Pin0,Pin2 Key3=Pin0,Pin3 Key4=Pin0,Pin4 Key5=Pin1,Pin2 Key6=Pin1,Pin3 Key7=Pin1,Pin4 Key8=Pin2,Pin3 Key9=Pin2,Pin4 Key10=Pin3,Pin4
m=6时. C62=6!/2!/4!=6*5*4!/2/4!=15 即6线15键. 设6个IO为Pin0,Pin1,Pin2,Pin3,Pin4,Pin5. 组合扫描为Key1=Pin0,Pin1 Key2=Pin0,Pin2 Key3=Pin0,Pin3 Key4=Pin0,Pin4 Key5=Pin0,Pin5 Key6=Pin1,Pin2 Key7=Pin1,Pin3 Key8=Pin1,Pin4 Key9=Pin1,Pin5 Key10=Pin2,Pin3 Key11=Pin2,Pin4 Key12=Pin2,Pin5 Key13=Pin3,Pin4 Key14=Pin3,Pin5 Key15=Pin4,Pin5
m=7时. C72=7!/2!/5!=7*6*5!/2/5!=21 即7线21键. 设7个IO为Pin0,Pin1,Pin2,Pin3,Pin4,Pin5,Pin6. 组合扫描为Key1=Pin0,Pin1 Key2=Pin0,Pin2 Key3=Pin0,Pin3 Key4=Pin0,Pin4 Key5=Pin0,Pin5 Key6=Pin0,Pin6 Key7=Pin1,Pin2 Key8=Pin1,Pin3 Key9=Pin1,Pin4 Key10=Pin1,Pin5 Key11=Pin1,Pin6 Key12=Pin2,Pin3 Key13=Pin2,Pin4 Key14=Pin2,Pin5 Key15=Pin2,Pin6 Key16=Pin3,Pin4 Key17=Pin3,Pin5 Key18=Pin3,Pin6 Key19=Pin4,Pin5 Key20=Pin4,Pin6 Key21=Pin5,Pin6
m=8时. C82=8!/2!/6!=8*7*6!/2/6!=28 即8线28键. 设8个IO为Pin0,Pin1,Pin2,Pin3,Pin4,Pin5,Pin6,Pin7. 组合扫描为Key1=Pin0,Pin1 Key2=Pin0,Pin2 Key3=Pin0,Pin3 Key4=Pin0,Pin4 Key5=Pin0,Pin5 Key6=Pin0,Pin6 Key7=Pin0,Pin7 Key8=Pin1,Pin2 Key9=Pin1,Pin3 Key10=Pin1,Pin4 Key11=Pin1,Pin5 Key12=Pin1,Pin6 Key13=Pin1,Pin7 Key14=Pin2,Pin3 Key15=Pin2,Pin4 Key16=Pin2,Pin5 Key17=Pin2,Pin6 Key18=Pin2,Pin7 Key19=Pin3,Pin4 Key20=Pin3,Pin5 Key21=Pin3,Pin6 Key22=Pin3,Pin7 Key23=Pin4,Pin5 Key24=Pin4,Pin6 Key25=Pin4,Pin7 Key26=Pin5,Pin6 Key27=Pin5,Pin7 Key28=Pin6,Pin7
如果加"独占键"即8个IO的接地键,那么8个IO不加如何器件的键盘个数为28+8=36个.
"组合键"的程序很好编写,可能比行扫描更好编~~~不要被它吓到,问问数学家~~~
祥见菜农的"键盘论"~~~ 相关链接:http://www.**/blog/hotpower/11888/message.aspx |