Undefined Identifier Error - Page 1
Forum section: electronics / general

author: radhika
author_rank: Regular Contributor
timestamp: December 04, 2018, 02:10:34 pm
content: 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/nMHh0xzCThanksAwaiting response.

author: rstofer
author_rank: Super Contributor
timestamp: December 04, 2018, 04:31:49 pm
content: 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.

author: radhika
author_rank: Regular Contributor
timestamp: December 04, 2018, 04:39:12 pm
content: no. its written for 18f4520.how do i define identifier in it?

author: rstofer
author_rank: Super Contributor
timestamp: December 04, 2018, 05:55:44 pm
content: 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.hhttp://digsys.upc.es/ed/CSD/units/Ch4/U4_06/pic18f4520.hNote 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.

author: TomS_
author_rank: Frequent Contributor
timestamp: December 04, 2018, 08:26:01 pm
content: 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?

author: rstofer
author_rank: Super Contributor
timestamp: December 04, 2018, 11:26:39 pm
content: Quote from: TomS_ on December 04, 2018, 08:26:01 pmThose 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.

author: radhika
author_rank: Regular Contributor
timestamp: December 05, 2018, 10:47:59 am
content: When I used that 18f4520.h from the link.I am getting this error.https://postimg.cc/3W1sRm7wHow do I solve this?

author: rstofer
author_rank: Super Contributor
timestamp: December 06, 2018, 12:42:59 am
content: 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!

author: radhika
author_rank: Regular Contributor
timestamp: December 07, 2018, 05:48:59 am
content: Quote from: rstofer on December 06, 2018, 12:42:59 amHello Sir,We make it runI 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:CCP1CON = 0; //Clear CCP1CON registerPR2 = 7; //7.4VCCPR1L = 3; //50% Duty CycleTRISCbits.TRISC2 = 0; //Make PWM pin an outputT2CON = 0x01; //Timer 2CCP1CON = 0x1C; //PWM Mode, 01 for DC1B1:DC1B2TMR2 = 0; //Clear Timer 2T2CONbits.TMR2ON = 1; //Turn ON Timer 2while(1){PIR1bits.TMR2IF = 0; //Clear Timer 2 Flagwhile (PIR1bits.TMR2IF == 0); //Wait for end of period}Here, is the attached header file. Please have a look

author: tsman
author_rank: Frequent Contributor
timestamp: December 07, 2018, 08:55:23 am
content: 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.

author: Wilksey
author_rank: Super Contributor
timestamp: December 07, 2018, 09:31:32 am
content: 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.