用ARM驱动触摸屏,中断方式 打印到串口终端的信息如下:
Test Touch Screen... HandlerIRQ... Select IRQ function... HandlerTC... Auto xy mode... 鎬
显示已经跳转到HandlerTC子函数,也进入了自动xy模式. 可是怎么就死了呢?
有时候多按几下复位键,又能够读出xy坐标: Test Touch Screen... HandlerIRQ... Select IRQ function... HandlerTC... Auto xy mode... HandlerADC... X=0287 Y=0316
很奇怪,不知道是哪里出错了 贴上自己的程序:
#define ISR_ADC_OFT 31
void HandlerTC(void) { //Disable TC intrrupt rSUBSRCPND |= (1<<9); rSRCPND |= (0x8000); rINTPND |= (0x8000); UartSendString("HandlerTC...");
if(rADCDAT0 & 0x8000) { rADCTSC = (1<<7) | (1<<6) | (1<<4) | (3); UartSendString("wait intrrupt mode..."); } else { //AUTO_PST = 1, PULL_UP = 1,XY_PST = 0 rADCTSC = (1<<3) | (1<<2); UartSendString("Auto xy mode..."); rADCCON |= 1;//ADC start } }
void HandlerADC(void) { //Disable ADC intrrupt rSUBSRCPND |= (1<<10); rSRCPND |= (0x8000); rINTPND |= (0x8000); UartSendString("HandlerADC..."); SEND_XY_VALUE;
rADCTSC = (1<<7) | (1<<6) | (1<<4) | (3); }
void TouchScrIntHandle(void) { UartSendString("Select IRQ function..."); if(rSUBSRCPND & (1<<9)) HandlerTC(); else if(rSUBSRCPND & (1<<10)) HandlerADC(); else UartSendString("other interrupt occur..."); }
void SysClkSet(void) { //Fin = 12MHz, FCLK = 400MHz, FCLK:HCLK:PCLK = 1:4:4 //FCLK = 400MHz,HCLK = 100MHz, PCLK = 100MHz; rMPLLCON = (42<<12) | (1<<4);//FCLK = 400MHz rCLKDIVN = (2<<1);//FCLK:HCLK:PCLK = 1:4:4 }
void ADC_Init(void) { isr_handle_array[ISR_ADC_OFT] = TouchScrIntHandle; rINTMSK &= ~(1<<31);//Enable ADC interrupt rINTSUBMSK &= ~(1<<9);//Enable INT_TC interrupt rINTSUBMSK &= ~(1<<10);//Enable INT_ADC_S interrupt //PRSCVL = 99, A/D CLK = PCLK / (PRSCVL + 1)= 1MHz rADCCON = (1<<14) | (99<<6); rADCDLY = 50000; //UD_SEN = 0, PULL_UP = 0, XP_SEN = 1, XM_SEN = 0 //YP_SEN = 1, YM_SEN = 1, XY_PST = 3. rADCTSC = (1<<7) | (1<<6) | (1<<4) | (3);
//AUTO_PST = 1, //rADCTSC |= (1<<2);
//AUTO_PST = 1, //rADCDAT0 |= (1<<14); //rADCDAT1 |= (1<<14); }
void LCD_Init(void) { //I/O port Init, rGPCUP = 0xffffffff;// Disable pullup rGPCCON = 0xaaaaaaaa;// GPIO管脚用于VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND rGPDUP = 0xffffffff;// Disable pullup rGPDCON = 0xaaaaaaaa;// GPIO管脚用于VD[23:8] rGPGUP = 0xffffffff; rGPGCON = (3<<8);//GPG4:LCD_PWREN //CLKVAL = 4, VCLK = HCLK / [(CLKVAL + 1) * 2] = 50MHz //PNRMODE = 0b11, TFT LCD //BPPMODE = 0b1100, 16BPP rLCDCON1 = (4<<8) | (3<<5) | (12<<1);
//VBPD = 1, LINEVAL = 320-1, VFPD = 5, VSPW = 1 rLCDCON2 = (1<<24) | (319<<14) | (5<<6) | (1); //HBPD = 36, HOZVAL = 240-1, HPFD = 19, rLCDCON3 = (36<<19) | (239<<8) | (19);
//HSPW = 5, rLCDCON4 = 5;
//FRM565 = 1, INVVLINE = 1, INVVFRAME = 1, BSWP = 1 rLCDCON5 = (1<<11) | (1<<9) | (1<<8) | (1<<1);
rLCDSADDR1 = ((LCDBUFFER>>22)<<21) | (0x1FFFFF & (LCDBUFFER>>1)); rLCDSADDR2 = (0x1FFFFF) & ((LCDBUFFER + 240*320*2)>>1); rLCDSADDR3 = 120; }
void HandlerIRQ(void) { unsigned long oft = rINTOFFSET;
UartSendString("HandlerIRQ..."); //清中断 if (oft == 4) rEINTPEND = 1<<7; rSRCPND = 1<<oft; rINTPND = rINTPND;
isr_handle_array[oft](); }
void Isr_Init(void) { rINTMOD=0x0; // All=IRQ mode rINTMSK=BIT_ALLMSK; // All interrupt is masked.
pISR_IRQ = (int)HandlerIRQ; }
int Main(void) { unsigned int ADDR; SysClkSet(); Isr_Init(); UartInit(); ADC_Init(); LCD_Init(); rTPAL |= (0xff); rTPAL |= (1<<24);
UartSendString("Test Touch Screen...");
for(;;) { ; } }
|