Now try controlling an LED with a button... make the LED light up when a button is pressed and turn off when it is released.
The main purpose is to learn GPIO input and interrupt.
1. Circuit
J39-n in the picture are several jumper sockets, located near the LCD of the development board. Make sure the jumpers are connected before proceeding.
It can be seen that when the button is pressed, the pin is grounded. That is, if the pin is connected to a pull-up resistor, the pin is in a high level state when the button is popped up, and in a low level state when the button is pressed.
The button used this time is BP3, which is the PA20 pin; the LED is a blue LED, which is PA0.
When the additional interrupt control is not enabled, the interrupt will be triggered on both edges.
7. Interrupt Service Function
There are several registers:
PIO_ELSR——Used to indicate whether the interrupt is triggered by level or edge
PIO_FRLHSR——Used to indicate whether the interrupt is triggered by a falling edge or a low level, or a rising edge or a high level
Unfortunately, these registers have no effect when no additional interrupt control modes are used.
However, you can directly determine the pin level by reading the PIO_PDSR register. Note that when using this register, you need to turn on the clock of the PIO controller first.
The code logic is relatively simple:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #define LED_PIO PIO_PA0 void PIOA_Handler() { /* Get the interrupt status and pull the interrupt low*/ uint32_t status = PIOA->PIO_ISR; /* First determine whether the interrupt is triggered by the button pin*/ if ((status & BUTTON_PIO) != 0) { if (PIOA->PIO_PDSR & BUTTON_PIO) { /* High level, button pops up*/ PIOA->PIO_SODR = LED_PIO; } else { /* Low level, button pressed*/ PIOA->PIO_CODR = LED_PIO; } } } |
Previous article:SAM4E MCU Tour - 7. TC Interrupt of LED Flashing
Next article:SAM4E MCU Tour - 5. LED Breathing and PWM
Recommended ReadingLatest update time:2024-11-16 13:06
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
- C6000 DSP code online compilation problem
- Research on the information performance advantages of Suruide in-vehicle Ethernet hardware and applications
- [Synopsys IP Resources] Prototyping as a Service (PaaS): Breaking through chip design process bottlenecks and simplifying the path to innovation
- How to write the test bench file for the verliog10 divider
- [Xianji HPM6750 Review] + Environment Setup Test
- EEWORLD University ---- Webinar: Thermal Monitoring and Protection
- How to solve the power supply ripple
- 【AT-START-F425 Review】No.06 Driving Segment LCD
- Today at 10:00 AM Award-winning live broadcast: STMicroelectronics SiC products and industrial application guide
- Gossip negative feedback