CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Already define file header, but still "Undefined identi

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Already define file header, but still "Undefined identi
PostPosted: Tue Sep 16, 2008 3:52 am     Reply with quote

Hi Guys, I really need your help. I'm trying to write a WTD into my program, but I encountered "undefined identifier" error after compile.

I'm using PIC16F72

My program as below:

Code:
#include <16F72.h>
#fuses RC,WDT,PROTECT
#use delay(clock=4000000)

..
..
..
..

unsigned int cnt = 0;

main()
{
      STATUS &= 0x9F;
      PORTA   = 0;
      STATUS &= 0xBF;
      TMR0  = 96;
      cnt = 0;
     
      ADCON1  = 6;
      TRISA   = 0b11111011;
      TRISB   = 0b10000000;
      TRISC   = 0b00000000;
      STATUS &= 0x9F;
      ADCON0  = 0;
..
..
..

Errors are :

***Error12"WTD.c"Line 417(11,17): Undefined identifier STATUS
***Error12"WTD.c"Line 419(11,17): Undefined identifier STATUS
***Error12"WTD.c"Line 420(10,14): Undefined identifier TMR0
***Error12"WTD.c"Line 422(11,17): Undefined identifier ADCON0
***Error12"WTD.c"Line 430(11,17): Undefined identifier STATUS
***Error12"WTD.c"Line 431(12,18): Undefined identifier ADCON1

I can't find where goes wrongly.. Pls help. Thanks in advance : )
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 5:19 am     Reply with quote

The error message is very clear, you are using several variable names that the compiler doesn't know of.
What is in your 16F72.h? I don't know this file.
brett777_L



Joined: 16 Sep 2008
Posts: 7

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 7:19 am     Reply with quote

In PIC16F72, STATUS, TMR0, ADCON0 and ADCON1 are general & special registers.

So I define header file as
#include <16F72.h>

Is that because that file 16F72.h is out of date ? It seems impossible.

Please help.

Thanks a lot !
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 8:16 am     Reply with quote

The addresses of those registers are not in the 16F72.h file. If you want to use them in your code you need to use the #BYTE pre-processor directive:
Example
#BYTE STATUS = 0x03

I would create and include a "16F72.def" file with either all of the registers you need to use or just all the registers for that chip.

The #BYTE pre-processor directive is explained in the manual.
_________________
David
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 3:34 pm     Reply with quote

The standard CCS include files don't contain register names because CCS follows a different philosophy. Instead of writing to the registers CCS provides wrapper functions that are 'functionality based'.
Example, instead of:
Code:
ADCON1 = 6;
you write in CCS:
Code:
SETUP_ADC_PORTS(NO_ANALOGS);


This has several advantages:
- Easier to read and self documenting code (you don't have to explain each magic value in comments).
- Program at a 'higher' level.
- Register based bit-juggling is error prone.
- Changing to another processor with different register layout is easy, only changing the header file (and a few other minor things).
- Chip errata with work around functionality can often be added by the compiler without any changes to your code.

Given the #byte method as mentioned by DRH you can program the way you started but personally I think you are working inefficiently and you have bought the wrong compiler if this is what you want.
wayneosdias



Joined: 26 Nov 2007
Posts: 16

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 3:56 pm     Reply with quote

ckielstra wrote:
The standard CCS include files don't contain register names because CCS follows a different philosophy. Instead of writing to the registers CCS provides wrapper functions that are 'functionality based'


Is there a reference, aside from the compiler manual, outlining what these functions are actually doing?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 4:05 pm     Reply with quote

Yes, there is. Put the compiler in "symbolic" mode for the List file format.
Then compile a program. Look at the .LST file and see the results.
This shows exactly what the compiler is doing:
Code:
.................... setup_adc_ports(NO_ANALOGS);
0018:  BSF    ADCON1.PCFG0
001A:  BSF    ADCON1.PCFG1
001C:  BSF    ADCON1.PCFG2
001E:  BCF    ADCON1.PCFG3
wayneosdias



Joined: 26 Nov 2007
Posts: 16

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 4:23 pm     Reply with quote

PCM programmer wrote:
Yes, there is. Put the compiler in "symbolic" mode for the List file format.
Then compile a program. Look at the .LST file and see the results.
This shows exactly what the compiler is doing:
Code:
.................... setup_adc_ports(NO_ANALOGS);
0018:  BSF    ADCON1.PCFG0
001A:  BSF    ADCON1.PCFG1
001C:  BSF    ADCON1.PCFG2
001E:  BCF    ADCON1.PCFG3


Dont want to get flamed here, but I need to learn PIC assembly to find what the psuedocode is doing?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 4:34 pm     Reply with quote

Look in the A/D section of the PIC data sheet. It shows the PCFGx
bits are in the bottom 4 bits of the ADCON1 register:
Code:

REGISTER 17-2: ADCON1 REGISTER

 7      6     5   4     3      2      1      0 
ADFM  ADCS2   —   —   PCFG3  PCFG2  PCFG1  PCFG0


Then look in this table, which shows what the various combinations
of PCFGx bits will do, to setup the A/D:
Quote:
bit 3-0 PCFG3:PCFG0: A/D Port Configuration Control bits

You do need to know that "BSF" means "Bit Set" in the specified register.

From the table in the data sheet, setting all PCFGx bits =1 will make
all the A/D pins into digital i/o pins.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 4:56 pm     Reply with quote

Quote:
Dont want to get flamed here, but I need to learn PIC assembly to find what the psuedocode is doing?
I think I don't fully understand your question. A compiler generates assembly code, not pseudo code. What you see here is the actual generated code.

Most of the CCS functions are tiny wrapper functions for setting or reading a few registers. Most CCS functions don't get more complicated than the example given above, 4 assembly instructions.

I know assembly language is very low level but what kind of representation would you have liked to see in between the manual and the generated code? Can you tells us what that looks like because I don't know it and like to know about it.
wayneosdias



Joined: 26 Nov 2007
Posts: 16

View user's profile Send private message

PostPosted: Tue Sep 16, 2008 5:01 pm     Reply with quote

PCM programmer wrote:
Look in the A/D section of the PIC data sheet. It shows the PCFGx
bits are in the bottom 4 bits of the ADCON1 register:
Code:

REGISTER 17-2: ADCON1 REGISTER

 7      6     5   4     3      2      1      0 
ADFM  ADCS2   —   —   PCFG3  PCFG2  PCFG1  PCFG0


Then look in this table, which shows what the various combinations
of PCFGx bits will do, to setup the A/D:
Quote:
bit 3-0 PCFG3:PCFG0: A/D Port Configuration Control bits

You do need to know that "BSF" means "Bit Set" in the specified register.

From the table in the data sheet, setting all PCFGx bits =1 will make
all the A/D pins into digital i/o pins.


PCM thanks for the help thus far

As someone with exp in programming motorolla/freescale assembly I understand how to read an lst file and a uC data sheet.

I just think it is a bit backwards to attempt to write code in a C lang using a compiler that is marketed as a functional based compiler and offer little more than a simplistic overview of what the functions do. Then to understand the function Im attempting to use I must scrutinize the propriety assembly, if it actually compiles.

As an example, whenever I see an assembly command start w/a B, I immediatly think of branch, so I get sucked into trying to learn specific instruction set of whatever chip. Kind of makes wonder why Im using C.

Again, I sincerely thank you for taking time to answer my questions just ranting a bit
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Sep 17, 2008 5:21 pm     Reply with quote

drh wrote:
I would create and include a "16F72.def" file with either all of the registers you need to use or just all the registers for that chip.
I forgot to mention Chipedit.exe in the v4 compiler has a new feature for generating such a register include file. In Chipedit select your processor and then 'Registers / Make Include file'.

Chipedit.exe is downloadable from the CCS website in the IDEUTILS package (possibly the Command Line versions of the CCS compilers don't have download rights for this toolset?).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group