- 再也不做站长了
-
说明使用的一个网友发表的文件,提取了触摸屏部分
.h部分
#ifndef touch_H
#define touch_H
#define touch
#define CMD_RDY 0X90 //0B10010000即用差分方式读X坐标
#define CMD_RDX 0XD0 //0B11010000即用差分方式读Y坐标
#define TEMP_RD 0XF0 //0B11110000即用差分方式读Y坐标
#define ZLG7290 0x70
#define SubKey 0x01
#define SubCmdBuf 0x07
#define SubDpRam 0x10
#define ZLG7290I2C_frequence 25000
extern uint8 key;
extern uint8 key_value_renew; //按键中断标志
extern uint8 key_value_break; //按键中断标志
extern machine_work_state mystate;
//extern void __irq irq_EINT3(void);
#define CHX 0x90
#define CHY 0xD0
#define T_CS ((unsigned int)1<<17)
#define T_CLK ((unsigned int)1<<18)
#define T_DIN ((unsigned int)1<<16)
#define T_INT ((unsigned int)1<<30)
#define T_DOUT ((unsigned int)1<<2)
//#define TP_BUSY (1<<21)
#define TP_CLK_0 IO0CLR = IO0CLR | T_CLK
#define TP_CLK_1 IO0SET = IO0SET | T_CLK
#define TP_CS_0 IO0CLR = IO0CLR | T_CS
#define TP_CS_1 IO0SET = IO0SET | T_CS
#define TP_DIN_0 IO0CLR = IO0CLR | T_DIN
#define TP_DIN_1 IO0SET = IO0SET | T_DIN
#define TP_DOUT ( IO0PIN & T_DOUT )
#define TP_INT_IN ( IO0PIN & T_INT )
extern void Init_TouchPannel_Port(void);
//-----------------------------------------------------------------------
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//-----------------------------------------------------------------------
//-----------------------内部函数----------------------------------------
extern void WR_CMD(unsigned char cmd);
extern unsigned short RD_AD(void);
extern unsigned short Read_X(void);
extern unsigned short Read_Y(void);
//------------------------------------
extern void TP_GetAdXY(int *x,int *y);
extern unsigned char CheckTP_INT(void);
extern unsigned int touch_x_value;
extern unsigned int touch_y_value;
extern machine_work_state mystate;
#endif
.c部分
#include "config.h"
//#define SPI_REAL
//---------------------------------------------------------------
//---------------------------------------------------------------
//---------------------------------------------------------------
//------------ADS7843 GPIO Pin Config------------------------------------
//Write To ADS7843"s Pin
//-----------------------------------------------------------------------
//#define TP_IRQ (IO0PIN&TP_INT)//for check pressed
//---------------------------------------------------------
//-----------------------------------------------------------------------
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//-----------------------------------------------------------------------
//----------------------具体函数实现-------------------------------------
//---------------------------------------------------------
unsigned short xt,yt;//touch data fit LCD,adjusted!!!!!!
unsigned short xr,yr;//real touch data from ad
unsigned int touch_x_value;
unsigned int touch_y_value;
//---------------------------------------------------------
unsigned char CheckTP_INT(void)
{
return (IO0PIN&T_INT);
}
//-----------------------------------------------------------------------
void Init_TouchPannel_Port(void)
{
PINSEL0 &= ~(0x03 << (2 * 2)); //设置P0.2接GPIO Dout 液晶屏的数据输出引脚
IO0DIR &= ~(1 << 2); //dout 数据输入端
PINSEL1 &= ~(0x03 << (16 *2 - 32));
IO0CLR |= (1 << 16); // din 数据输出端
IO0SET |= T_DIN;
PINSEL1 &= ~(0x03 << (17 *2 - 32));
IO0CLR |= (1 << 17); //cs
IO0SET |= T_CS;
PINSEL1 &= ~(0x03 << (18 *2 - 32));
IO0CLR |= (1 << 18); //clk
IO0SET |= T_CLK;
PINSEL1 &= ~(0x03 << (30 *2 - 32));
IO0CLR &= ~(1 << 30); //int
IO0SET |= T_INT;
}
//------------------------------------------------------------
void WR_CMD(unsigned char cmd)
{
unsigned char i;
TP_CS_1;
TP_DIN_0;
TP_CLK_0;
TP_CS_0;
for(i=0;i<8;i++)
{
if(cmd&0x80) TP_DIN_1;
else TP_DIN_0;
TP_CLK_1;
cmd<<=1;
TP_CLK_0;
}
}
//---------------------------------------------------
unsigned short RD_AD(void)
{
unsigned short OutData=0;
unsigned char i;
TP_DIN_0;
TP_CLK_1;
for(i=0;i<12;i++)
{
OutData<<=1;
TP_CLK_0;
if(IO0PIN&T_DOUT)
OutData|=0x0001;
TP_CLK_1;
}
for(i=0;i<4;i++)
{
TP_CLK_1;
TP_CLK_0;
}
TP_CS_1;
return(OutData);
}
//---------------------------------------------------
unsigned short Read_X(void)
{
unsigned short OutData;
WR_CMD(CHX);
OutData=RD_AD();
return OutData;
}
//---------------------------------------------------
unsigned short Read_Y(void)
{
unsigned short OutData;
WR_CMD(CHY);
OutData=RD_AD();
return OutData;
}
//------------------------------------------------------
void TP_GetAdXY(int *x,int *y)
{
#define TIME 10 //循环读数次数 最大16次
unsigned char t=0,t1,count=0;
unsigned char X_EABLE=0,Y_EABLE=0;
unsigned short databuffer[TIME]={0,0,0,0,0,0,0,0,0,0};//数据组
unsigned short temp=0;
while(TP_INT_IN==0&&count<TIME)//循环读数
{
databuffer[count]=Read_X() ;
count++;
}
if(count==TIME)//一定要读到TIME次数据,否则丢弃
{
do//将数据X升序排列
{
t1=0;
for(t=0;t<count-1;t++)
{
if(databuffer[t]>databuffer[t+1])//升序排列
{
temp=databuffer[t+1];
databuffer[t+1]=databuffer[t];
databuffer[t]=temp;
t1=1;
}
}
}while(t1);
*x=(databuffer[TIME/2-1]+databuffer[TIME/2]+databuffer[TIME/2+1])/3;
X_EABLE=1;
}
count=0;
while(TP_INT_IN==0&&count<TIME) //循环读数TIME次
{
databuffer[count]=Read_Y();
count++;
}
if(count==TIME)//一定要读到TIME次数据,否则丢弃
{
do//将数据X升序排列
{
t1=0;
for(t=0;t<count-1;t++)
{
if(databuffer[t]>databuffer[t+1])//升序排列
{
temp=databuffer[t+1];
databuffer[t+1]=databuffer[t];
databuffer[t]=temp;
t1=1;
}
}
}while(t1);
*y=(databuffer[TIME/2-1]+databuffer[TIME/2]+databuffer[TIME/2+1])/3;
Y_EABLE=1;
}
}
//-----------------------------------------------------
//--------------------------------------------------------------------------------------
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//-----------------------------End of TouchPannel_ARM.H---------------------------------