{"id":2609,"date":"2019-06-10T02:21:37","date_gmt":"2019-06-10T02:21:37","guid":{"rendered":""},"modified":"2019-06-10T10:22:02","modified_gmt":"2019-06-10T02:22:02","slug":"stc%e5%8d%95%e7%89%87%e6%9c%baadc%e9%87%87%e6%a0%b7%e7%a8%8b%e5%ba%8f%e8%ae%be%e8%ae%a1","status":"publish","type":"post","link":"http:\/\/www.szryc.com\/?p=2609","title":{"rendered":"STC\u5355\u7247\u673aADC\u91c7\u6837\u7a0b\u5e8f\u8bbe\u8ba1"},"content":{"rendered":"

\n\t#include“STC12C4052AD.h”<\/p>\n

\n\ttypedefstruct<\/p>\n

\n\t <\/div>\n

\n\t{<\/p>\n

\n\tBOOLRun;\/\/BOOL\u91cf\u4f5c\u4e3a\u5b9a\u65f6\u91c7\u6837\u6807\u5fd7\uff0c\u6bd4\u5982\u6bcf\u96943\u79d2\uff0c\u7f6e\u4f4d\u4e00<\/p>\n

\n\t\u6b21\u8be5\u6807\u5fd7<\/p>\n

\n\tBYTE<\/u>Curch;\/\/\u5f53\u524d\u901a\u9053<\/p>\n

\n\tBYTEtempCvData\uff3b6\uff3d;\/\/\u8f6c\u6362\u7ed3\u679c\u4e34\u65f6\u7f13\u51b2<\/p>\n

\n\tBYTECvTi<\/u>mes;\/\/\u91c7\u6837\u6b21\u6570\u91c7\u68374\u6b21\uff0c\u53bb\u6700\u5927\u6700\u5c0f\uff0c\u4fdd\u75594\u4e2a\u53d6\u5e73\u5747\u503c<\/p>\n

\n\tBYTEADData\uff3bMAX_ADC<\/u>H\uff3d;\/\/MAX_ADCH\u4fdd\u5b58\u5404\u901a\u9053\u6700\u7ec8\u91c7\u6837\u6570\u636e<\/p>\n

\n\t\"STC\u5355\u7247\u673aADC\u91c7\u6837\u7a0b\u5e8f\u8bbe\u8ba1\"<\/p>\n

\n\t}STADC;<\/p>\n

\n\tSTADCADC;<\/p>\n

\n\tvoidInitADC\uff08\uff09<\/p>\n

\n\t{<\/p>\n

\n\tUint16i;<\/p>\n

\n\tADC_CONTR=0xC0;\/\/ADC\u6a21\u5757\u52a0\u7535\uff0c420\u5468\u671f\u8f6c\u6362\u4e00\u6b21<\/p>\n

\n\tfor\uff08i=0;i\u300a20000;i++\uff09;\/\/ADC\u7535\u6e90\u5f00\u542f\u540e\uff0c\u5ef6\u65f6<\/p>\n

\n\t\/\/\u8bbe\u7f6eP\u53e3\u5916AD\u6a21\u5f0f<\/p>\n

\n\tP1M0=0x03;\/\/ADC0\/1\u9ad8\u963b\u8f93\u5165<\/p>\n

\n\tP1M1=0x00;<\/p>\n

\n\tEADC_SPI<\/u>=1;\/\/\u5f00\u653eADCSPI\u603b\u4e2d\u65ad<\/p>\n

\n\tADC_DATA=0;<\/p>\n

\n\tAUXR=EADCI;\/\/\u5f00\u653eADC\u4e2d\u65ad<\/p>\n

\n\tMEMSet\uff08&ADC\uff0c0\uff0csizeof\uff08STADC\uff09\uff09;<\/p>\n

\n\t\/\/\u542f\u52a80\u53f7\u901a\u9053<\/p>\n

\n\tADC.Curch=0;<\/p>\n

\n\tADC_CONTR|=ADC.Curch;\/\/\u8bbe\u7f6e\u4e0b\u4e00\u901a\u9053<\/p>\n

\n\tADC.Run=TRUE;\/\/\u6807\u5fd7ADC\u6b63\u5728\u8f6c\u6362<\/p>\n

\n\tADC_CONTR|=ADC_START;\/\/\u542f\u52a8AD\u8f6c\u6362\u5668<\/p>\n

\n\t}<\/p>\n

\n\tvoidADCISR\uff08\uff09interruptADC_VECTOR<\/p>\n

\n\t{<\/p>\n

\n\tADC_CONTR&=ADC_STOP;\/\/stopAD<\/u><\/p>\n

\n\tADC.Run=FALSE;<\/p>\n

\n\tADC.tempCvData\uff3bADC.CvTImes\uff3d=ADC_DATA;\/\/\u53d6\u8f6c\u6362\u503c<\/p>\n

\n\tADC_DATA=0;<\/p>\n

\n\tADC.CvTImes++;<\/p>\n

\n\tADC.CvTImes%=6;<\/p>\n

\n\tif\uff08ADC.CvTImes\uff01=0\uff09<\/p>\n

\n\t{<\/p>\n

\n\tADC_CONTR|=ADC_START;\/\/\u542f\u52a8AD\u8f6c\u6362\u5668<\/p>\n

\n\tADC.Run=TRUE;<\/p>\n

\n\t}<\/p>\n

\n\tADC_CONTR&=ADC_FLAG;\/\/\u6e05\u9664ADC_FLAG\u4e2d\u65ad\u6807\u5fd7<\/p>\n

\n\t}<\/p>\n

\n\tvoidProc_ADC\uff08\uff09<\/p>\n

\n\t{<\/p>\n

\n\tUint16CvSum=0\uff0ci;<\/p>\n

\n\tBYTEMaxCv=0\uff0cMi<\/u>nCv=0;<\/p>\n

\n\tif\uff08ADC.Run||ADC.CvTimes\uff01=0\uff09\/\/AD\u8fd8\u5728\u8fdb\u884c\uff0c\u7b49\u5f85<\/p>\n

\n\treturn;<\/p>\n

\n\tfor\uff08i=0;i\u300a6;i++\uff09<\/p>\n

\n\t{<\/p>\n

\n\tif\uff08ADC.tempCvData\uff3bi\uff3d\u300bMaxCv\uff09<\/p>\n

\n\tMaxCv=ADC.tempCvData\uff3bi\uff3d;<\/p>\n

\n\tif\uff08ADC.tempCvData\uff3bi\uff3dMinCv=ADC.tempCvData\uff3bi\uff3d;<\/p>\n

\n\t}<\/p>\n

\n\tfor\uff08i=0;i\u300a4;i++\uff09<\/p>\n

\n\tCvSum+=ADC.tempCvData\uff3bi\uff3d;<\/p>\n

\n\tCvSum=CvSum-MaxCv-MinCv;<\/p>\n

\n\tADC.ADData\uff3bADC.Curch\uff3d=\uff08CvSum\u300b\u300b2\uff09;<\/p>\n

\n\tADC.Curch++;<\/p>\n

\n\tADC.Curch%=MAX_ADCH<\/p>\n

\n\tADC_CONTR&=0xF8;\/\/\u5148\u6e05\u9664\u5f53\u524d\u901a\u9053\u503c<\/p>\n

\n\tADC_CONTR|=ADC.Curch;\/\/\u8bbe\u7f6e\u4e0b\u4e00\u901a\u9053<\/p>\n

\n\tADC.Run=TRUE;\/\/\u6807\u5fd7ADC\u6b63\u5728\u8f6c\u6362<\/p>\n

\n\tfor\uff08i=0;i\u300a500;i++\uff09;\/\/\u901a\u9053\u5207\u6362\u5ef6\u65f6100us\u5de6\u53f3<\/p>\n

\n\tADC_CONTR|=ADC_START;\/\/\u542f\u52a8AD\u8f6c\u6362\u5668<\/p>\n

\n\t}<\/p>\n","protected":false},"excerpt":{"rendered":"

#includeSTC12C4052AD.h typedefstruct { BOOLRun;\/\/BOOL\u91cf\u4f5c\u4e3a\u5b9a\u65f6\u91c7\u6837\u6807\u5fd7\uff0c\u6bd4\u5982\u6bcf\u96943\u79d2\uff0c\u7f6e\u4f4d\u4e00 \u6b21\u8be5\u6807\u5fd7 BY TE Curch;\/\/\u5f53\u524d\u901a\u9053 BYTEtempCvData\uff3b6\uff3d;\/\/\u8f6c\u6362\u7ed3\u679c\u4e34\u65f6\u7f13\u51b2 BYTECv Ti mes;\/\/\u91c7\u6837\u6b21\u6570\u91c7\u68374\u6b21\uff0c<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"_links":{"self":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts\/2609"}],"collection":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2609"}],"version-history":[{"count":0,"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts\/2609\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2609"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}