www.pudn.com > ARM9(s3c2410)TOUCH_SCREEN.rar > touch_screen.c


/************************************************************** 
Touch Screen control 
**************************************************************/ 
#include "def.h" 
#include "option.h" 
#include "2410addr.h" 
#include "2410lib.h" 
#include "uart.h" 
#include "interrupt.h" 
#include "2410lib.h" 
#include "touch_screen.h" 
#include "240_320TFT_LCD.h" 
#include "text.h" 
#include "pwm_timer.h" 
 
 
 
#define ST_IDENTIFY_BLANK    60 
 
 
 
 
  
 
 
 
  volatile   static U32 ts_state; 
  volatile   static int ts_lefttop_x; 
  volatile   static int ts_lefttop_y; 
  volatile   static int ts_righttop_x; 
  volatile   static int ts_righttop_y; 
  volatile   static int ts_leftbuttom_x; 
  volatile   static int ts_leftbuttom_y; 
  volatile   static int ts_rightbuttom_x; 
  volatile   static int ts_rightbuttom_y; 
  volatile    int xdata_lcd_width  = -759; 
  volatile    int ydata_lcd_heigth = -775; 
  volatile    int xdata_at_first_block_middle = 509; 
  volatile    int ydata_at_first_block_middle = 532; 
   
  volatile    U8  stylus = STYLUS_UP  ;  
   
 
 
//************************************************************* 
 
/************************************************************** 
The interrupt function for Touch Screen 
**************************************************************/ 
void __irq Touch_Screen(void) 
{       
 
    int i; 
    int Ptx[6]; 
    int Pty[6]; 
    int ts_lcd_x; 
    int ts_lcd_y; 
     
 
     
    lcd_window_start_point  lcd_window_start_point0;   
   
    rINTSUBMSK |= (BIT_SUB_ADC|BIT_SUB_TC); // Mask sub interrupt (ADC and TC)  
 
      // TC(Touch screen Control) Interrupt  
    if(rADCTSC & 0x100) //用到了rADCTSC保留的第八位。下面按下时下面中断程序将其设为一。 
    { 
        rADCTSC &= 0xff;    // Set stylus down interrupt 
       // Uart_Printf("stylus up.......\n"); 
        stylus = STYLUS_UP; 
        if(ts_state==TS_START) { 
           Text_Show_OnePage(0x001f); 
         } 
    } 
    else  
    {    
        stylus = STYLUS_DOWN; 
      //  Uart_Printf("stylus down.......\n");   
          //  
        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 
        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;i239 ) ts_lcd_x = 239; 
            if(ts_lcd_x <0   ) ts_lcd_x = 0; 
            if(ts_lcd_y >319 ) ts_lcd_y = 319; 
            if(ts_lcd_y <0 )   ts_lcd_y = 0; 
            lcd_window_start_point0=Get_LcdViewPort_StartPoint(); 
            ts_lcd_x += lcd_window_start_point0.X ; 
            ts_lcd_y += lcd_window_start_point0.Y ; 
            LCD_String_Set(0,0,0xf800); 
            LCD_Printf(" 坐标:(%3d,%3d)",ts_lcd_x,ts_lcd_y);  
           // Uart_Printf("LCD position at (%3d , %3d)\n",ts_lcd_x,ts_lcd_y); 
           // Glib_FilledRectangle(ts_lcd_x,ts_lcd_y,ts_lcd_x+1,ts_lcd_y+1 ,0x0);  
 
 
           }  
 
    } 
    rSUBSRCPND |= BIT_SUB_TC; 
    rINTSUBMSK =~ (BIT_SUB_TC);         // Unmask sub interrupt (TC)      
    ClearPending(BIT_ADC);        
} 
     
   
             
/************************************************************** 
The Initial of Touch Screen 
**************************************************************/ 
void Touch_Screen_Init(void) 
{ 
    Uart_Printf("[Touch Screen Test.]\n"); 
    Uart_Printf("Separate X/Y position conversion mode test\n"); 
    rADCDLY = (0x7fff);  // ADC Start or Interval Delay 
    rADCCON = (1<<14)|(ADCPRS<<6)|(0<<3)|(0<<2)|(0<<1)|(0); 
      // Enable Prescaler,Prescaler,AIN7/5 fix,Normal,Disable read start,No operation 
    rADCTSC = (0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3); 
      // Down,YM:GND,YP:AIN5,XM:Hi-z,XP:EXTENAL,XP pullup En,Normal,Waiting for interrupt mode 
      // 2410 427页上设置。为等待中断状态 xp : pull up  and external V;  xm : Hi-z ;  YP :AIN[5]  ; YM :GND 
      // 相当于 X导电片X+ X-都为高电平(xp : pull up  and external;xm : Hi-z) 
      // 而Y-接地 ,Y+接ain[5],Y-、Y+为同一导电片,则Y+也为低电平,那么当接触时,Y+由低变高, 
      // 产生中断。 
       
    pISR_ADC   = (unsigned)Touch_Screen; 
    EnableIrq(BIT_ADC); 
    EnableSubIrq(BIT_SUB_TC); 
     
   // ts_state=TS_FIRST; 
    ts_state=TS_START; 
     
    xdata_lcd_width  = -759; 
    ydata_lcd_heigth = -775; 
    xdata_at_first_block_middle = 509; 
    ydata_at_first_block_middle = 532; 
     
 
    
 
    Lcd_ClearScr(0); 
    Lcd_MoveViewPort(0,0); 
    if(ts_state==TS_FIRST){ 
    	Glib_Rectangle(0,0,SCR_XSIZE_TFT_240_320/2-1,SCR_YSIZE_TFT_240_320/2-1,0x001f);       
    	Uart_Printf("\nTouch the touch_sreen to begin touch_sreen justify !! .......\n"); 
    	LCD_Puts(16*3,16*9,"请触摸屏幕的任意点",0xffff); 
    	while(1) { 
       		if(ts_state==TS_START) break; 
       	} 
    }   	 
} 
//*************************************************************