📄 touch.c
字号:
#include <string.h>
#include "..\inc\2410addr.h"
#include "..\inc\2410lib.h"
#include "..\inc\Ts.h"
#include "..\inc\def.h"
#include "..\inc\glib.h"
#include "..\inc\lcddrive.h"
#include "..\inc\font.h"
#define REQCNT 30
#define ADCPRS 9 //YH 0627
#define LOOP 1
void __irq AdcTsAuto(void);
volatile int Ymax,Ymin,Xmin,Xmax;
int count=0;
int Ts_Index=0;
volatile int xdata, ydata;
void Test_Touchpanel(void)
{
Xmax = 950;
Ymax = 950;
Xmin = 30;
Ymin = 30;
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");
Uart_Getch();
rINTSUBMSK|=BIT_SUB_TC;
rINTMSK|=BIT_ADC;
Uart_Printf("Touch Screen Test is Finished!!!\n");
}
void __irq AdcTsAuto(void)
{
int i;
char fail = 0;
U32 saveAdcdly;
int temp;
if(rADCDAT0&0x8000)
{
//Uart_Printf("\nStylus Up!!\n");
rADCTSC&=0xff; // Set stylus down interrupt bit
}
//else
//Uart_Printf("\nStylus Down!!\n");
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
while(rADCCON & 0x1); //check if Enable_start is low
while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high, This line is necessary~!!
while(!(rSRCPND & (BIT_ADC))); //check if ADC is finished with interrupt bit
xdata=(rADCDAT0&0x3ff);
ydata=(rADCDAT1&0x3ff);
//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
{
if(rSUBSRCPND & (BIT_SUB_TC)) //check if ADC is finished with interrupt bit
{
//Uart_Printf("Stylus Up Interrupt~!\n");
break; //if Stylus is up(1) state
}
}
Uart_Printf("count=%03d XP=%04d, YP=%04d\n", count++, xdata, ydata); //X-position Conversion data
if((xdata<Xmin)|(xdata>Xmax)|(ydata<Ymin)|(ydata>Ymax)) //谅钎蔼捞 裹困 救俊 甸绢坷瘤 臼栏搁
{ fail = 1;return; }
xdata =240*(Xmax-xdata)/(Xmax-Xmin); // X- Position
//ydata =320*(ydata-Ymin)/(Ymax-Ymin);
ydata =320*(ydata-Ymin)/(Ymax-Ymin);
temp =xdata;
xdata = ydata;
ydata = temp;
//Index阑 傈开函荐肺 棱绊 矫胶袍 鸥捞赣俊辑 捞蔼阑 炼荤窍咯 阿 Stage嘎绰 悼累
//角泅.
if(xdata>260 && ydata>30 && xdata<310 && ydata<60) Ts_Index=1;
if(xdata>260 && ydata>80 && xdata<310 && ydata<110) Ts_Index=2;
if(xdata>260 && ydata>130 && xdata<310 && ydata<160) Ts_Index=3;
if(xdata>260 && ydata>180 && xdata<310 && ydata<210) Ts_Index=4;
switch(Ts_Index)
{
case 1:
Lcd_PutString("1锅" ,10,40);
break;
case 2:
Lcd_PutString("2锅", 10,60);
break;
case 3:
Lcd_PutString("3锅", 10,80);
break;
case 4:
Lcd_PutString("4锅", 10,80);
break;
default:
break;
}
Uart_Printf(" XY-Position is (%04d,%04d)\n",xdata,ydata);
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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -