本帖最后由 ZG11211 于 2014-2-17 20:21 编辑
大家都是新手成长起来的,给楼主看看我的ADC函数,酌情考虑是否有用,祝PIC粉丝们新年快乐!
/***********10位ADC*****************************************************/
unsigned int get_ad10(unsigned char n) //AD采样函数 n为通道号
{
unsigned int ad_data;
ADCON0 = (n<<2)|0x41; //Fosc/8, ADC使能,4M时钟需用F0sc/8, 最佳2us
//ADCON0 = (n<<2)|0x81; //Fosc/32,ADC使能,8M时钟需用F0sc/32,最佳4us
asm("nop"); //空操作延时 根据实际效果选择是否需要
asm("nop"); //空操作延时
GO_DONE = 1; //开始转换
while(GO_DONE); //等待转换结束
ad_data = ADRESH;//取高8位
ad_data =(ad_data << 2) + (ADRESL >> 6);//取10位时左对齐时使用,8位可//掉此指令
return (ad_data);
}
|