合泰单片机智能充电器AD转换程序HT46R47_ADC

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include "HT46R47-H.h"

extern void DelayNms(unsigned int ms);

unsigned int ADCStart(unsigned char chanl)

{

unsigned int k;

unsigned int adcbufL = 0;

unsigned int adcbufH = 0;

unsigned int adcdata = 0;

_eadi = 0; //disable interrupt

_adcr = 0x20|(0x07&chanl); //an0-an3 chanl=0x00,0x01,0x02,0x03 _acsr = 0x02; // fsys=4M 32分频Tad= 8us

_start = 0;

_start = 1;

_start = 0;

while(_eocb==1);

adcbufL = _adrl;

adcbufH = _adrh;

adcbufL = 0; //first time get out

adcbufH = 0;

DelayNms(1);

for(k=0;k<5;k++) //sample five times

{

_start = 0;

_start = 1;

_start = 0;

while(_eocb==1);

adcbufL = (unsigned int)(_adrl&0x01);

adcbufH = (unsigned int)_adrh;

adcdata += (unsigned int)((adcbufH<<1)+adcbufL);

DelayNms(1);

}

adcdata = adcdata/5;

_adcr = 0x00;

_acsr = 0x00;

return(adcdata);

}

相关文档
最新文档