adc not work pic18f2550/4550

2013-08-20
2013-09-04
  • alexrlopez86

    alexrlopez86 - 2013-08-20

    adc not work pic18f2550/4550 tested with the following code sdcc 19 August and 20 August

    code:

    include pic18fregs.h

    include adc.h

    include pic18f4550.h

    typedef unsigned int config;
    config at 0x2007 CONFIG = _HS_OSC & _WDT_OFF & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _DEBUG_OFF & _CP_OFF;

    unsigned int adc1;

    define GO ADCON0bits.GO

    int LeerADC (int c){
    switch(c) {
    case 1:
    ADCON0=0b01000001; //RA0 AN0
    break;
    case 2:
    ADCON0=0b01001001; //RA1 AN1
    break;
    case 3:
    ADCON0=0b01010001; //RA2 AN2
    break;
    case 4:
    ADCON0=0b01100001; //RA5 AN4
    break;
    }
    GO=1;
    while(GO==0);
    return ADRESH;
    }

    void main(void)
    {
    TRISA = 0xff;
    TRISB = 0x00; // Set port B as all outputs
    ADCON2=0b00110110;
    ADCON1=0b00000001;
    //while(1)
    {
    adc1=LeerADC(1);

    PORTB = adc1;
    //delay_ms(2);
    
    }
    

    }

    I hope your help

     
    Last edit: alexrlopez86 2013-08-20
    • vloki

      vloki - 2013-09-04

      while(GO==0); ???

       
  • Diego Herranz

    Diego Herranz - 2013-09-04

    if you use #include <pic18fregs.h>, you don't need to #include <pic18f4550.h>. You just need to compile specifying the PIC model (-mpic16 -p18f4550).

    By the way, why not using the sdcc built-in library for PIC's ADC?

    #include <adc.h>
    adc_open(...
    adc_setchannel(...
    adc_read(...
    ...

     
    Last edit: Diego Herranz 2013-09-04

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks