Function: Digital tube display 4X4 keyboard matrix keys PROTEUS and 51 single chip microcomputer tutorial
The program source code is as follows:
/*
Digital tube display 4X4 keyboard matrix buttons
*/
#include typedef unsigned char uint8; typedef unsigned int uint16; #define BUZZER() P3 ^= 0x01 code uint8 LED_CODE[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07, 0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71}; void delay(uint16 x) { uint16 i,j; for(i = x; i > 0; i --) for(j = 114; j > 0; j --); } uint8 Pre_KeyNO = 16,KeyNO = 16; void Keys_Scan() { uint8 Tmp; P1 = 0x0f; delay(1); Tmp = P1 ^ 0x0f; //High 4 bits output, low 4 bits input switch(Tmp) { case 1: KeyNO = 0; break; case 2: KeyNO = 1; break; case 4: KeyNO = 2; break; case 8: KeyNO = 3; break; default: KeyNO = 16; } P1 = 0xf0; delay(1); Tmp = P1 >> 4 ^ 0x0f; // High 4 bits input, low 4 bits output switch(Tmp) { case 1: KeyNO += 0; break; case 2: KeyNO += 4; break; case 4: KeyNO += 8; break; case 8: KeyNO += 12; } } void Beep() { uint8 i; for(i=0;i<100;i++) { delay(1);BUZZER(); } } void main() { P0 = 0x00; while(1) { P1 = 0xf0; if(P1 != 0xf0) Keys_Scan(); if(Pre_KeyNO != KeyNO) { P0 = LED_CODE[KeyNO]; Beep(); Pre_KeyNO = KeyNO; } delay(10); } }
Previous article:A single button controls a single digital tube to scroll display
Next article:Microcontroller controls buzzer to sing Happy Birthday song
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Is this dime-sized millimeter-wave sensor evaluation board worth trying?
- Questions about TPS65090 power management chip selection
- VK1621B/VK1622 is a perfect replacement for HT1621B/HT1622, and is compatible with all packaged chips, die, wafers, bonding COB chips, etc.
- Xintang M2354 Fault Injection Attack Protection
- Date in spring - go to the beach and relax
- Some experience accumulated when debugging a system using Keil C
- Power amplifier driving capacitive load case sharing
- Power supply zero and live wire detection
- RSL1 Bluetooth characteristic value reading and writing
- Sapphire on PCB---DFM about optical positioning points