The 4X4 keyboard corresponds to 16 numbers from 0 to F. Pressing any key will display the corresponding number on the common anode seven-segment display.
Circuit Description:
Circuit
Port B of the HT46F49E is connected to a common anode seven segment display.
Since a common anode seven-segment digital display is used, a resistor is connected in series to each pin of port B for voltage division. Because each segment of the seven-segment display can be regarded as a light-emitting diode, VCC is enough to burn out the segment, so a resistor should be connected in series to each segment to divide the voltage with the light-emitting diode to protect the seven-segment display.
Port A of the HT46F49E is connected to a 4X4 keyboard. PA7-PA0 sends out a row scan code, one of the pins sends out 0, the rest send out 1, and PA7-PA4 send out 0 in turn. If a key is pressed, PA3-PA0 will receive the information of which key is pressed. Combining the row scan code of PA7-PA4 and the information of the key pressed by PA3-PA0 can determine which key is pressed.
Complete program code download address: http://www.51hei.com/f/htjp.rar
program:
#include "HT46F49E.H" const unsigned char number[]={ 0x81,0xcf,0x92,0x86, 0xcc,0xa4,0xa0,0x8f, 0x80,0x84,0x88,0xe0, 0xb1,0xc2,0xb0,0xb8}; unsigned int key_code; void scan_keypressed() { unsigned int i,scan_code; scan_code=0xef; key_code=0; for(i=0;i<4;i++) { _pa=scan_code; if(_pa0==0) key_code=i*4+1; if(_pa1==0) key_code=i*4+2; if(_pa2==0) key_code=i*4+3; if(_pa3==0) key_code=i*4+4; _rl(&scan_code); } } void scan_keyeleased() { switch(key_code%4) { case 1:while(!_pa0); break; case 2:while(!_pa1); break; case 3:while(!_pa2); break; case 0:while(!_pa3); break; } } void main() { unsigned int key_old,led; _pcc=0x00; _pbc=0x00; _pac=0x0f; led=0; _pb=number[0]; while(1) { scan_keypressed(); if(key_code>0) { key_old=key_code; _delay(20000); scan_keypressed(); if(key_old==key_code) { scan_keyeleased(); led=key_code-1; _pb=number[led]; } } } }
Previous article:HOLTEK MCU-Stopwatch
Next article:HOLTEK MCU-8LED Thunderbolt Light
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Configuration issues of SEED-XDS510PLUS in CCS5.5.0
- STM32F4 hardware I2C driver 0.96 OLED screen
- Analog electronics course selection test + isolation course learning
- Why can't my INT function enter the interrupt?
- [RT-Thread Reading Notes] Part 2 (3) Semaphores and Mutexes
- What software do I use for schematic illustrations?
- Problems encountered in debugging B-U585I-IOT02A WIFI module
- 2021 National Undergraduate Electronic Design Competition Restart Notice and Schedule
- MicroPython 1.18 released
- Last day: Let's play together, AI development board based on Allwinner R329 chip