打印
[PIC®/AVR®/dsPIC®产品]

PIC18F25K80用mplab x 调试ad程序读数不正常

[复制链接]
813|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
catfay226|  楼主 | 2017-4-19 20:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
PIC18F25K80用mplab x 调试ad程序读数不正常,基准电源设外部电压、内部电压、得到的值一直都是10以下的数据,请大神帮忙看下哪里出问题了,万分感谢
外部晶振8M,ad通道是AN0
主程序:
while (1)
    {
        // Add your application code
        Adresult=ADC_GetConversion(channel_AN0);//0V-5V  0-1024
        
        
        ledshan(Adresult);IO_RB2_SetHigh();delay500ms();
    }

子程序(是软件自动生成的):
adc_result_t ADC_GetConversion(adc_channel_t channel)
{
    // Select the A/D channel
    ADCON0bits.CHS = channel;

    // Turn on the ADC module
    ADCON0bits.ADON = 1;


    // Start the conversion
    ADCON0bits.GO_nDONE = 1;

    // Wait for the conversion to finish
    while (ADCON0bits.GO_nDONE)
    {
    }
   
    // Conversion finished, return the result

    return ((ADRESH << 8) + ADRESL);
}

初始化程序(系统自动生成的):
void PIN_MANAGER_Initialize(void)
{
    /**
    LATx registers
    */   
    LATA = 0x00;   
    LATB = 0x00;   
    LATC = 0x00;   

    /**
    TRISx registers
    */   
    TRISA = 0xEF;
    TRISB = 0xFB;
    TRISC = 0xFF;

    /**
    ANSELx registers
    */   
    ANCON0 = 0x1F;
    ANCON1 = 0x07;

    /**
    WPUx registers
    */
    WPUB = 0xFF;

   


   
   
}
void OSCILLATOR_Initialize(void)
{
    // SCS FOSC; HFIOFS not stable; IDLEN disabled; IRCF 8MHz_HF;
    OSCCON = 0x60;
    // SOSCGO disabled; MFIOSEL disabled; SOSCDRV Low Power;
    OSCCON2 = 0x00;
    // INTSRC INTRC; PLLEN disabled; TUN 0;
    OSCTUNE = 0x00;
    // ROSEL System Clock(FOSC); ROON disabled; ROSSLP Disabled in Sleep mode; RODIV Fosc;
    REFOCON = 0x00;
    // Set the secondary oscillator
   
}
void ADC_Initialize(void)
{
    // set the ADC to the options selected in the User Interface
   
    // GO_nDONE stop; ADON enabled; CHS AN0;
    ADCON0 = 0x01;
   
    // TRIGSEL ECCP1; VNCFG AVSS; VCFG internal_2.048V; CHSN AN0;
    ADCON1 = 0x21;
   
    // ADFM Right; ACQT 4_Tad; ADCS FOSC/8;
    ADCON2 = 0x91;
   
    // ADRESH 0;
    ADRESH = 0x00;
   
    // ADRESL 0;
    ADRESL = 0x00;
   
}
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

1

帖子

0

粉丝