资 源 简 介
#include
volatile unsigned char adresult;
void ADC_Sample(unsigned char adch);
void DelayXms(unsigned char x);
#define _DEBUG //调试程序用
/**********************************************************
函数名称:AD_Sample
函数功能:AD检测
入口参数:adch - 检测通道
出口参数:无
备 注:采样通道需自行设置为模拟口
采样10次,取中间八次的平均值为采样结果存于adresult中
**********************************************************/
void ADC_Sample(unsigned char adch)
{
static unsigned int adsum = 0;
static unsigned char admin = 0,admax = 0;
static unsigned char adtimes = 0;
ADCON1 = 0; //左对齐
ADCON0 = 0X41 | (adch << 2); //16分频
asm("nop");
asm("nop");
GODONE = 1; //开始转换
unsigned char i = 0;
while(GODONE)
{
if(0 == (--i))
return;
}
if(0 == admax