ADC conversion for PIC18F4550 problems

Discussion in 'Embedded Systems and Microcontrollers' started by tuanvoi, Jan 30, 2009.

  1. tuanvoi

    Thread Starter Active Member

    Oct 31, 2008
    56
    0
    Hi all,
    Could you help me find the errors for my code. When I use "Build all" in MPLAB v8.10, its showing me syntax errors. Here is my code:

    #include <p18F4550.h>
    #fuses HSPLL,USBDIV,PLL5,CPUDIV1,VREGEN,NOWDT,NOPROTECT,NOLVP,NODEBUG
    #use delay(clock=48000000)
    #use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8) // Configuration RS232 port

    void main() {
    //int16 Dat;
    int8 AN0_Value,AN1_Value,AN2_Value,AN3_Value;

    set_tris_a(0B00001111);
    set_tris_c(0B10111111);
    setup_adc_ports(ALL_ANALOG); // Asign Analog pin
    setup_adc(ADC_CLOCK_INTERNAL);


    While (1)
    {
    set_adc_channel(0); // Select Channel AN0
    //if(
    delay_us(10);
    AN0_Value = read_adc(); // Read adc channel 0
    set_adc_channel(1); // Select Channel AN1
    delay_us(10);
    AN1_Value = read_adc(); // Read adc channel 1
    set_adc_channel(2); // Select Channel AN2
    delay_us(10);
    AN2_Value = read_adc(); // Read adc channel 2
    set_adc_channel(3); // Select Channel AN3
    delay_us(10);
    AN3_Value = read_adc(); // Read adc channel 3
    // continue;
    }
    }

    And the errors showed:
    C:\Documents and Settings\Administrator\Desktop\tuanvoi\A2D.c:2:Error: syntax error

    Thank you a lot.
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Have you used MPLAB again? Did it work?
     
  3. tuanvoi

    Thread Starter Active Member

    Oct 31, 2008
    56
    0
    yes I've used MPLAB v8.10 and I've tried to complied it but showed me syntax error. Could you please resolve this mik3? Thank you
     
  4. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Have you ever used MPLAB before successfully?
     
  5. tuanvoi

    Thread Starter Active Member

    Oct 31, 2008
    56
    0
    Actually I'm newbie to MPLAB, I've used MPLAB to compile the demo code successfully and also follow the MPLAB manual. If there is anything that I need to learn more, please help me "mik3". Also, I've read the manual for CCS compiler C, but I don't quite understand that the functions in the manual is already built and we only need to use it like the above code or we have to write these functions. Thank you again "mik3".
     
  6. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Without knowing what version of C are you using its hard to know where you are going wrong but the error message indicates the your source file contains statements that the C compiler does not recognize as a valid C.

    I suspect that your syntax is wrong in the line that sets up the fuses. The pic18 has numerous fuse registers so you need to tell the the compiler the register name as well as the fuse value. Also the the various fuse values are normally "anded" (&) together.
     
  7. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Just one more thought, in MPLAB did you select the language and device type.
    Go to the menu Project > Select Language Suite and select your language then go to menu Configure > Select Device to select the device type.
     
  8. tuanvoi

    Thread Starter Active Member

    Oct 31, 2008
    56
    0
    I've followed the instructions, and did what you said AlexR, but still get the same errors.
    How do you specify the code Alberto?
    Could you please rewrite it? Thank you all!

    Tom
     
  9. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    The error message says the error is in line 2. The only thing that I can see is that you have a space in the NOLVP directive (written N OLVP) which should not be there.

    The error has nothing to do with the ADC. Your source file is named A2D.c thus the error message A2D.c:2:xxxxx
     
Loading...