PIC单片机:仅使用C中的端口C RC0-RC3扫描4x4键盘上的输入 [英] PIC Microcontrollers: Scan inputs on a 4x4 Keypad, using only Port C RC0-RC3 in C

查看:217
本文介绍了PIC单片机:仅使用C中的端口C RC0-RC3扫描4x4键盘上的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PIC微控制器&的新手. C语言编程,我的任务是创建自己的键盘扫描方法,该方法专用于端口C(16F877A微控制器).具体来说,使用此方法的程序仅使用数字1、2、4和5,因此为了高效,扫描仪方法仅将RC0,RC1,RC2和RC3用作指定的输入/输出(不允许使用使用RC4-RC7).这实际上将4x4键盘变成了2x2键盘.

I'm new to PIC Microcontrollers & C programming and I've been set the task of creating my own Keypad scanning method that works exclusively on Port C (16F877A Microcontroller). Specifically, the program that uses this method only uses digits 1, 2, 4 and 5- so to be efficient, the scanner method is to only use RC0, RC1, RC2 and RC3 as the designated input/ outputs (I'm not allowed to use RC4-RC7). This essentially turns the 4x4 keypad into a 2x2 keypad.

我了解扫描的概念是将端口行设置为高行,并将行设置为输入列-当按下按钮时,这将读取端口的低半字节以检测按钮.

I understand that the concept on scanning has Port lines set to high on rows, and lines set as input columns- when a button is pressed, this reads the low nibble of the port to detect the button.

不幸的是,我不知道如何用C语言编写代码,尤其是使用上面指定的Port行.任何人都可以阐明这个问题,并指出正确的方向吗? 谢谢!

Unfortunately, I have no idea how to code this in C, especially using the Port lines specified above. Can anybody shed some light on the problem and point me in the right direction? Thanks!

推荐答案

一种可能的方法:

硬件:

  1. 将RC0连接到第0行
  2. 将RC1连接到第1行
  3. 将RC2连接到第0列
  4. 将RC3连接到第1列

软件:

设置:

  1. 将RC0和RC1配置为输出
  2. 将RC2和RC3配置为输入

阅读:

  1. 将RC0设置为高,RC1设置为低
  2. 阅读RC2.如果为高,则按下1
  3. 阅读RC3.如果为高,则按下2
  4. 将RC0设置为低电平,将RC1设置为高
  5. 阅读RC2.如果高,则按下4
  6. 阅读RC3.如果高,则按下5
  1. Set RC0 high, RC1 low
  2. Read RC2. If high, 1 is being pressed
  3. Read RC3. If high, 2 is being pressed
  4. Set RC0 low, RC1 high
  5. Read RC2. If high, 4 is being pressed
  6. Read RC3. If high, 5 is being pressed

作为练习,留给读者适当的上拉/下拉动作和反跳动作.

Adding appropriate pull-ups/pull-downs and debouncing is left as an exercise to the reader.

这篇关于PIC单片机:仅使用C中的端口C RC0-RC3扫描4x4键盘上的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆