ADS7846处理程序如下:
void ADS7846(void)
{
static unsigned char poscount=0; //测量坐标计数
static unsigned char r=0;
unsigned int x[6];
unsigned int y[6];
int xTemp=0,yTemp=0;
int x0,x1,x2,x3,x4,x5;
int y0,y1,y2,y3,y4,y5;
unsigned int xmin,xmax,ymin,ymax;
unsigned char i;
GpioDataRegs.GPFSET.bit.GPIOF9=1; //SPICE脚输出高电平,触摸屏的SPI口被选上
GpioDataRegs.GPFCLEAR.bit.GPIOF10=1; //SS脚输出电平拉低SS脚拉低这样经过138后选择TCS,即触摸片选为低电平
// Delay_1us(10);
Write7846(0xd0); //输入测量X坐标命令字
Delay_1us(30);
xpos[poscount]=Read7846();
Delay_1us(10);
Write7846(0x90); //输入测量Y坐标命令字
Delay_1us(30);
ypos[poscount]=Read7846();
Delay_1us(30);
GpioDataRegs.GPFSET.bit.GPIOF10=1; //SS脚拉高,导致TCS脚为高电平,即ADS7846没有被选上
poscount++;
if(poscount>6)
{
poscount=0;
x[0]=xpos[0]; x[1]=xpos[1]; x[2]=xpos[2]; x[3]=xpos[3]; x[4]=xpos[4]; x[5]=xpos[5];
y[0]=ypos[0]; y[1]=ypos[1]; y[2]=ypos[2]; y[3]=ypos[3]; y[4]=ypos[4]; y[5]=ypos[5];
x0=x[0];x1=x[1];x2=x[2];x3=x[3];x4=x[4];x5=x[5];
y0=y[0];y1=y[1];y2=y[2];y3=y[3];y4=y[4];y5=y[5];
xmin=x[0];xmax=x[0];ymin=y[0];ymax=y[0];
for(r=1;r<6;r++)
{
if(x[r]<xmin)
xmin=x[r];
if(x[r]>xmax)
xmax=x[r];
if(y[r]<ymin)
ymin=y[r];
if(y[r]>ymax)
ymax=y[r];
};
xTemp=(x0+x1+x2+x3+x4+x5-xmin-xmax)/4;
yTemp=(y0+y1+y2+y3+y4+y5-ymin-ymax)/4;
WriteLcd(0x46,1); //显示光标地址
WriteLcd(0x0000&0xff,0); //低八位光标地址
WriteLcd((0x0000>>8)&0xff,0); //高八位光标地址
WriteLcd(0x42,1);
for(i=0;i<4;i++)WriteLcd(0x00,0);
BtoOC_show(0x0000,xTemp);
WriteLcd(0x46,1); //显示光标地址
WriteLcd(0x0028&0xff,0); //低八位光标地址
WriteLcd((0x0028>>8)&0xff,0); //高八位光标地址
WriteLcd(0x42,1);
for(i=0;i<4;i++)WriteLcd(0x00,0);
BtoOC_show(0x0028,yTemp);
// pos_show(0x0000,xTemp);
// pos_show(0x0028,yTemp);
LCDX=5*xTemp;
LCDX>>=6; //x方向坐标=(320*xTemp)/4096
LCDY=15*yTemp;
LCDY>>=8; //y方向坐标=(240*yTemp)/4096
};
} |