s3c2440 external interrupt button implementation

Publisher:独行侠客Latest update time:2017-11-27 Source: eefocusKeywords:s3c2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

According to the schematic diagram of the TQ2440 development board, the buttons are connected to the EINT0, 1, 2, and 4 pins of the S3C2440 that can be used for external interrupts, and GPFCON can set the functions of these pins.

The EXTINT0 register can set the conditions for the interrupts of these four pins. It should be noted that EINT0~2 have their own interrupt vectors, while EINT4~7 share an interrupt vector.

Therefore, when using EINT4, you must also open the corresponding interrupt enable bit in the EINTMASK register, and after entering the EINT4 interrupt, you must also clear the interrupt bit of the EINTPEND register.

 

 

The following is the flowchart of the interrupt handling function. The implementation methods of these four buttons are the same:

 

                                 

 

Here is the procedure:

 

/*******************************
    s3c2440 external interrupt button experiment
    LHG
********************************/
#include "2440addr.h"

#include "eint_button.h"
#include "uart.h"

#define U32 unsigned int


int button_result;//Record which button is pressed

int get_button_result(void)//Get the button
{
    int b;
    switch(button_result)//Switch out the correct button number
    {
    case 0:b=4;break;
    case 1:b=1;break;
    case 2:b=3;break;
    case 4:b=2;break;
    default:b=-1;break;
    }
    button_result=-1; 
    return b;//Return button
}


void button_delay(int a,int b)
{
  int c ;
  if (a==0 || b==0)
  return;
  
  while (a--)
  for (c=0;c  ;
}

void share_eint(int b)//Because the interrupt processing flow is the same, we share a processing function, int b is to select which external interrupt source is

  if ( (rEXTINT0>>(4*b)&7)==0x1 )//Judge whether it is a high-level interrupt
  {
  button_result=b;//Notify that a key is pressed
  rEXTINT0 &=~( (7<<16)|(7<<8)|(7<<4)|(7) );//Set the four buttons to low level to enter the interrupt
  rINTMSK &= ~((U32)0x17);//Enable interrupt eint 0,1,2
  rEINTMASK &= ~((U32)0x10);//Enable interrupt eint 4 
  }
  else
  {
  button_delay(100,100);//Delay debounce
  rGPFCON &=~( (3<<8)|0x3f );//Set the pin to inputif
  ( !(rGPFDAT&(1<  {//It is at a low level, confirm that a key is pressedif
       (b<4)//If 0,1,2 interrupt
       {
       rINTMSK |= ((U32)0x17)&(~(1<       rEINTMASK |= (U32)0x10;//Shield interrupt eint 4
       rEXTINT0 |=(1<<4*b); //Set to high level interrupt
       }
       else//If it is 4 interrupts
       {
      //Uart_Printf("int 4/r/n");
       rINTMSK |= ((U32)0x17)&(~(1<       rEINTMASK &= ~((U32)0x10);//Enable interrupt eint 4   
       rEXTINT0 |=(1<<4*b); //Set to high level interrupt
      }
    
  }
  else
  {
  //It is jitter, do nothing
  }
  }
  
  rGPFCON &=~( (3<<8)|0x3f );//Set GPIO to external interrupt mode
  rGPFCON |= ( (2<<8)|0x2a );
 
  rSRCPND |= 0x17;//clear interrupt flag
  rINTPND |= 0x17;
  rEINTPEND |= 0x10;

}

void __irq eint0ISR(void) //eint0 interrupt function

  share_eint(0);
}

void __irq eint1ISR(void) //eint1 interrupt function
{
  share_eint(1);
}

void __irq eint2ISR(void) //eint2 interrupt function
{
  share_eint(2);
}

void __irq eint4_7ISR(void) //eint4 interrupt function

  if (rEINTPEND&0x10)
  share_eint(4);
  
  rSRCPND |= 0x17;//clear interrupt flag
  rINTPND |= 0x17;
  rEINTPEND |= 0x10;
}

void init_eint_button(void)//initialization

  button_result=-1;//No key pressed
  //Set interrupt entry
   pISR_EINT0=(U32)eint0ISR;
   pISR_EINT1=(U32)eint1ISR;
   pISR_EINT2=(U32)eint2ISR;
   pISR_EINT4_7=(U32)eint4_7ISR;//eint4~7 share an interrupt
  
  rINTMOD &= ~((U32)0x17);//Use IRQ mode
  
  rGPFUP |= 0x17;//No pull-up resistor
  rGPFCON &=~( (3<<8)|0x3f );//Set GPIO
  rGPFCON |= ( (2<<8)|0x2a );
  rEXTINT0 &=~( (7<<16)|(7<<8)|(7<<4)|(7) );//All four buttons enter the interrupt at low level
  
  //Open interrupt
  rSRCPND |= 0x17;//Clear interrupt flag
  rINTPND |= 0x17;
  rEINTPEND |= 0x10;
  
  rINTMSK &= ~((U32)0x17);//Enable interrupt eint 0,1,2
  rEINTMASK &= ~((U32)0x10);//Enable interrupt eint 4
 // Uart_Printf("button init/n/r");
}

 

 

 

Achievement results:

              


Keywords:s3c2440 Reference address:s3c2440 external interrupt button implementation

Previous article:S3C2440 IIC read and write AT24C02A
Next article:Use of S3C2440 timer

Recommended ReadingLatest update time:2024-11-16 14:28

s3c2440 bare metal-memory controller (1. Principle of memory controller)
1. Memory interface concept S3C2440 is a system on a chip, with a GPIO controller (connected to GPIO pins (GPA-GPH)), a serial port controller (connected to TXD RXD pins), a memory controller, a Nand controller, etc... 1. Different types of controllers: (1) The GPIO controller is a gate circuit, does not involve tim
[Microcontroller]
s3c2440 bare metal-memory controller (1. Principle of memory controller)
Display of BMP images on S3C2440 development board Part 3
3. BMP picture display function expansion 1. Functional expansion of picture display (1) Ability to adjust the display area of ​​the image. For example, if I prepare a 480x384 image, the LCD screen size is only one ninth of it. I need to control it through the keyboard to "see the whole image." (2) Capable of display
[Microcontroller]
Detailed explanation of S3C2440 cp15 coprocessor
The 2440 coprocessor CP15 has a total of 16 coprocessor registers from c0 to c15, each with a certain function definition. But in general, cp15 is mainly related to the following functions: 1. Get some CPU related information such as device id and cache type. 2. MMU operation. Including enabling and disabling the MMU,
[Microcontroller]
Detailed explanation of S3C2440 cp15 coprocessor
ARM S3C2440 clock initialization process
1. Set lock time 2. Set the frequency division coefficient 3. Set the CPU to asynchronous working mode 4. Set FCLK   Understand the clock schematic of the chip and the function of the register Understand the chip's crystal frequency, phase-locked loop, frequency division factor, and what clocks are available
[Microcontroller]
S3C2440 needs to burn bare metal applet to NAND Flash
For Wei Dongshan's S3C2440 development board, when running simple small programs such as LED, it must be burned to NAND Flash for the following reasons: (1) Although NOR Flash can be read like RAM, it cannot be written like RAM. Therefore, if you want to boot from NOR Flash, you usually use assembly instructions at th
[Microcontroller]
Section 002_S3C2440_LCD Controller
LCD controller main functions and required settings: Get: Get the data of a certain pixel from the memory (FrameBuffer); then tell the LCD controller the FrameBuffer address, BPP, and resolution; Send: send FrameBuffer data to LCD in conjunction with other signals; need to set LCD controller timing and pin polarity;
[Microcontroller]
Section 002_S3C2440_LCD Controller
Samsung CPU s3c2440 interrupt vector table problem
I have never understood why the interrupt vector table of 2440 is at _ISR_STARTADDRESS=0x33FF_FF00? How does the CPU jump to this location? What is the purpose of the terminal vector table at address zero? I had some free time today, so I studied it carefully and finally saw it clearly.    Note the following code:
[Microcontroller]
Energy dispersive X-ray fluorescence spectrometer based on S3C2440
X-ray fluorescence analysis is a fast, accurate and economical multi-element analysis method . At present, X-ray fluorescence analysis technology has been widely used in geology, metallurgy, chemical industry, materials, petroleum, medicine and other fields, especially energy dispersive X-ray fluorescence (EDXRF) sp
[Microcontroller]
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号