µØÇø£ºÈ«¹ú
¸ü¶à³ÇÊÐ
ͨÐÐÖ¤ ×¢²á | µÇ¼ µÇ¼
Ê×Ò³ -> ¼¼Êõ½»Á÷ -> ARM¿ª·¢
XPT2046µÄ´¥ÃþÆÁÓ¦ÓÃ
  • ÈËÆø£º2257
  • »Ø¸´£º2
  • ÔÞ(0)
ÆÕͨ»áÔ±
×¢²á£º2018-01-14
µÇ¼£º2019-02-11


u16 touch_get_adval(u8 cmd)

{

u16 adval=0;

T_CS_L();

touch_delay(20); //¿ÉÒÔ²»ÓÃ

touch_send(cmd);

touch_delay(20); //¿ÉÒÔ²»ÓÃ

adval = touch_read();

T_CS_H();

 adval >>=3;

return (adval&0xFFF);

}


void touch_send(u8 cmd)

{

u8 i=0;

for(i=0;i<8;i++)

{

T_CLK_L();

touch_delay(20);

if( cmd&(0x80>>i) )  T_MOSI_H();

else                 T_MOSI_L();

T_CLK_H();

touch_delay(20);

}

}


u16 touch_read(void)

{

u8  i=0;

u16 dat=0;

for(i=0;i<16;i++)

{

T_CLK_L();

touch_delay(20);

T_CLK_H();

if( T_MISO_Read() )  dat |=0x8000>>i;

touch_delay(20);

}

return dat;

}


void touch_delay(u8 time)

{

while(time--);

}


11-08 09:29 »Ø¸´
ÆÕͨ»áÔ±
×¢²á£º2018-01-14
µÇ¼£º2019-02-11

¸½¼ÓһЩԴÂ룺

void touch_adjust(void)

{

u8 i=0;

char buff[30]={0};

const u16 lcd_val[4][2]={{20,20},{300,20},{20,460},{300,460}};

u16 ad_val[4][2]={0};

at24c02_read(Touch_Addr,(u8*)&touch_pemer,sizeof(touch_pemer));

if(touch_pemer.flag !=Touch_OK )

{

ADJUST:

for(i=0;i<4;i++)

{

LCD_Draw_Cross(lcd_val[i][x],lcd_val[i][y],RED);

while( touch_scan() ==0 ); //ûÓа´Ï£¬µÈ´ý°´Ï£¬Ïû¶¶

touch_get_xyadval(&ad_val[i][x],&ad_val[i][y]);

sprintf(buff,"x%d=%-4d;y%d=%-4d",i,ad_val[i][x],i,ad_val[i][y]);

LCD_String(50, 80+i*18,buff ,RED,WHITE);

printf("%s\r\n",buff);

while( T_PEN==0 );  //µÈ´ýËÉ¿ª

LCD_Draw_Cross(lcd_val[i][x],lcd_val[i][y],WHITE);

}

/* ÀûÓþØÐεÄÌØÐÔÅжÏ4У׼µãÊÇ·ñºÏ¸ñÄÜÓà */

if(   (abs(ad_val[0][y] -ad_val[1][y])> 100)  //ÅжÏÉÏÃæÒ»¸ùºáÏßƽÐÐÓÚXÖá

|| (abs(ad_val[2][y] -ad_val[3][y])> 100)  //ÅжÏÏÂÃæÒ»¸ùºáÏßƽÐÐÓÚXÖá

|| (abs(ad_val[0][x] -ad_val[2][x])> 100)  //ÅжÏ×ó±ßÒ»¸ùÊúÏßƽÐÐÓÚYÖá

|| (abs(ad_val[1][x] -ad_val[3][x])> 100)  //ÅжÏÓÒ±ßÒ»¸ùÊúÏßƽÐÐÓÚYÖá

|| (abs(ad_val[0][y] -ad_val[2][y])<3000)  //ÅжϾØÐεij¤ÊÇ·ñ̫С

|| (abs(ad_val[0][x] -ad_val[1][x])<3000)  //ÅжϾØÐεĿíÊÇ·ñÌ«¶Ì

)  

{

LCD_Clear(0,319,0,479,WHITE);  //ÇåÆÁ

goto ADJUST;  //ÖØÐÂУ׼

}

LCD_Clear(0,319,0,479,WHITE);  //ÇåÆÁ

touch_pemer.Xsca = ((float)lcd_val[1][x] - lcd_val[0][x])/((float)ad_val[1][x] - ad_val[0][x]);

touch_pemer.Xdev = lcd_val[1][x]- ad_val[1][x]*touch_pemer.Xsca;  

touch_pemer.Ysca = ((float)lcd_val[2][y] - lcd_val[0][y])/((float)ad_val[2][y] - ad_val[0][y]);

touch_pemer.Ydev = lcd_val[2][y]- ad_val[2][y]*touch_pemer.Ysca;

touch_pemer.flag =Touch_OK;

at24c02_write(Touch_Addr,(u8*)&touch_pemer,sizeof(touch_pemer));

}

}



11-08 09:28 »Ø¸´
ÄÚÈݼÓÔØÖС­¡­,ÇëÉÔºò£¡
·¢±í»Ø¸´
³Ðŵ×ñÊØÎÄÃ÷·¢Ìû£¬¹ú¼ÒÏà¹Ø·¨¹æ

ÊÖ»ú·ÃÎÊÂÛ̳

¸øTAÁôÑÔ
ÁôÑÔ