1.1 µç×è´¥ÃþÆÁ½éÉÜ
1.1.1 ´¥ÃþÆÁ½éÉÜ
µç×èʽ´¥ÃþÆÁ£ºÐèҪУ׼£¬Ö»Äܵ¥µã´¥¿Ø£»¿¹¸ÉÈÅÄÜÁ¦±È½ÏÇ¿¡£ÊÊÓÃÓÚ¹¤Òµ²úÆ·¡£
µçÈÝʽ´¥ÃþÆÁ£º²»ÐèҪУ׼£¬Ö§³Ö¶àµã´¥¿Ø£»¿¹¸ÉÈÅÄÜÁ¦±È½Ï²î¡£ÊÊÓÃÓÚµç×ÓÏû·Ñ²úÆ·¡£
´¥ÃþIC£º´ø´¥Ãþ¹Ü½ÅµÄоƬ¡£
1.1.2 ʵÎï
´¥ÃþÆÁºÍLCDÆÁÊÇÁ½¸öÆ÷¼þ£¬µç·ÉÏûÓÐÈκÎÁªÏµ¡£
1.1.3 ½á¹¹
ÈçÉÏͼËùʾ£¬µç×è´¥ÃþÆÁÊÇÒ»¿é 4 ²ãµÄ͸Ã÷µÄ¸´ºÏ±¡Ä¤ÆÁ£¬´¥ÃþÆÁÓÉÁ½²ãËÜÁϱ¡Ä¤×é³É£¬¸÷±¡Ä¤²ãÉϾùÍ¿
ÓÐÒ»²ãµ¼µç½ðÊô£¨Í¨³£ÊÇÑõ»¯î÷Îý£©£¬ÖмäµÄ¿ÕÆø¼ä϶½«¶þÕß·Ö¿ª¡£ÈçÏÂͼËùʾ£¬ÍâÃæÁ½²ã°×É«µÄ£¬ÉÏÃæΪÈí
±¡Ä¤£¬ÏÂÃæ°×ɫΪ²£Á§»ù°å£¬ÖмäÁ½²ã·Ö±ðΪ X¡¢ Y Á½¸ö͸Ã÷µç¼«²ã¡£ÓÉÉÏͼ¿ÉÖª£¬µç×è´¥ÃþÆÁÔÚ×îÉÏÃæµÄ´¥
ÃþÆÁÊÇÈíµÄ£¬ËùÒÔÒ²³ÆΪÈíÆÁ£¨Ïà¶ÔÓÚµçÈÝ´¥ÃþÆÁΪӲÆÁ£©¡£
1.2 ´¥ÃþÆÁ»ñÈ¡×ø±êÔÀí
1.2.1 ʾÒâͼ
ÏÂÃæÕâ¸öʾÒâͼ¸ü±È½ÏÃ÷È·£ºÈç¹ûÓе㰴Ï£¬ÈçÏ£¬ X+Ϊ VDD£¬ X-Ϊ GND£¬ Y+Ϊ AD ת»¯£¬ Y-Ϊ¸ß×è״̬¡£ÕâÑù¿ÉÒÔ²â³ö´¥Ãþµã X ÖáµÄ AD Öµ¡£
1.2.2 µÈЧµç·
Èç¹ûÉÏÃ治̫Ã÷°×µÄ»°£¬ÔÙÀ´Ò»¸ö±È½Ï¼òÒ×Àí½âµÄ¡£µÈЧµç·ÈçÏÂËùʾ£¬µç×èʽ´¥ÃþÆÁ¹¤×÷µÄºËÐÄΪ£ºµ±
ÔÚ X ·½ÏòµÄµç¼«¶ÔÉÏÊ©¼Óһȷ¶¨µÄµçѹ£¬¶ø Y ·½Ïòµç¼«¶ÔÉϲ»¼Óµçѹʱ£¬ÔÚ X ƽÐеçѹ³¡ÖУ¬´¥µã´¦µÄµçѹֵ¿ÉÒÔÔÚ Y+(»ò Y-)µç¼«ÉÏ·´Ó³³öÀ´£¬Í¨¹ý²âÁ¿ Y+µç¼«¶ÔµØµÄµçѹ´óС£¬±ã¿ÉµÃÖª´¥µãµÄ X ×ø±êÖµ¡£Í¬Àí£¬µ±ÔÚ Y µç¼«¶ÔÉϼӵçѹ£¬¶ø X µç¼«¶ÔÉϲ»¼Óµçѹʱ£¬Í¨¹ý²âÁ¿ X+µç¼«µÄµçѹ£¬±ã¿ÉµÃÖª´¥µãµÄ Y ×ø±ê¡£ µÃµ½(X,Y)¾Í¿ÉÒԵõ½Ò»¸öµãµÄ×ø±êÖµÁË¡£
×¢Ò⣺ÎÒÃÇ´ËʱµÃµ½µÄXÖá×ø±êºÍYÖá×ø±ê¸úLCD×ø±êÓÐûÓйØϵ£¿
ûÓÐÈκÎÁªÏµ£¬ÎÒÃÇÐèҪΪËûÃǽ¨Á¢ÁªÏµ£¨Ð£×¼£©¡£
1.3 XPT2046½éÉÜ
XPT2046 ÊÇÒ»ÖÖµäÐ͵ÄÖð´Î±Æ½üÐÍÄ£Êýת»»Æ÷£¨SAR ADC£©£¬°üº¬Á˲ÉÑù/±£³Ö¡¢Ä£Êýת»»¡¢´®ÐпÚÊý¾ÝÊä³öµÈ¹¦ÄÜ¡£Í¬Ê±Ð¾Æ¬¼¯³ÉÓÐÒ»¸ö 2.5V µÄÄÚ²¿²Î¿¼µçѹԴ¡¢Î¶ȼì²âµç·£¬¹¤×÷ʱʹÓÃÍⲿʱÖÓ¡£ XPT2046 ¿ÉÒÔµ¥µçÔ´¹©µç£¬µçÔ´µçѹ·¶Î§Îª 2.7V¡« 5.5V¡£²Î¿¼µçѹֱֵ½Ó¾ö¶¨ ADC µÄÊäÈ뷶Χ£¬²Î¿¼µçѹ¿ÉÒÔʹÓÃÄÚ²¿²Î¿¼µçѹ£¬Ò²¿ÉÒÔ´ÓÍⲿֱ½ÓÊäÈë 1V¡« VCC ·¶Î§ÄڵIJο¼µçѹ£¨ÒªÇóÍⲿ²Î¿¼µçѹԴÊä³ö×迹µÍ£©¡£ X¡¢Y¡¢ Z¡¢ VBAT¡¢ Temp ºÍ AUX Ä£ÄâÐźž¹ýƬÄڵĿØÖƼĴæÆ÷Ñ¡Ôñºó½øÈë ADC£¬ ADC ¿ÉÒÔÅäÖÃΪµ¥¶Ë»ò²î·Öģʽ¡£Ñ¡Ôñ VBAT¡¢ Temp ºÍ AUX ʱ¿ÉÒÔÅäÖÃΪµ¥¶Ëģʽ£»×÷Ϊ´¥ÆÁÓ¦ÓÃʱ£¬¿ÉÒÔÅäÖÃΪ²î·Öģʽ£¬Õâ¿ÉÓÐЧÏû³ýÓÉÓÚÇý¶¯¿ª¹ØµÄ¼ÄÉúµç×è¼°ÍⲿµÄ¸ÉÈÅ´øÀ´µÄ²âÁ¿Îó²î£¬Ìá¸ßת»»×¼È·¶È¡£
1.3.1 ÔÀíͼ
1.3.2 ·â×°
1.3.3 ¹Ü½Å˵Ã÷
T_CS | chip select£¬´¥ÃþÆÁƬѡ¹Ü½Å£¬PC13£»½«´Ë¹Ü½ÅÀµÍ±íʾѡÔñ´¥ÃþоƬ¡£ |
T_CLK | seleve clock£¬Ê±Öӹܽţ¬PB0£»Ö÷»ú¿ØÖÆSTM32¿ØÖÆ£» |
T_PEN | ±ÊÖе¥¹Ü½Å£¬PB1£¬µÍµçƽÓÐЧ£»µ±´¥ÃþÆÁÓа´Ï²Ù×÷ʱ£¬T_PEN¶ÔÍâÊä³öµÍµçƽ£¬¿ÉÒÔ½ÓÉÏÀµç×èµ½STM32£¬Ð£²âµ½´Ë¹Ü½ÅÊä³öµÍµçƽʱ£¬ËµÃ÷Óд¥Ãþ²Ù×÷¡£ |
T_MOSI | master output seleve input£¬Ö÷»úÊä³ö´Ó»úÊäÈ룬 PF11£»Ö÷»ú×¼±¸Êý¾ÝµÄ¹Ü½Å¡£ |
T_MISO | master input seleve output £¬Ö÷»úÊäÈë´Ó»úÊä³ö£¬ PB2£»Ö÷»ú²ÉÑùÊý¾ÝµÄ¹Ü½Å¡£ |
1.3.4 ʱÐò
1.3.5 ÃüÁî
S £º Æðʼ룬¿ØÖÆ×ÖµÄÊ×λ±ØÐëÊÇ 1£¬¼´ S£½1¡£
A2\A1\A0 £ºµØַ룬ÓÃÀ´Ñ¡Ôñ²âÁ¿µÄλÖá£
001 £º²âÁ¿YÖá×ø±ê£»
101 £º²âÁ¿XÖá×ø±ê£»
MODE £º ģʽѡÔñ룬ÓÃÓÚÉèÖà ADC µÄ·Ö±æÂÊ¡£ MODE£½0£¬ÏÂÒ»´ÎµÄת»»½«ÊÇ 12 λģʽ£» MODE£½1£¬ÏÂÒ»´ÎµÄת»»½«ÊÇ 8 λģʽ ¡£·Ö±æÂÊÔ½¸ß¾«¶ÈÔ½¸ß¡£
SER/ DFR £º¿ØÖƲο¼Ô´Ä£Ê½£¬Ñ¡Ôñµ¥¶Ëģʽ£¨ SERDFR£½1£©£¬»òÕß²î·Öģʽ£¨ SER/DFR£½0£©¡£´¥ÃþÆÁÓ¦ÓÃÑ¡Ôñ²î·Öģʽ¡£
PD0 ºÍ PD1£ºÑ¡ÔñµôµçºÍÄÚ²¿²Î¿¼µçѹÅäÖõĹØϵ¡£
×ÛÉÏ£¬¿ÉÒԵõ½Á½¸ö²âÁ¿ÃüÁ
²âÁ¿XÖá×ø±ê£º1101 0000 = 0xD0¡£
²âÁ¿YÖá×ø±ê£º1001 0000 = 0x90¡£
1.4 ´¥ÃþÆÁУ׼ÔÀí
1.4.1 ×ø±êÂ˲¨
1£©½èÓðÂÔË»áÌøË®ÆÀ·Ö±ê×¼£ºÈ¡¶à¸ö·ÖÊý£¬È¥µô×î¸ßºÍ×îµÍ£¬È»ºóÇóƽ¾ù¡£
2£©»ñÈ¡Á½´Î×ø±ê£¬ÅжÏÕâÁ½¸ö×ø±êµÄ²îÖµÊÇ·ñÌ«´ó¡£
1.4.2 ÔÀí
ÀíÂÛÉÏ£¬¼ÙÈç´¥ÃþÆÁºÍLCDÆÁÄܹ»100%ÌùºÏ¶ÔÓ¦
Xlcd = Xad * 320/4096¡£
Ylcd = Yad * 480/4096¡£
µ«ÊÇÓÉÓÚ¹¤ÒÕ¡¢³ß´ç¡¢ÔµãµÈÔÒò£¬Êµ¼Ê²úÆ·ÖÐûÓа취×öµ½100%ÌùºÍ£¬ÐèҪͨ¹ýÈí¼þ¶ÔÕâÁ½¸ö×ø±ê½øÐÐÁªÏµ£¬Õâ¸ö¹ý³Ì¾ÍÊÇ´¥ÃþÆÁУ׼¡£
ÔÚXYD-M4¿ª·¢°åÉÏ£¬ÎÒÃǵÄLCDÆÁºÍ´¥ÃþÆÁËäȻûÓÐ100% ÌùºÍ£¬µ«ÊÇËûÃǵÄXÖáºÍYÖᶼ»¥Ïà³ÉÏßÐÔ¹Øϵ¡£
XlcdÊÇLCDÆÁÉÏij¸öµãµÄ×ø±ê£¬ÓÉÓÚÁ½¸öÆÁÌùºÏµÄ£¬ÔòÕâ¸öµã±Ø¶¨ºÍ´¥ÃþÆÁµÄij¸öµãÌùºÏµÄ¡£ÓÉÓÚLCDÆÁºÍ´¥ÃþÆÁ³ÉÏßÐÔ¹Øϵ£¨y=kx+b£©£»
ÎÒÃÇÒ»°ã¼ÙÉèËûÃǵÄÏßÐÔ¹ØϵΪ£º
Xlcd= k1*Xad + b1;
Ylcd= k2*Yad + b2;
ÆäÖÐXadºÍYadÊÇͨ¹ýXPT2046µÃµ½µÄAD×ø±ê¡£
XlcdºÍYlcdÊÇ´¥ÃþÆÁ¶ÔÓ¦µÄLCDÆÁµÄ×ø±ê¡£
Çó½â£º
Xlcd= k1*Xad + b1;
ÐèÒªµÃµ½ k1ºÍb1£¬ÐèÒªÁ½¸öµÈʽ¡£
Xlcd1= k1*Xad1 + b1;
Xlcd2= k1*Xad2 + b1;
µÃµ½£º
Xlcd2 - Xlcd1 = k1*£¨Xad2-Xad1£©
k1=£¨Xlcd2 - Xlcd1£©/£¨Xad2-Xad1£© //XÖá±ÈÀýϵÊý
b1=Xlcd1- Xad1*k1; //XÖáµÄÆ«ÒÆϵÊý
×¢Ò⣬ѡÔñ²Î¿¼µÄÁ½¸öµã¼ÆËãXÖáµÄ²ÎÊýµÄʱºò£¬ÕâÁ½¸öµãµÄLCD×ø±êµÄXÖá×ø±ê²»ÄÜÒ»Ñù
Ñ¡ÔñËĸöµã³É¾ØÐΣ¬¿ÉÒÔÀûÓþØÐεÄÌصã³õ²½ÅжÏÕâ4¸öµãÊÇ·ñºÏ¸ñ£¨Ð£×¼µÄÈËÊֲУ¬µã²»×¼£©¡£