View previous topic :: View next topic |
Author |
Message |
Guest
|
Already define file header, but still "Undefined identi |
Posted: Tue Sep 16, 2008 3:52 am |
|
|
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
|
|
Posted: Tue Sep 16, 2008 5:19 am |
|
|
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
|
|
Posted: Tue Sep 16, 2008 7:19 am |
|
|
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
|
|
Posted: Tue Sep 16, 2008 8:16 am |
|
|
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
|
|
Posted: Tue Sep 16, 2008 3:34 pm |
|
|
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: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
|
|
Posted: Tue Sep 16, 2008 3:56 pm |
|
|
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
|
|
Posted: Tue Sep 16, 2008 4:05 pm |
|
|
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
|
|
Posted: Tue Sep 16, 2008 4:23 pm |
|
|
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
|
|
Posted: Tue Sep 16, 2008 4:34 pm |
|
|
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
|
|
Posted: Tue Sep 16, 2008 4:56 pm |
|
|
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
|
|
Posted: Tue Sep 16, 2008 5:01 pm |
|
|
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
|
|
Posted: Wed Sep 17, 2008 5:21 pm |
|
|
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?). |
|
|
|