开发者

4x4 switch panel detection

I am programming PIC16f877 in MPLAB (using assembly). I have 4x4 switch panel. I can take inputs but I ca开发者_开发技巧nnot detect from which one of the switches it come. I am using portb, making first RB4 to RB7 input and RB0 to RB3 output, but for example SW0, SW4, SW8, SW12 are functioning same? How can I strictly determine them??

Here is related parts of my code

...
bsf TRISB,5
bcf TRISB,2
bcf STATUS,RP0

bsf STATUS,RP0
bcf OPTION_REG,7
bcf STATUS,RP0

...

btfs PORTB,5
call button1

goto    main

button1:
movlw   b'11111111'
movwf   PORTD
clrf    PORTE
bsf PORTE,2
call    delay

    return


Drive one column at a time, scan the rows, then drive the next column. Sounds like you are driving multiple columns at the same time so can't tell which switch it is because the same row goes active. There is some sample code here but you'd need to convert it to assembly. Alternative a good Microchip app note (AN1081) describes the problem and solution, which you can learn from even if your hardware is different.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜