3. KEY lighting
The register definition of the KEY pin is the same as that of the LED, which is still 3 registers: DDRx, PORTx, and PINx (for details, please refer to the LED lighting section).
DDRx: 1-output, 0-input. When configured as input, PORTx=1, pull-up enabled, PORTx=0, high configuration, but pay attention to the third pin of SDIOR, which is used to disable pull-up, so pay attention when configuring pull-up, otherwise it will be high configuration.
Figure 2-2 SFIOR register diagram
Code Explanation:
ØDefine the corresponding bits of the 3 button pin registers. Again, use the underscore to get the bit position of the register.
ØButton initialization, while allowing pull-up
ØUse the key scanning program to detect whether the three keys are triggered. If yes, return the corresponding key value, otherwise return 0. Here, the key variable is used to determine whether the key is triggered, and the detection effect is better.
For other instructions, please refer to the original project. It also uses object-oriented structure function thinking for programming, improves the C language level, and keeps pace with the times.
Simulation video
/**
******************************************************************************
* @file main.c
* @author Alex——Xiaobai
* @version V1.0
* @date 2021.1.20
* @brief LED lighting
* @store Proteus simulation store
* @Link https://shop484534014.taobao.com/
* @Email 844545015@qq.com
******************************************************************************
* @attention All Rights Reserved
**/
#include void main(void) { LED.LED_Init(0xFF); //LED ALL OUTPUT KEY.KEY_Init(); //KEY 0/1/2 INPUT while(1) { switch(KEY.KEY_Scan()) { case 1: LED.LED_Reverse(0); //LED0 flip break; case 2: LED.LED_Reverse(1); //LED1 flip break; case 3: LED.LED_Reverse(2); //LED2 flip break; default: break; } } } /******************************************************** End Of File ************************************************************/
Previous article:ATmega16 Development Board Tutorial (3) - 74HC595 driving digital tube display
Next article:ATmega16 Development Board Tutorial (1) - LED Lighting
Recommended ReadingLatest update time:2024-11-16 16:43
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Award-winning live broadcast: Application of TI millimeter-wave radar in cars is now open for registration~
- Modelsim10.4 installation and adding crack files error solution
- TI - MCU - MSP430 User Guide 1 -> MSP430 Introduction and Selection Guide
- [BearPi-HM Nano, play Hongmeng "Touch and Go"] -1- Unboxing and preliminary data collection
- Adding your own C functions to MicroPython
- PCB production
- Sharing 10 common formulas for switching power supply design
- Battery Management System BMS Technical Data Transfer
- [Raspberry Pi Pico Review] LCD1602 4-bit mode display driver
- There are 10 digital tubes on a digital tube display board, which uses 1 74HC00D, 2 74HC04D and 10 74HC164D