mini2440中断实验

 mini2440中断实验_第1张图片

注意:

清除标志的顺序为SUBSRCPEN->SRCPND->INTPND.

 

#define rGPGCON (*(volatile unsigned long*)0x56000060)

#define rSRCPND (*(volatile unsigned long*)0X4A000000)
//#define rINTMOD (*(volatile unsigned long*)0X4A000004)
#define rINTMSK (*(volatile unsigned long*)0X4A000008)
//#define rPRIORITY (*(volatile unsigned long*)0x4A00000C)
#define rINTPND (*(volatile unsigned long*)0X4A000010)
#define rINTOFFSET (*(volatile unsigned long*)0x4A000014)
//#define rSUBSRCPND (*(volatile unsigned long*)0X4A000018)
//#define rINTSUBMSK (*(volatile unsigned long*)0X4A00001C)
#define rEINTMASK (*(volatile unsigned long*)0x560000a4)
#define rEINTPEND (*(volatile unsigned long*)0x560000a8)

#define	rGPBCON (*(volatile unsigned long *)0x56000010)
#define	rGPBDAT (*(volatile unsigned long *)0x56000014)

#define rWTCON (*(volatile unsigned long *)0x53000000)

#define GPG0EINT8	(2<<0)		//key 1
#define GPG3EINT11	(2<<6)		//key 2
#define GPG5EINT13	(2<<10)		//key 3
#define GPG6EINT14	(2<<12)		//key 4


void port_init(void)
{
	rGPGCON |= GPG0EINT8 | GPG3EINT11 | GPG5EINT13 | GPG6EINT14;
	rGPBCON |= (1<<10)|(1<<12)|(1<<14)|(1<<16);
}

void int_init(void)
{
	rINTMSK &= ~(1<<5);
	rEINTMASK &= ~((1<<8)|(1<<11)|(1<<13)|(1<<14));
}
void disable_watchdog(void)
{
	rWTCON = 0;
}


void ISR(void)
{
	unsigned long m = rINTOFFSET;
	
	if(m == 5)
	{
		if(rEINTPEND & (1<<8))
		{
			rGPBDAT = 0x1e0;
			rGPBDAT &= ~(1<<5);
			rEINTPEND |= (1<<8);
		}
		else if(rEINTPEND & (1<<11))
		{
			rGPBDAT = 0x1e0;
			rGPBDAT &= ~(1<<6);
			rEINTPEND |= (1<<11);			
		}
		else if(rEINTPEND & (1<<13))
		{
			rGPBDAT = 0x1e0;
			rGPBDAT &= ~(1<<7);
			rEINTPEND |= (1<<13);		
		}
		else if(rEINTPEND & (1<<14))
		{
			rGPBDAT = 0x1e0;
			rGPBDAT &= ~(1<<8);
			rEINTPEND |= (1<<14);		
		}
		else
		{
		}
	}
	rSRCPND |= (1<<m);
	rINTPND |= (1<<m);
	
}

void delay(void)
{
	int m,n;
	
	for(m=0;m<500;m++)
	{
		for(n=0;n<500;n++)
		{
		}
	}
}




void Main(void)
{
	while(1)
	{
//		rGPBDAT = 0x1e0;
//		delay();
//		rGPBDAT = 0x0;
//		delay();	
	}
}






	IMPORT Main
	IMPORT ISR
	IMPORT port_init
	IMPORT int_init
	IMPORT disable_watchdog

	AREA Init,CODE,READONLY
	ENTRY

	B Reset
	
HandleUndef
	B HandleUndef
HandleSWI
	B HandleSWI
HandlePrefetchAbort
	B HandlePrefetchAbort
HandleDataAbort
	B HandleDataAbort
HandleNotUsed
	B HandleNotUsed
	
	B HandleIRQ
	
HandleFIQ
	B HandleFIQ

HandleIRQ

    sub lr, lr, #4                  ; 计算返回地址
    stmdb   sp!,    { r0-r12,lr }   ; 保存使用到的寄存器 此SP为中断模式下SP
                                    ; 初始值是下面指定的3*1024    
    ldr lr, =int_return             ; ÉèÖõ÷ÓÃISR¼´EINT_Handleº¯ÊýºóµÄ·µ»ØµØÖ·  
    ldr pc, =ISR		            ; µ÷ÓÃÖжϷþÎñº¯Êý£¬ÔÚinterrupt.cÖÐ
int_return
    ldmia   sp!,    { r0-r12,pc }^  ;
Reset
	msr cpsr_c,#0xd2	
	ldr sp,=3*1024
	
	msr cpsr_c,#0xdf
	LDR SP,=4*1024
	
	
	BL disable_watchdog
	BL port_init
	BL int_init
	msr cpsr_c,#0x5f
	BL Main
	
	END

你可能感兴趣的:(c,import,delay)