⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 int.c

📁 这是基于三星公司的S3C2410芯片中外部中断的应用.
💻 C
字号:
#include "s3c2410_addr.h"


void printf(char *c);
static __irq void int_srv(void);


/*
*该函数用于完成将开发板上的4个小键盘相对应的中断设置好
*
*/
void key_interrupt_init()
{
	/*由于4个小键盘分别连接到GPF0/GPF2/GPG3/GPG11口,设置这四个引脚为中断口*/
	rGPFCON|=2<<0|2<<4;//设置GPF0和GPF2为中断EINT0/EINT2		
	rGPGCON|=2<<6|2<<22;//设置GPG3和GPG11为中断EINT11/EINT19 
	rGPFUP=0;
	rGPGUP=0;
	
	/*4个发光二极管连接到GPF4~GPF7引脚上,设置这四个引脚为输出口*/
	rGPFCON|=1<<8|1<<10|1<<12|1<<14;
	
	
	
	/*设置中断类型为IRQ*/
	rINTMOD =0;
	
	
	/*设置EINT0/EINT2/EINT11/EINT19上升沿触发*/
	rEXTINT0|=4<<0|4<<8;//设置EINT0/EINT2上升沿触发
	rEXTINT1|=4<<12;//设置EINT11上升沿触发
	rEXTINT2|=4<<12;//设置EINT19上升沿触发
	
	
	/*打开EINT0/EINT2/EINT11/EINT19中断*/
	rEINTMASK &= ~(1<<11|1<<19);//打开EINT11/EINT19中断
	rINTMSK &= ~(1<<0|1<<2|1<<5);//打开EINT0/EINT2/EINT8_23
	
	/*打开CPSR寄存器中IRQ中断位*/
	__asm{					//clear the bits of IRQ and	FIQ in CPSR to 0
		MRS	R0,CPSR
		AND	R0,R0,0XFFFFFF7F
		MSR	CPSR_c,R0			
	};
	
	pISR_EINT0 = pISR_EINT2 = pISR_EINT8_23 = (unsigned int)int_srv;
}


/*键盘0中断服务函数*/
void key0_int_srv()
{
	uart_send("the button 0 is pressed!\r\n");
	//you can add your code here if you want to do something when you press button 0

}


/*键盘1中断服务函数*/
void key1_int_srv()
{
	uart_send("the button 1 is pressed!\r\n");
	//you can add your code here if you want to do something when you press button 1

}


/*键盘2中断服务函数*/
void key2_int_srv()
{
	uart_send("the button 2 is pressed!\r\n");
	//you can add your code here if you want to do something when you press button 2

}

/*键盘3中断服务函数*/
void key3_int_srv()
{
	uart_send("the button 3 is pressed!\r\n");
	//you can add your code here if you want to do something when you press button 3

}



/*
*该函数用于完成触摸屏初始化
*/

void ts_init()
{
	//配置GPG12~15引脚为XMON/nXPON/YMON/nYPON
	rGPGCON	|= (3<<24|3<<26|3<<28|3<<30);
	
	//设置ADC中断和TS中断为IRQ中断
	rINTMOD =0;
	
		
	// Enable Prescaler,Prescaler,AIN7/5 fix,Normal,Disable read start,No operation
	rADCCON = (1<<14)|(0xff<<6)|(0<<3)|(0<<2)|(0<<1)|(0);
	
    // Down,YM:GND,YP:AIN5,XM:Hi-z,XP:AIN7,XP pullup En,Normal,Waiting for interrupt mode
    rADCTSC = (0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3<<0);
    
    
    
	//打开ADC中断和TS中断
	rINTMSK &= ~(1<<31);	
	rINTSUBMSK &= ~(1<<10|1<<9);
	
	/*打开CPSR寄存器中IRQ中断位*/
	__asm{					//clear the bits of IRQ and	FIQ in CPSR to 0
		MRS	R0,CPSR
		AND	R0,R0,0XFFFFFF3F
		MSR	CPSR_c,R0			
	};
      

}



void ts_process(void)
{
	int i;
    int Ptx[6], Pty[6];
   
   
           
          // <X-Position Read>
        rADCTSC=(0<<8)|(0<<7)|(1<<6)|(1<<5)|(0<<4)|(1<<3)|(0<<2)|(1);
          // Down,Hi-Z,AIN5,GND,Ext vlt,Pullup Dis,Normal,X-position
        for(i=0;i<200;i++);            //delay to set up the next channel
        for(i=0;i<5;i++)
        {
            rADCCON|=0x1;               // Start X-position conversion
            while(rADCCON & 0x1);       // Check if Enable_start is low
            while(!(0x8000&rADCCON));   // Check ECFLG
            Ptx[i]=(0x3ff&rADCDAT0);
        }
        Ptx[5]=(Ptx[0]+Ptx[1]+Ptx[2]+Ptx[3]+Ptx[4])/5;

          // <Y-Position Read>
        rADCTSC=(0<<8)|(0<<7)|(1<<6)|(1<<5)|(0<<4)|(1<<3)|(0<<2)|(2);
          // Down,GND,Ext vlt,Hi-Z,AIN7,Pullup Dis,Normal,Y-position
        for(i=0;i<500;i++);            //delay to set up the next channel
        for(i=0;i<5;i++)
        {
            rADCCON|=0x1;               // Start X-position conversion
            while(rADCCON & 0x1);       // Check if Enable_start is low
            while(!(0x8000&rADCCON));   // Check ECFLG
            Pty[i]=(0x3ff&rADCDAT1);
        }
        Pty[5]=(Pty[0]+Pty[1]+Pty[2]+Pty[3]+Pty[4])/5;
        rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
          // Up,GND,AIN,Hi-z,AIN,Pullup En,Normal,Waiting mode

       // printf("TOUCH Position = (%04d, %04d)        ", Ptx[5], Pty[5]);
		


}






/*
*IRQ中断处理函数总入口,即发生中断后会跳到该函数.
*在该函数中判断发生中断的类型,然后跳转到相应的中断处理函数
*/
static __irq void int_srv(void)
{
	unsigned int which_int=500;
	unsigned int sub_which_int=501;
	which_int = rINTOFFSET;//读出是何中断发生
	
	uart_send("a interrup occours!\r\n");
	
	/*清除中断源状态寄存器和中断请求寄存器中相对应的位*/
	rINTPND |= 1<<which_int;
	rSRCPND |= 1<<which_int;
	
	switch(which_int)
	{
		case 0://按下button 0 小键盘
				key0_int_srv();
				break;
		case 2://按下button 1 小键盘
				key1_int_srv();
				break;
		case 5://按下button 2 或button 3小键盘
				sub_which_int=rEINTPEND;
				rEINTPEND |= rEINTPEND;
				switch(sub_which_int)
				{
					case 0x800://按下button 2 小键盘
						key2_int_srv();
						break;
					case 0x80000://按下button 3 小键盘
						key3_int_srv();
						break;
					default:
						uart_send("It is not a unknown sub interrupt\r\n");
						break;
				}
				break;					
				
		default:
				uart_send("it's a unknown interrupt\r\n");
	}
}
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -