4x4 开关面板检测
我正在 MPLAB 中对 PIC16f877 进行编程(使用汇编)。我有 4x4 开关面板。我可以接受输入,但无法检测到它来自哪一个开关。 我正在使用 portb,使第一个 RB4 到 RB7 输入和 RB0 到 RB3 输出,但例如 SW0、SW4、SW8、SW12 的功能相同吗?我怎样才能严格确定它们?
这是我的代码的相关部分
...
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
I am programming PIC16f877 in MPLAB (using assembly). I have 4x4 switch panel. I can take inputs but I cannot 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一次驱动一列,扫描行,然后驱动下一列。听起来好像您同时驱动多个列,因此无法分辨是哪个开关,因为同一行处于活动状态。这里有一些示例代码,但您需要转换将其组装。另一种优秀的 Microchip 应用笔记 (AN1081) 描述了问题和解决方案,即使您的硬件不同,您也可以从中学习。
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.