|  | 
| /***************************************** NAME: Touchpanel.c
 DESC: ADC & Touch screen test
 *****************************************/
 #include "config.h"
 
 
 #define REQCNT 30
 
 #define LOOP 1
 #define ADCPRS 0x27
 int TX=0;//触摸坐标x
 int TY=0;//触摸坐标y
 
 int isDown;
 volatile int touch_over = 0;
 
 int count=0;
 U32 Pt[6];
 U16 diffx, diffy;
 U16 errx1, erry1,errx2, erry2;
 
 extern OS_EVENT *TouchMbox;
 
 static void TSIrqISR(void);
 
 
 int calibration(void)
 {
 
 //        Lcd_ClearScr( (0x1f<<11) | (0x3f<<5) | (0x1f)  )  ;//白屏
 /* 获取左上角基准点 */
 //    DrawLine(   0,  19,  39, 19, 0);
 //    DrawLine(  19,   0,  19, 39, 0);//十字叉
 
 touch_over = 0;
 while(!touch_over);//if not touch over,wait
 //    DrawLine(   0,  19,  39, 19, 0xffff);
 //    DrawLine(  19,   0,  19, 39, 0xffff);//清十字叉
 if( (TX<855) && (TX>810) && (TY<170) && (TY>115) )
 {
 errx1 = TY;
 erry1 = TX;//基准点坐标
 }
 else
 {
 return(0);
 }
 
 /* 获取右下角基准点 */
 //   DrawLine( 279, 219, 319, 219, 0);
 //   DrawLine( 299, 199, 299, 239, 0);
 
 touch_over = 0;
 while(!touch_over);//if not touch over,wait
 //    DrawLine( 279, 219, 319, 219, 0xffff);
 //    DrawLine( 299, 199, 299, 239, 0xffff);//清十字叉
 if( (TX<200) && (TX>145) && (TY<916) && (TY>869) )
 {
 errx2 = TY;
 erry2 = TX;//基准点坐标
 }
 else
 {
 return(0);
 }
 diffx = errx2 - errx1;
 diffy = erry1 - erry2;
 return (1);
 }
 
 
 
 void SetTSInterrupt(void)
 {
 rADCDLY = (50000);
 rADCCON = (1<<14)|(ADCPRS<<6)|(7<<3)|(0<<2)|(0<<1)|(0);
 rADCTSC = (0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
 pISR_ADC = (U32)TSIrqISR; //
 rINTMSK &= ~(BIT_ADC);
 rINTSUBMSK &= ~(BIT_SUB_TC);
 OSPrintf("\nTouch Initing.. !\n");
 }
 
 
 static void TSIrqISR(void)
 {
 int i;
 
 rINTSUBMSK |= (BIT_SUB_ADC|BIT_SUB_TC);
 if(rADCDAT0 & 0x8000)
 {//抬起
 isDown = 0;
 rADCTSC &= 0xff;    // Set stylus down interrupt
 TX = -1;
 TY = -1; //抬起触笔时,TX,TY要值成不大于0的数
 }
 else //按下
 {          isDown = 1;
 rADCTSC=(0<<8)|(0<<7)|(0<<6)|(1<<5)|(1<<4)|(1<<3)|(0<<2)|(1);
 for(i=0;i<LOOP;i++);            //delay to set up the next channel
 for(i=0;i<5;i++)                           //5 times
 {
 rADCCON|=0x1;               // Start X-position conversion
 while(rADCCON & 0x1);       // Check if Enable_start is low
 while(!(0x8000&rADCCON));   // Check ECFLG
 Pt[i]=(0x3ff&rADCDAT0);
 }
 Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;//多次采样取平均值
 TX = Pt[5];
 rADCTSC=(0<<8)|(0<<7)|(1<<6)|(1<<5)|(0<<4)|(1<<3)|(0<<2)|(2);
 for(i=0;i<LOOP;i++);            //delay to set up the next channel
 for(i=0;i<5;i++)                           //5 times
 {
 rADCCON|=0x1;               // Start Y-position conversion
 while(rADCCON & 0x1);       // Check if Enable_start is low
 while(!(0x8000&rADCCON));   // Check ECFLG
 Pt[i]=(0x3ff&rADCDAT1);
 }
 Pt[5]=(Pt[0]+Pt[1]+Pt[2]+Pt[3]+Pt[4])/5;// 多次采样取平均值
 
 TY = Pt[5];
 rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
 }
 //cprintf("%d,%d\n",TX,TY);
 //OSMboxPost(TouchMbox, 0);//向处理触摸进程发消息
 if(rSUBSRCPND & (BIT_SUB_TC))        //check if ADC is finished with interrupt bit
 {
 touch_over = 1;//gshx_2010_7_11
 }
 
 rSUBSRCPND |= BIT_SUB_TC;
 rINTSUBMSK &= ~(BIT_SUB_TC);         // Unmask sub interrupt (TC)
 ClearPending(BIT_ADC);
 }
 | 
 |