|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2009-6-4 00:22:41
|
显示全部楼层
/*****************************************
NAME: Touchpanel.c
DESC: ADC & Touch screen test
HISTORY:
2003.09.23:Leon YH KIM: draft ver 1.0
*****************************************/
#include "def.h"
#include "2440addr.h"
#include "2440lib.h"
#define REQCNT 30
#define ADCPRS 9 //YH 0627
#define LOOP 1
void __irq AdcTsAuto(void);
extern void Glib_FilledRectangle(int x1,int y1,int x2,int y2,int color);
extern void Write_Dot (U16 lcd_x,U16 lcd_y,U16 color);
int count=0;
volatile U16 X_Data, Y_Data,X_Coules,Y_Coules;
volatile U16 X1,Y1,X2,Y2;
void Test_Touchpanel(void)
{
rADCDLY=50000; //Normal conversion mode delay about (1/3.6864M)*50000=13.56ms
rADCCON=(1<<14)+(ADCPRS<<6); //ADCPRS En, ADCPRS Value
Uart_Printf("ADC touch screen test\n");
rADCTSC=0xd3; //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En
pISR_ADC = (int)AdcTsAuto;
rINTMSK=~BIT_ADC; //ADC Touch Screen Mask bit clear
rINTSUBMSK=~(BIT_SUB_TC);
Uart_Printf("\nType any key to exit!!!\n");
Uart_Printf("\nStylus Down, please...... \n");
//rINTSUBMSK|=BIT_SUB_TC;
//rINTMSK|=BIT_ADC;
//Uart_Printf("Touch Screen Test is Finished!!!\n");
}
void __irq AdcTsAuto(void)
{
int i;
U32 saveAdcdly;
if(rADCDAT0&0x8000)
{
rADCTSC&=0xff; // Set stylus down interrupt bit
}
rADCTSC=(1<<3)|(1<<2); //Pull-up disable, Seq. X,Y postion measure.
saveAdcdly=rADCDLY;
rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms
rADCCON|=0x1; //start ADC 启动ADC
while(rADCCON & 0x1); //check if Enable_start is low 等待ADC启动
while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high, This line is necessary~!! 等待ADC转换结束
while(!(rSRCPND & (BIT_ADC))); //check if ADC is finished with interrupt bit
Y_Data=(rADCDAT0&0x3ff);
X_Data=(rADCDAT1&0x3ff);
//Y_Coules = 320*(Y_Data-122)/(890-122);
//X_Coules = 240*(X_Data-81)/(960-81);
if((X1>0)&(Y1>0))
{
if((X2>0)&(Y2>0))
{
Y_Coules = 320*(Y_Data-Y1)/(Y2-Y1);
X_Coules = 240*(X_Data-X1)/(X2-X1);
DisplayTmp(66,32,X_Coules);
DisplayTmp(66,48,Y_Coules);
DisplayTmp(66,64,X_Data);
DisplayTmp(66,80,Y_Data);
Write_Dot(X_Coules,Y_Coules,0xf00f);
}
else
{
if(X1>X_Data)
{
X2=X1;
X1=X_Data;
}
else
{
X2=X_Data;
}
if(Y1>Y_Data)
{
Y2=Y1;
Y1=Y_Data;
}
else
{
Y2=Y_Data;
}
}
}
if((X2==0)|(Y2==0))
{
X1= X_Data;
Y1= Y_Data;
}
//YH 0627, To check Stylus Up Interrupt.
rSUBSRCPND|=BIT_SUB_TC;
ClearPending(BIT_ADC);
rINTSUBMSK=~(BIT_SUB_TC);
rINTMSK=~(BIT_ADC);
rADCTSC =0xd3; //Waiting for interrupt
rADCTSC=rADCTSC|(1<<8); // Detect stylus up interrupt signal.
while(1) //to check Pen-up state
{
Delay(5);
if(rSUBSRCPND & (BIT_SUB_TC)) //check if ADC is finished with interrupt bit
{
break; //if Stylus is up(1) state
}
rADCTSC=(1<<3)|(1<<2); //Pull-up disable, Seq. X,Y postion measure.
saveAdcdly=rADCDLY;
rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms
rADCCON|=0x1; //start ADC 启动ADC
while(rADCCON & 0x1); //check if Enable_start is low 等待ADC启动
while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high, This line is necessary~!! 等待ADC转换结束
//while(!(rSRCPND & (BIT_ADC))); //check if ADC is finished with interrupt bit
Y_Data=(rADCDAT0&0x3ff);
X_Data=(rADCDAT1&0x3ff);
// Y_Coules = 320*(Y_Data-122)/(890-122);
// X_Coules = 240*(X_Data-81)/(960-81);
if((X1>0)&(Y1>0)&(X2>0)&(Y2>0))
{
Y_Coules = 320*(Y_Data-Y1)/(Y2-Y1);
X_Coules = 240*(X_Data-X1)/(X2-X1);
DisplayTmp(66,32,X_Coules);
DisplayTmp(66,48,Y_Coules);
DisplayTmp(66,64,X_Data);
DisplayTmp(66,80,Y_Data);
Write_Dot(X_Coules,Y_Coules,0xf00f);
}
rSUBSRCPND|=BIT_SUB_TC;
ClearPending(BIT_ADC);
rINTSUBMSK=~(BIT_SUB_TC);
rINTMSK=~(BIT_ADC);
rADCTSC =0xd3; //Waiting for interrupt
rADCTSC=rADCTSC|(1<<8); // Detect stylus up interrupt signal.
}
rADCDLY=saveAdcdly;
rADCTSC=rADCTSC&~(1<<8); // Detect stylus Down interrupt signal.
rSUBSRCPND|=BIT_SUB_TC;
rINTSUBMSK=~(BIT_SUB_TC); // Unmask sub interrupt (TC)
ClearPending(BIT_ADC);
}
void Touchpanel_Check (void)
{
Clr_Sckreen(0XFFFF);
X_Data=Y_Data=0;
Glib_FilledRectangle(1,1,16,16,0X0000);
DrawString(0,32,(U8*)"请输入单击屏幕左上角:",0XFF00,0X0F00,1);
while(1)
{
if((X1>0)&(Y1>0))
{
break;
}
}
Clr_Sckreen(0XFFFF);
Glib_FilledRectangle(224,304,240,320,0X0000);
DrawString(0,32,(U8*)"屏幕左上角已经定位好:",0XFF00,0X0F00,1);
DrawString(0,56,(U8*)"请输入单击屏幕右下角:",0XFF00,0X0F00,1);
X_Data=Y_Data=0;
while(1)
{
if((X2>0)&(Y2>0))
{
break;
}
}
DrawString(0,32,(U8*)"屏幕左上角已经定位好:",0XFF00,0X0F00,1);
DrawString(0,56,(U8*)"屏幕右下角已经定位好:",0XFF00,0X0F00,1);
DrawString(0,80,(U8*)"正在计算请稍后。。。!",0XFF00,0X0F00,1);
} |
|