触摸屏校准好了,可以使用了,想保存一下校准数据,数据也写入内部FLASH了,也能读出来了。问题也来了:读出的数据就是不对,触摸屏就是不能使用,除非再次校准,应该数据保存的时候出问题了,以下是这部分的代码,请高人帮我看一下,问题到底出在哪呀?我都要哭了。
struct
{
uint8_t CMD_RDX; //
uint8_t CMD_RDY; //
int16_t xoff; //
int16_t yoff; //
float xfactor; //
float yfactor; //
}Touchconfig; //结构变量保存的是触摸屏的参数
union myfloat //
{
uint16_t u[2];
float f;
};
union myint //两个联合体用来做数据变换
{
uint16_t u;
int16_t s;
};
union myfloat xfac,yfac; //联合变量定义
union myint xoff,yoff;
////////////////////////////////////////////////
......省略校准部分
xoff.s = Touchconfig.xoff;
yoff.s = Touchconfig.yoff;
xfac.f = Touchconfig.xfactor; //有符号数据复制到联合变量
yfac.f = Touchconfig.yfactor;
touch_save[0] = Touchconfig.CMD_RDX; //联合无符号数据复制到无符号数组
touch_save[1] = Touchconfig.CMD_RDY;
touch_save[2] = xoff.u;
touch_save[3] = yoff.u;
touch_save[4] = xfac.u[0];
touch_save[5] = xfac.u[1];
touch_save[6] = yfac.u[0];
touch_save[7] = yfac.u[1];
STMFLASH_Write(0,touch_save,8);//数据写入FLASH
////////////////////////////////////////////////////////////////////////////////
void Touch_Init(void)
{
uint16_t touch_save[8];
union myint xoff,yoff;
union myfloat xfac,yfac;
/*********初始化ADS7843*********/
TPCLK_CLR;
TPCS_SET;
TPDI_SET;
TPCLK_SET;
TPCS_CLR;
STMFLASH_EEPROM_Read(0,touch_save,8);//从FLASH读取数据
if((touch_save[0] == 0x00D0)||(touch_save[0] == 0x0090))//如果读取到这两个数据表示已经校准过触摸屏
{
Touchconfig.CMD_RDX = (uint8_t)(touch_save[0]<<8);
Touchconfig.CMD_RDY = (uint8_t)(touch_save[1]<<8);
xoff.u = touch_save[2];//数组数据复制给联合无符号数据
yoff.u = touch_save[3];
xfac.u[0]= touch_save[4];
xfac.u[1]= touch_save[5];
yfac.u[0]= touch_save[6];
yfac.u[1]= touch_save[7];
Touchconfig.xoff = xoff.s;//联合有符号数据复制到结构体
Touchconfig.yoff = yoff.s;
Touchconfig.xfactor = xfac.f;
Touchconfig.yfactor = yfac.f;
// Touchconfig.xfactor = (((u32)touch_save[4])<<16) + touch_save[5];
// Touchconfig.yfactor = (((u32)touch_save[6])<<16) + touch_save[7];
}
else touch_adj();//需要重新校准触摸屏
CLR_Screen(Blue); //清屏,退出触摸初始化
} |