2012-08-23 2 views
2

초보자는 ADC 설정을 배우려고하지만, 불행히도 대부분의 온라인 예제는 다른 pic18 모델 용이며 리소스로서의 adc.h 정의가 없습니다. (그렇지 않으면 C 코드가 아닙니다.) 정말로 숟가락 먹이를 먹고 싶지는 않습니다. 누군가가 훌륭한 워크 스루, 온라인 리소스 등을 제안 할 수 있다면 정말 고맙겠습니다. 감사합니다!ADC에서 pic18f1xk22에 대한 설정

필자가 작성한 의사 코드에 대한 도움도 훌륭합니다. 오류가있을 가능성이 ... 내가 올바른 길을 가고 있는지 알지 못한다.

//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) 
+2

마이크로 칩 데이터 시트에는 모든 SFR 위치가 있으며 ADC에는 8 개의 레지스터 만 있습니다. 직접 'adc.h'를 수행 할 수 있습니다. 데이터 시트에는 C로 구현하기 쉬운 어셈블러 예제도 있습니다. 일부 코드를 시도해보고 작동하는지보십시오. –

답변

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){}