Four-wire resistive touch screen sampling filtering algorithm C language code

Source: Internet
Author: User
Tags abs

Four-wire resistive touch screen sampling filter algorithm, practice proved very useful!
void Tsadcstart (void)//own implementation {}bool istsadcover (void)//own implementation {BOOL iRes; return iRes;}    U16 Tsadcgetx (void)//implementation {u16 ixphy = 0; return ixphy;}    U16 tsadcgety (void)//implementation {u16 iyphy = 0; return iyphy;}    void delayms (U32 t)//own implementation {}U32 Tsgetphycoord (void) {U8 i = 0;    U8 j = 0;    U16 Arrxphy[3] = {0};    U16 Arryphy[3] = {0};    U16 Arrmidxphy[2] = {0};    U16 Arrmidyphy[2] = {0};    U16 deltax = 0;     U16 DeltaY = 0; U32 ixyphy = 0;for (i=0; i<6; i++) {if (i = = 0) {delayms (5);//////////X, Y, 3 physical values as a set for (j=0; j<3; j + +) for first sampling             Tsadcstart (); Implement while (!   Istsadcover ()); own implementation Arrxphy[j] = Tsadcgetx (); own implementation Arryphy[j] = Tsadcgety ();    Implement it yourself if (j! = 2) {delayms (1);}} Remove the intermediate size values of a set of physical values arrxphy[1] = middle (arrxphy[0], arrxphy[1], arrxphy[2]); arryphy[1] = Middle (arryphy[0], arryphy[1], ARRYPHY[2]); if (I < 2)//record the first two groups get the median value {arrmidxphy[i] = arrxphy[1];arrmidyphy[i] = arryphy[1];} else//Record the median value (if necessary) after the first two groups {//move the 1th value of the array to the NO. 0 value so that the 1thValues can be stored in the new value arrmidxphy[0] = arrmidxphy[1];arrmidyphy[0] = arrmidyphy[1];           Deposit the new value at the 1th value of the array arrmidxphy[1] = arrxphy[1];arrmidyphy[1] = arryphy[1]; This code moves the value [1] to [0] each time, and then places the new value at [1]} if (i > 0) {deltax = arrmidxphy[0]-arrmidxphy[1];d Eltay = arrmidyphy[0]-Arrmid        YPHY[1]; if (ABS (deltax) >2 | | ABS (DeltaY) >2) {//If the initial two sets of sampled data are not required, continue sampling,//until the sampling meets the requirements or the maximum number of samples allowed to end sampling delayms (2); continue;} else{//sample results meet requirements, end this touch sampling break;}}        else{//after the first outer loop, the next cycle delayms (5) is to be carried out at intervals. }//for X, y two sets of physical intermediate values arrmidxphy[0] = (Arrmidxphy[0] + arrmidxphy[1]) >> 1;arrmidyphy[0] = (Arrmidyphy[0] + arrmidyphy [1]) >> 1;ixyphy = arrmidxphy[0];ixyphy <<= 16;ixyphy |= arrmidyphy[0];return ixyphy;}

Four-wire resistive touch screen sampling filtering algorithm C language code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.