2

初学者尝试学习 ADC 设置,但不幸的是,大多数在线示例都是针对其他 pic18 模型的,而且我没有 adc.h 定义作为资源。(或者不是 C 代码。)真的不想被灌输一个答案,但如果有人能建议一些很棒的演练、在线资源等。我真的很感激,谢谢!

此外,我编写的这个伪代码的任何帮助都会很棒。可能有错误......不知道我是否在正确的轨道上。

//configure port
    //disable pin output driver (TRIS) - same thing as clear?
    //configure pin as analog
//configure adc module
    //set ADC conversion clock
    // configure voltage reference
    //select adc input channel
        //CH0-CH12 of ADCON0
    // select result format
        //select data format using the ADFM bit of the ADCON1 register                                                 
           //select aquisition delay  
    // turn on ADC module
        //enable A/D converter by setting the ADON bit of the ADCON0 register                                                     
//start conversion by setting GODONE bit of ADCON0 register
    //GODONE = 1;

// read ADC result
    //read the ADRESH and ADRESL registers
//clear the adc interrupt flag (optional)
4

1 回答 1

0

还不完美,但大部分都弄明白了。休息应该不会太难。。现在主要是需要实现中断。

    TRISc = 0x01; // disable tri-state    
    ANSEL = 0xFF;//setting to analog
    ADCON1 = 0x00;//Voltage References Set
    ADCON2 = 0x00;// left justified ADFM, set Acquisition Time and Conversion Clock
    ADCON0 = 0x11;// Analog Channel Select, GODONE set, Enable ADC

    //TODO:interrupt ADIF bit in the PIR1 register
    ADIF = 0;
    ADIE = 1;
    GODONE = 1;
    while(GODONE) {};

    adcValue = ADRESH;
    adcValue <<= 8;
    adcValue |= ADRESL;

    while(1){}
于 2012-08-24T14:08:07.313 回答