need urgent help....PIC C lite

Discussion in 'Embedded Systems and Microcontrollers' started by riad_00, Apr 12, 2008.

  1. riad_00

    Thread Starter Member

    Feb 9, 2008
    19
    0
    Hi,

    I m trying to learn pic c lite. Here is a simple program to flash a LED.

    HTML:
    1.  
    2. #include <pic.h>
    3. _CONFIG(FCMDIS & IESODIS & BORDIS & UNPROTECT
    4.   &
    5.   MCLRDIS &PWRTEN WDTDIS & INTIO);
    6.    
    7.    int i;
    8.    
    9.    main()
    10.    {
    11.        PORTA = 0;
    12.        CMCON0 = 0;
    13.        ANSEL = 0;
    14.        TRISA4 = 0;
    15.        TRISA5 = 0;
    16.        while (1=1)
    17.        {
    18.            for i=0; i<25000; i++;
    19.            RA4 = RA4^1;
    20.            
    21.         }
    22.        
    23.    }
    24.  
    And the output for the program is given below.

    HTML:
    1.  
    2.  
    3. Build E:\New Folder\flash for device 16F84
    4. Using driver C:\Program Files\HI-TECH Software\PICC\LITE\9.60\bin\picl.exe
    5.  
    6. Executing: "C:\Program Files\HI-TECH Software\PICC\LITE\9.60\bin\picl.exe" -C "E:\New Folder\flash.c" --chip=16F84 -P --opt=default -q -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
    7. Error   [194] E:\New Folder\flash.c; 2.16 ")" expected
    8. Warning [349] E:\New Folder\flash.c; 4.32 non-prototyped function declaration for "_CONFIG"
    9. Error   [313] E:\New Folder\flash.c; 4.32 function body expected
    10. Error   [192] E:\New Folder\flash.c; 11.1 undefined identifier "CMCON0"
    11. Error   [192] E:\New Folder\flash.c; 12.1 undefined identifier "ANSEL"
    12. Error   [192] E:\New Folder\flash.c; 14.1 undefined identifier "TRISA5"
    13. Error   [202] E:\New Folder\flash.c; 15.11 only lvalues may be assigned to or modified
    14. Error   [317] E:\New Folder\flash.c; 17.5 "(" expected
    15. Error   [195] E:\New Folder\flash.c; 17.6 expression syntax
    16. Error   [194] E:\New Folder\flash.c; 17.22 ")" expected
    17.  
    18. ********** Build failed! **************
    19.  
    20.  
    Can some body tell me plz what I am doing wrong here !!!!
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    You might try these minor changes.

    hgmjr
     
  3. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    oh yeah! And this change also.

    hgmjr
     
  4. riad_00

    Thread Starter Member

    Feb 9, 2008
    19
    0
    I have tried the corrected code but didn't work. Here is the result again,

    HTML:
    1.  
    2. #include <pic.h>
    3. _CONFIG(FCMDIS & IESODIS & BORDIS & UNPROTECT
    4.   &
    5.   MCLRDIS &PWRTEN WDTDIS & INTIO);
    6.  
    7.    int i;
    8.  
    9.    main(void)
    10.    {
    11.        PORTA = 0;
    12.        CMCON0 = 0;
    13.        ANSEL = 0;
    14.        TRISA4 = 0;
    15.        TRISA5 = 0;
    16.        while (1)                  /* <----------  */
    17.       {
    18.           for i=0; i<25000; i++;
    19.           RA4 = RA4^1;
    20.  
    21.        }
    22.  
    23.    }
    24.  
    25.  
    Output....

    HTML:
    1.  
    2. Build C:\New Folder\flash for device 16F84
    3. Using driver C:\Program Files\HI-TECH Software\PICC\LITE\9.60\bin\picl.exe
    4.  
    5. Executing: "C:\Program Files\HI-TECH Software\PICC\LITE\9.60\bin\picl.exe" -C "C:\New Folder\flash.c" --chip=16F84 -P --opt=default -q -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"
    6. Error   [194] C:\New Folder\flash.c; 2.16 ")" expected
    7. Warning [349] C:\New Folder\flash.c; 4.32 non-prototyped function declaration for "_CONFIG"
    8. Error   [313] C:\New Folder\flash.c; 4.32 function body expected
    9. Error   [192] C:\New Folder\flash.c; 11.1 undefined identifier "CMCON0"
    10. Error   [192] C:\New Folder\flash.c; 12.1 undefined identifier "ANSEL"
    11. Error   [192] C:\New Folder\flash.c; 14.1 undefined identifier "TRISA5"
    12. Error   [317] C:\New Folder\flash.c; 17.5 "(" expected
    13. Error   [195] C:\New Folder\flash.c; 17.6 expression syntax
    14. Error   [194] C:\New Folder\flash.c; 17.22 ")" expected
    15.  
    16. ********** Build failed! **************
    17.  
    18.  

    I don't know what to do now !!!:(
     
  5. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    change your config macro to...

    Code ( (Unknown Language)):
    1. __CONFIG( FCMDIS & IESODIS & BORDIS & UNPROTECT & MCLRDIS & PWRTEN & WDTDIS & INTIO );
     
  6. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Read your error report! It tell you that the compiler knows nothing about various register names. This implies that you need to include a header file that is specific to the PIC you are using and contains definitions of register names and addresses.
    Once you get the program to compile you can sort out your pragma fuse setting command which has a couple of typos in it. Also if you want to see the LED blink you will need to add some sort of delay in the toggle loop.

    I just followed my own advice and had a close look at your error report.
    It says that its compiling code for a PIC16F84!
    The 16F84 does not have an ANSEL register and although I've not checked I suspect that neither does it have the other registers that the compiler is complaining about.
     
  7. riad_00

    Thread Starter Member

    Feb 9, 2008
    19
    0
    Thanks for the replies,

    HTML:
    1.  
    2. #include <pic.h>
    3. __CONFIG( FCMDIS & IESODIS & BORDIS & UNPROTECT & MCLRDIS & PWRTEN & WDTDIS & INTIO );
    4.  
    5.    int i;
    6.  
    7.    main(void)
    8.    {
    9.        PORTA = 0;
    10.        
    11.        TRISA = 0;
    12.        
    13.        while (1)                  /* <----------  */
    14.       {
    15.           for i=0; i<25000; i++;     /* Error
    16.             {
    17.                 RA4 = RA4^1;
    18.             }
    19.        }
    20.  
    21.    }
    22.  
    The error it's showing up there. But this is the right format (for i=0; i<25000; i++; ) isn't!!!
     
  8. Caveman

    Active Member

    Apr 15, 2008
    471
    0
    Come on guys. The right format is:
    Code ( (Unknown Language)):
    1. for(i=0;i<25000;i++);
    This creates a spin delay.
     
  9. Maximus Byamukama

    New Member

    Sep 9, 2008
    1
    0
    what is the aim of this code? are you just trying to flash a LED or you are trying to flash a LED the hard way?!! what is wrong with something as simple as this:

    #include <htc.h>
    #include <pic.h>
    #include <delay.c>

    void Wait_A_Second(void)
    {
    int j;
    for(j=1;j<=4;j++)
    {
    DelayMs(250);
    }
    }

    main()
    {
    TRISB=0; // port b is output, you can use A if u want

    for(;;)//do forever
    {
    RB0=0;
    Wait_A_Second();
    RB0=1;
    Wait_A_Second();
    }
    }// end main
     
    Last edited: Sep 9, 2008
  10. danielottosen

    New Member

    Mar 26, 2009
    1
    0
    Assuming you're (or were) very new to c and PICs, just like me, you've probably wanted to get started just like me and got the same problem:

    You have selected the flash code from the examples on the PicKit CD and try to build your own project. That code is for 16F684 and if your PIC is e.g. 16F84 the header pic.h redirects to (pic 1684.h) does not contain a CMCON0, but lots of other thingies, so you have to find the corresponding one to build you project.

    I'm using a 16F690 and try to compile with the Hi-Tech compiler, which doesnt have a PIC16F690.h header available so I guess it uses the PIC16F6x.h, am I right?

    edit: it uses pic16F685.h. For you other newcomers: Look in the pic.h to see which header file it redirects to for you very PIC.

    Comparing the two enormous data sheets of the PIC in the example (16F684) and my 16F690, I found that C1ON and C2ON = 0 did the same job for the 16F690 as the CMCON0 = 0 did for the 16F684.
     
    Last edited: Mar 29, 2009
  11. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Daniel, you've pulled up a thread that's been dead for six months. Doubtful that the OP is still "listening".

    You should start your own thread to avoid confusion.
     
Loading...