?? int.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 + -