Cortex-M3 Learning Log (Part 3) - External Interrupt 0

Publisher:快乐家庭Latest update time:2016-04-06 Source: eefocusKeywords:Cortex-M3 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The LPC1768 microprocessor includes 4 external interrupts, namely EINT0, EINT1, EINT2, and EINT3. The corresponding pins are P2.10~P2.13, which can also be used as general IO ports. Each external interrupt can be set to low level/high level or rising edge/

Register Name

describe

Function

default value

EXTINT

External interrupt flag register

Set or check the interrupt flag

0x00

EXTMODE

External Interrupt Mode Register

Set level trigger or edge trigger

0x00

EXTPOLAR

External interrupt polarity register

Set to high/low level or rising/falling edge trigger

0x00

PINSEL4

Pin Function Select Register

Select the function of the P2 pin

0x00

Because the experiment uses the interrupt mode instead of the query mode to test the interrupt, and because there is a button connected to the P2.10 port, this button is used to make a simple interrupt experiment. Because the falling edge trigger is selected, a register is also involved: IO2IntEnF. The function of this register is to enable the falling edge interrupt function of the P2 port. Because it is just an experiment, the circuit is very simple, and the circuit diagram used in the previous two times is still used, as shown below:

Cortex-M3 Learning Log (Part 3) - External Interrupt 0
Figure 1-1 LED indicator circuit

There is another circuit, which is actually connecting a light touch button to the P2.10 port to trigger an external interrupt. I won't show the diagram here. Well, since the experiment is simple, the interrupt program is given below. If you are interested in the main program, you can refer to the attachment, which contains the complete engineering artifacts created by Real MDK4.10:

 

#include "includes.h"

volatile uint32_t eint0_counter = 8;    //  The first light turns on during initialization

 

void EINT0_IRQHandler (void)

{

  SC->EXTINT = EINT0;                      

                         

  witch(eint0_counter%8)

  {

            case 0: Led1Neg();     

                       break;

            case 1: Led2Neg();        

                       break;

            case 2: Led3Neg();     

                       break;

            case 3: Led4Neg();     

                       break;

            case 4: Led5Neg();     

                       break;

            case 5: Led6Neg();     

                       break;

            case 6: Led7Neg();     

                       break;

            case 7: Led8Neg();     

                       break;

    default:break;

  }

   eint0_counter++;                      

}

 

uint32_t EINTInit( void )

{

  PINCON -> PINSEL4 = 0x00100000;           

  GPIOINT->IO2IntEnF = 0x200;        

  SC->EXTMODE = EINT0_EDGE;      

  SC->EXTPOLAR = 0;           

  NVIC_EnableIRQ(EINT0_IRQn);      

  return( TRUE );

}

This program has only two functions, one is the interrupt handling function, which is not difficult to understand, so I won't summarize it here. Regarding the interrupt initialization function, the previous ones are all about setting the related interrupt registers. You can look at the LPC1768 manual for details on how to set the registers, which are explained in detail. I won't summarize it here. Regarding the void NVIC_EnableIRQ(IRQn_Type IRQn) function, it is defined in core_cm3.h. In fact, it sets the interrupt enable register ISER. As you can see from the name, its function is to enable interrupts. This time, the external interrupt did not use the query method. The principle of the query method is to set the interrupt, enable the interrupt, and then the main program keeps querying the interrupt bit to see if there is an interrupt, and then execute the corresponding measures. Relatively speaking, the query method consumes more software system resources, but the program is not too difficult. The other external interrupts are similar.

Keywords:Cortex-M3 Reference address:Cortex-M3 Learning Log (Part 3) - External Interrupt 0

Previous article:Cortex-M3 Learning Log (IV) -- UART0 Experiment
Next article:Cortex-M3 Learning Log (Part 2) - Button Experiment

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号