TQ2440 key interrupt

Publisher:QuailLatest update time:2015-10-15 Source: eefocusKeywords:TQ2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
There are a few things to note:

1. It is necessary to call the MMU function to implement memory mapping;

2. After the interrupt is triggered and the interrupt processing function is entered, the corresponding bits of SRCPND and INTPND must be cleared first. If the secondary interrupt source is used, such as EINT4 in EINT4_7, the corresponding bit of EINTPEND must be cleared. Generally speaking, the corresponding bit of the secondary interrupt source should be cleared first, and then the interrupt source, otherwise the interrupt source will cause multiple interrupts. After the clearing is completed, specific processing can be performed.

#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "mmu.h"


#define LED1 (1<<5) //must be "()"
#define LED2 (1<<6)
#define LED3 (1<<7)
#define LED4 (1<<8)
 
#define KEY1   (1< <1)   //GPF1
#define KEY2   (1<<4)   //GPF4
#define KEY3   (1<<2)   //GPF2
#define KEY4   (1<<0)   //GPF0

//void delay_ms(U32 i);
void init_irq(void);
void MMU_Init(void);

int Main(void)
{
    rGPBCON=0x15400;
    rGPBDAT=0x7ff;
    MMU_Init();    //MMU is required to implement address mapping
    init_irq();        //Initialize interrupt registers
    while(1);
   
}

void delay_ms(U32 i)
{
   int j;
   for(;i>0;i--)
       for(j=65535;j>0;j--);
}

void key_per(void)    //Key processing
{
    if(!(rGPFDAT&KEY1))
        rGPBDAT=~LED1;
       
    else if(!(rGPFDAT&KEY2))
        rGPBDAT=~LED2;
       
    else if(!(rGPFDAT&KEY3))
     rGPBDAT=~LED3;
     
    else if (!(rGPFDAT&KEY4))
        rGPBDAT=~LED4;
       
}

void __irq key1_3_4(void)
{
   //When a key is pressed, jump to this function. In each branch corresponding to the following keys, you should call before jumping to key_per()

  //ChearPending() clears the corresponding bits of SCRPND and INTPND
    if(rINTPND &KEY3)           
    {                                  
      ClearPending(BIT_EINT2);
      key_per();
    }
    else if(rINTPND &KEY4)
    {                               
      ClearPending(BIT_EINT0);
      key_per();
    }
  
    else if(rINTPND&KEY1)            
    {                
      ClearPending(BIT_EINT1);
      key_per();
    }
   

}

void __irq key2(void) 

{
 //if(rEINTPEND &KEY2)             //10000
 //{      
      rEINTPEND = (1<<4);            //CLEAR   rEINTPEND
      ClearPending(BIT_EINT4_7);
      key_per();
 //} 
}

//Since key2 corresponds to GPF4 in the circuit diagram, the corresponding interrupt function is EINT4, which is specifically determined by the secondary interrupt register

//EINTMASK is used to enable it. In init_irq(), since the interrupt processing function needs to be mapped, key2 is written separately here to make the program clear.

void init_irq(void)
{
    rGPFCON&=(~((3<<0)|(3<<2)|(3<<4)|(3<<8)));
    rGPFCON|=((2<<0 )|(2<<2)|(2<<4)|(2<<8));   //configure GPF0,1,2,4 to EINT0,1,2,4
    //rGPFCON=0xfeea;
    rPRIORITY= 0x00000000;     //deafult priority configure
    rINTMOD=0x0;                     //IRQ
    EnableIrq(BIT_EINT0|BIT_EINT1|BIT_EINT2|BIT_EINT4_7); //enable EINT0, 1, 2, 4_7 with INTMSK register
    //rINTMSK&=(~((1<<0 )|(1<<1)|(1<<2)|(1<<4)));
    rEINTMASK&=~(1<<4);                               //enbale EINT4 with EINTMASK register

//The following is to map the addresses of key1_3_4 and key2 functions to the interrupt vector table, so that when the interrupt is triggered, it jumps to the address of the corresponding function to execute

//Execute this function. If the EINT0 interrupt is triggered, the function key1_3_4 will be executed.

    pISR_EINT0= (unsigned int)key1_3_4;     

    pISR_EINT1= (unsigned int)key1_3_4;
    pISR_EINT2= (unsigned int)key1_3_4;
    pISR_EINT4_7= (unsigned int)key2;
  
}

Keywords:TQ2440 Reference address:TQ2440 key interrupt

Previous article:ARM startup method
Next article:S3C2440 timer 4 interrupt test program

Recommended ReadingLatest update time:2024-11-15 14:56

TQ2440 development board mounts USB disk and garbled characters appear
Solution: Configure the kernel make menuconfig File Systems --- DOS/FAT/NT Filesystems --- (utf8) Default iocharset for FAT Change to (cp936) Default iocharset for FAT Recompile the kernel, burn it to the development board, start the development board, insert the USB drive, m
[Microcontroller]
TQ2440 development board mounts USB disk and garbled characters appear
TQ2440 Study Notes —— 11. Basic knowledge of embedded programming [arm-linux-objcopy, objdump options]
1. arm-linux-objcopy option arm-linux-objcopy is used to copy the contents of a target file to another file. The destination file can be output in a format different from the source file, that is, format conversion can be performed. arm-linux-objcopy is often used to convert executable files in ELF format into binar
[Microcontroller]
TQ2440 Study Notes —— 11. Basic knowledge of embedded programming [arm-linux-objcopy, objdump options]
TQ2440 Study Notes - 17. Dislocated connection between processor and memory
        For a specific memory, its bit width is fixed. The so-called bit width refers to the "smallest data unit during read/write operations" - don't say the smallest unit is a "bit". Generally, there is no separate "bit operation" on the memory. When modifying a bit, the entire byte, word or double word is read out,
[Microcontroller]
TQ2440 Study Notes - 10. Basic knowledge of embedded programming [arm-linux-ld option]
arm-linux-ld is used to link multiple target files and library files into an executable file. Introducing the "-T" option, which can be used directly to specify the starting address of the code segment, data segment, and bss segment. It can also be used to specify a link script to perform more complex address settin
[Microcontroller]
TQ2440 Study Notes - 10. Basic knowledge of embedded programming [arm-linux-ld option]
Latest Microcontroller Articles
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号