www.pudn.com > 2410_TouthScreen.rar > Touch_Screen.c


/************************************************************** 
Touch Screen control 
**************************************************************/ 
#include  
#include "2410addr.h" 
#include "2410lib.h" 
#include "Touch_Screen.h" 
 
unsigned int buf[5][2]; 
//************************************************************* 
 
/************************************************************* 
          The interrupt function for Touch Screen 
**************************************************************/   
void __irq ADC_ISR(void) 
{ 
    int i; 
     
    DisableIrq(BIT_ADC); 
	 
	if( rSUBSRCPND & (1<<9))//TC init occur 
	{ 
	    DisableSubIrq(BIT_SUB_TC);    //Mask sub interrupt (ADC and TC)  
        Uart_Printf("\n Touch_Screen Down!\n"); 
        
        //Auto X-Position and Y-Position Read 
        //[7]=1,YM=GND; [6]=1,YP=AIN[5]; [5]=0 XM=Hi-Z; [4]=1, XP=AIN[7]; 
        //[3]=1,XP pull-up disable; [2]=1, Auto(sequential) X/Y position conversion mode,  
        //[1:0]=0, No operation mode;    
        rADCTSC = (1<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0); 
  
        for(i=0;i<5;i++) 
        { 
            rADCCON |= 0x01;             //A/D conversion starts and this bit is cleared after the start-up. 
            while(!((1<<15)&rADCCON));    //Check End of conversion flag ? 
        
            buf[i][0] = (0x3ff&rADCDAT0);//X-position conversion data value. 
            buf[i][1] = (0x3ff&rADCDAT1);//Y-position conversion data value. 
        } 
 
        for(i=0;i<5;i++)     
            Uart_Printf("X %4d, Y %4d\n", buf[i][0], buf[i][1]); 
        //[7] YM=GND, [6] YP is connected with AIN[5], [5] XM=Hi-Z, [4] XP is connected with AIN[7] 
        //[3] XP pull-up enable, [2] Normal ADC conversion, [1:0] Waiting for interrupt mode          
        rADCTSC = (1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);   
 
        ClearSubPending(BIT_SUB_TC); 
        EnableSubIrq(BIT_SUB_TC); 
        
    } 
    if( rSUBSRCPND & (1<<10))//ADC init occur 
    { 
        DisableSubIrq(BIT_SUB_ADC); 
        Uart_Printf("\n ADC init occur!\n"); 
        Uart_Printf( "AIN0: %04d\n",rADCDAT0&0x3ff); 
        ClearSubPending(BIT_SUB_ADC); 
        EnableSubIrq(BIT_SUB_ADC); 
    } 
     
    ClearPending(BIT_ADC); 
    EnableIrq(BIT_ADC); 
} 
             
/************************************************************** 
Touch Screen ³υΚΌ»― 
**************************************************************/ 
void Touch_Screen_Init(void) 
{ 
      
    // Enable Prescaler=39,Prescaler A/D converter freq. = 50 MHz/(39+1) = 1.25MHz 
    //Conversion time = 1/(1.25MHz / 5cycles) = 1/250 kHz = 4 us  
    //AIN0,Normal,Disable read start,No operation 
    rADCCON = (1<<14)|(39<<6)|(0<<3)|(0<<2)|(0<<1)|(0);  
    //YM=GND,YP=AIN5,XM=Hi-z,XP=AIN7,XP pullup En,Normal ADC,Waiting for interrupt mode   
    rADCTSC = (0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3); 
    rADCDLY = 500; //wait for Auto X/Y Position conversion.	 
     
    pISR_ADC    = (unsigned)ADC_ISR; 
     
    ClearSubPending(BIT_SUB_TC); 
    ClearSubPending(BIT_SUB_ADC); 
    ClearPending(BIT_ADC); 
     
    EnableSubIrq(BIT_SUB_ADC); 
    EnableSubIrq(BIT_SUB_TC); 
    EnableIrq(BIT_ADC); 
     
     
    Uart_Printf( "\nNow touchpanel controler is initial!\n" ) ; 
    Uart_Printf( "Please Press it with touch pen and see what happend\n" ) ; 
     
    Uart_Printf( "\nAny key to exit the touchpanel test\n" ) ; 
    Uart_Getch() ; 
     
    Touch_Screen_Off() ; 
} 
//************************************************************* 
void Touch_Screen_Off(void) 
{ 
	DisableIrq(BIT_ADC); 
	DisableSubIrq(BIT_SUB_TC); 
	rADCCON |= (1<<2); //ADC standby mode 
	rADCCON |= (1); //ADC no operation 
	 
}