SAM4E MCU Tour - 6. LED Flashing Button Control

Publisher:RainbowMelodyLatest update time:2017-01-07 Source: eefocusKeywords:SAM4E Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

clip_image002

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.

 

clip_image004

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;
        }
    }
}


Keywords:SAM4E Reference address:SAM4E MCU Tour - 6. LED Flashing Button Control

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

SAM4E MCU Tour - 24. Using DSP Library to Find Vector Dot Product
A lot of mathematical operations are used in DSP (Digital Signal Processing). Cortex-M4 is equipped with some powerful components to improve DSP capabilities. At the same time, CMSIS provides a DSP library that provides efficient implementation of many mathematical functions. This time, let's make a simple attempt to
[Microcontroller]
SAM4E MCU Tour - 24. Using DSP Library to Find Vector Dot Product
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号