Author Topic: Undefined Identifier Error  (Read 676 times)

0 Members and 1 Guest are viewing this topic.

Offline radhika

  • Regular Contributor
  • *
  • Posts: 75
  • Country: in
Undefined Identifier Error
« on: December 05, 2018, 01:10:34 am »
Hello,
I am working on a microcontroller PIC18F4520, I have added picture of it. I am using MPLAB IDE v9.92and CCS C Compiler.
I am getting undefined identifier issue.
How do I solve it and why I am getting it? Please advice and give me path that how do I approach it?
https://postimg.cc/nMHh0xzC
Thanks
Awaiting response. :)
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 5830
  • Country: us
Re: Undefined Identifier Error
« Reply #1 on: December 05, 2018, 03:31:49 am »
Maybe because the code was originally written for a 16F877A and the register names have been changed in the 18F4520?

The register names should be in that <18F4520.h> file or in a header file it includes.
 
The following users thanked this post: radhika

Offline radhika

  • Regular Contributor
  • *
  • Posts: 75
  • Country: in
Re: Undefined Identifier Error
« Reply #2 on: December 05, 2018, 03:39:12 am »
no. its written for 18f4520.
how do i define identifier in it?
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 5830
  • Country: us
Re: Undefined Identifier Error
« Reply #3 on: December 05, 2018, 04:55:44 am »
The comment in line 1 says 16F877A.  I know better than to rely on comments but it says what it says...

There are other header files besides the one you are using.
More registers are defined in the official Microchip header file:
pic18f4520.h

http://digsys.upc.es/ed/CSD/units/Ch4/U4_06/pic18f4520.h

Note that this file should not be included directly.  The comment says to include htc.h  and even then you would still have to find /peripheral/pconfig.h  I did notice that PORTAbits is defined in this file, I didn't pursue the other undefined symbols.

You're going to have to read the documentation for your compiler or find sample projects that are known to work with the compiler.

What you don't want to do is try to create your own header file.

Look through the subdirectories for your compiler and see what you find.  There is usually a header subdirectory and it usually has a LOT of files - most of which you don't care about.
 
The following users thanked this post: radhika

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 287
  • Country: gb
Re: Undefined Identifier Error
« Reply #4 on: December 05, 2018, 07:26:01 am »
I'd expect some things like PORTAbits and PORTBbits to be defined at the very least, that seems quite basic.

Perhaps the header file is empty? Have you checked that the things it claims are unidentified are actually in the header file?
 
The following users thanked this post: radhika

Online rstofer

  • Super Contributor
  • ***
  • Posts: 5830
  • Country: us
Re: Undefined Identifier Error
« Reply #5 on: December 05, 2018, 10:26:39 am »
I'd expect some things like PORTAbits and PORTBbits to be defined at the very least, that seems quite basic.

Perhaps the header file is empty? Have you checked that the things it claims are unidentified are actually in the header file?

Those bits ARE defined in a header file, just not the header file the OP is using.
I have no idea why he is using the header he is and I don't know whether he has the proper header.

A brief Google search turns up the header I referenced earlier, pic18f4520.h, and those bits are defined in that file.
 
I really think it will turn out to be as simple as including the proper header and dumping the one in the original code above.  If it turns out that the 18F4520.h (not PIC184520.h) is necessary then go ahead and include it along with PIC184520.h.
 
The following users thanked this post: TomS_, radhika

Offline radhika

  • Regular Contributor
  • *
  • Posts: 75
  • Country: in
Re: Undefined Identifier Error
« Reply #6 on: December 05, 2018, 09:47:59 pm »
When I used that 18f4520.h from the link.
I am getting this error.
https://postimg.cc/3W1sRm7w

How do I solve this?
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 5830
  • Country: us
Re: Undefined Identifier Error
« Reply #7 on: December 06, 2018, 11:42:59 am »
Google for this: 'ccs c compiler a device required before this line'

I notice that you don't have a target selected.  Does this matter?

Do you have the User Manual for ccs c?

Google is your friend!
 
The following users thanked this post: radhika

Offline radhika

  • Regular Contributor
  • *
  • Posts: 75
  • Country: in
Re: Undefined Identifier Error
« Reply #8 on: December 07, 2018, 04:48:59 pm »
Google for this: 'ccs c compiler a device required before this line'

I notice that you don't have a target selected.  Does this matter?

Do you have the User Manual for ccs c?

Google is your friend!

Hello Sir,
We make it run :)
I have used 18F4520.h header file of CCS C compiler.
But, as in the code i am using CCP1CON register for generating PWM. Can you guide me, what is the command for CCP1CON register in CCS C Compiler. I didn't get in header file.
Here is the code:
Code: [Select]
CCP1CON = 0;   //Clear CCP1CON register
            PR2 = 7;      //7.4V
            CCPR1L = 3;    //50% Duty Cycle
            TRISCbits.TRISC2 = 0;    //Make PWM pin an output
            T2CON = 0x01;            //Timer 2
            CCP1CON = 0x1C;          //PWM Mode, 01 for DC1B1:DC1B2
            TMR2 = 0;                //Clear Timer 2
            T2CONbits.TMR2ON = 1;    //Turn ON Timer 2
            while(1)
            {
            PIR1bits.TMR2IF = 0;     //Clear Timer 2 Flag
            while (PIR1bits.TMR2IF == 0);   //Wait for end of period
            }
Here, is the attached header file. Please have a look
 

Offline tsman

  • Frequent Contributor
  • **
  • Posts: 599
  • Country: gb
Re: Undefined Identifier Error
« Reply #9 on: December 07, 2018, 07:55:23 pm »
Your code and what CCS is expecting in that header file aren't the same.

All of the direct register manipulation in your code is handled by dedicated functions in your version of CCS. e.g. instead of setting the T2CON registers directly, there is a setup_timer_2() function that takes 3 arguments.

As this is code you've downloaded from somewhere, you need to find a compatible version for your CCS compiler or work out how to convert all of it yourself by looking at the documentation.
 
The following users thanked this post: radhika

Online Wilksey

  • Super Contributor
  • ***
  • Posts: 1148
Re: Undefined Identifier Error
« Reply #10 on: December 07, 2018, 08:31:32 pm »
The issue seems to be that you have downloaded some code from the internet and don't understand how to translate it to work with CCS C, or you don't know how to use CCS C.

Microchip header files will need tweaking before they can compile directly into CCS C, your "target" is unknown, I expect there is an IFDEF checking the header file is for the selected chip, as one isn't selected I doubt it can find it.

Not really much else to say about it.  :-//
 
The following users thanked this post: radhika


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf