PIC SINGLE-CHIP KEYSTROKE TEST
2016-08-23
0 0 0
no vote
Other
Earn points
Including simulation circuit and C program, refer to "PIC MCU introduction and actual combat". Key detection principle: the top 4 bits of the portb are set to input mode, and the internal pull-up function is turned on. In this way, the top 4 bits of the portb are all 1, that is, the column lines of the keys are all 1, while the bottom 4 bits of the portb are all 0, that is, the row lines of the keys are all 0. If a key is pressed, the row line and column line will be connected, and the voltage of the column line where the key is located will be lowered to 0. At this time, when reading portb, the lower four bits are still 0, but one of the higher four bits is also 0. Therefore, if ((portb & amp; 0xf0)! = 0xf0) can judge whether the key is pressed, because if it is pressed, the upper four digits are not all 1. Key scanning, the lower 4 bits output 0 in turn, and the other 3 bits of the lower 4 bits output 1. Then, when the row line of output 0 touches the column line pressed by the key, the voltage of the column line will be pulled down. At this time, read the portb, and you will get the row and column position of the key, that is, the key code. If the row line of output 0 is not connected with the column line of the key, then all the upper 4 bits are still 1. Just keep scanning. In the keycode [] array, the key codes of the last few times are stored, and the most recent 8 times can be stored. You can change the storage size by changing the array. If you connect several digital tubes, you can display the contents of the keys in turn, just like a calculator
c
Related Source Codes
PClite
0
0
no vote
generic embeded FTP Client
0
0
no vote
UDP Test Demo
0
0
no vote
TMS320F28335 DSP transmits data to EEPROM through
0
0
no vote
TMS320F28335 CAN communication source code
0
0
no vote
No comment