View previous topic :: View next topic |
Author |
Message |
ads
Joined: 09 May 2020 Posts: 11
|
Finding Declaration of a Function |
Posted: Sun May 17, 2020 2:20 pm |
|
|
Hi I want to find declaration for a function
When I right click and select find declaration it doesn't open it in a new page.
I want to see the function. Is there a way to see this. (Because there is a problem with this code I want to rewrite it in my main library to try something but I need to learn how it works.) Thank you for reading. Have a nice day. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sun May 17, 2020 2:47 pm |
|
|
I'd dump the listing... it'll be there.
Obviously cut a SMALL program......
Jay |
|
|
ads
Joined: 09 May 2020 Posts: 11
|
|
Posted: Sun May 17, 2020 2:55 pm |
|
|
I didn't understand what you mean by "I'd dump the listing... it'll be there."
My question is how to find a declaration do you know sir ? |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Sun May 17, 2020 2:59 pm |
|
|
I'm not sure you'll be able to see it all. To us, the users, #use (whatever) is short and easy. To support this simplicity will require quite a bit of "behind the scenes" support/code.
Anyway, if you "open all files", near the top of the processor .h file you'll see a #nolist line. Comment that out, then recompile. Open the c/assembly list file and any previously hidden code will now be there, in its entirety.
Good luck. Question: do you suspect that the compiler is generating code that has a mistake/bug? |
|
|
ads
Joined: 09 May 2020 Posts: 11
|
|
Posted: Sun May 17, 2020 3:43 pm |
|
|
Okey sorry for not being clear let me explain myself again. For example;
Lets assume I am trying to learn how this code works:
Code: | #use rs232(baud=2400, xmit=0, stop=1, parity=n) |
Normally in another compiler like KEIL or another I would right click on it and it sends me to its declaration. But in CCS C I couldn't find any. I only found that
header file of 12F1822.h there is no .c file. I didn't state my whole problem because I know the problem is because of my compiler version. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1345
|
|
Posted: Sun May 17, 2020 4:52 pm |
|
|
ads wrote: | Okey sorry for not being clear let me explain myself again. For example;
Lets assume I am trying to learn how this code works:
Code: | #use rs232(baud=2400, xmit=0, stop=1, parity=n) |
Normally in another compiler like KEIL or another I would right click on it and it sends me to its declaration. But in CCS C I couldn't find any. I only found that
header file of 12F1822.h there is no .c file. I didn't state my whole problem because I know the problem is because of my compiler version. |
I think you are misunderstanding what #use is. In C this is referred to as a preprocessor directive. It isn't a function, so there isn't going to be a declaration. It's a command to the compiler. In this case, it tells the compiler to setup the proper registers to use the PWM for you.
Anytime you see a statement starting with a '#', it is for the preprocessor. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sun May 17, 2020 5:05 pm |
|
|
re: 'dump the listing'....
After you comple your program, look in the folder and file the 'project.lst' file. That is the listing, the program ,listed ,line by line in machine code,with whatever comments, etc. Just look for the #use.....and there will be the code. |
|
|
ads
Joined: 09 May 2020 Posts: 11
|
|
Posted: Sun May 17, 2020 6:14 pm |
|
|
Thanks a lot for your answers. What I just want to see definitions of functions
Quote: | I think you are misunderstanding what #use is. In C this is referred to as a preprocessor directive. |
Sorry you are right I am not so familiar with programming. But I can't find this function either which is ;
"setup_timer_1(T1_DISABLED);"
Quote: | After you comple your program, look in the folder and file the 'project.lst' file. That is the listing, the program ,listed ,line by line in machine code,with whatever comments, etc. Just look for the #use.....and there will be the code. |
Okey I understand thank you. I saw these in assembly language. I don't know asm :(.
Actually what I want is to write codes in an another compiler. To do this, I need to understand functions and how it works. Thank you all for reading. And sorry for dwelling on this subject. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1345
|
|
Posted: Sun May 17, 2020 8:16 pm |
|
|
ads wrote: | Thanks a lot for your answers. What I just want to see definitions of functions
Quote: | I think you are misunderstanding what #use is. In C this is referred to as a preprocessor directive. |
Sorry you are right I am not so familiar with programming. But I can't find this function either which is ;
"setup_timer_1(T1_DISABLED);"
|
Ok. So it sounds like you are actually looking for the function definition, not the declaration. The declaration is just a prototype for the function call while the definition is the actual code that implements it. This link explains the difference probably better than me: https://www.geeksforgeeks.org/difference-between-definition-and-declaration/
The trouble here is CCS creates the function definitions on the fly based on various parameters (the chip you selected, the #use directives, #device directives, etc.). They are referred to as "built in" functions because they don't have a general C definition. The comments others have given you about "dumping the listing" are as close as you can get to this. Doing as they suggest will show you the underlying assembly code that the compiler generates. There is no current way to see the C code used for these functions, only the assembly (as others have mentioned to you). |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Mon May 18, 2020 12:39 am |
|
|
Make a single line change to the processor include file.
The second 'code' line in the file, immediately after the actual chip
declaration, is:
#nolist
Just remark this line out:
//#nolist
Save the file back with your code.
Change the include used to load the processor file to use "" instead
of <>. This makes the compiler look in the local directory 'first' so
it will find this modified file.
Then recompile.
The assembler for all the 'system' functions will now be visible in the .lst
file. So (for example), the timer setup etc..
Now understand this will only be 'assembler'. There is no 'C source' for
these core functions. Many are actually written in assembler by CCS.
For the #use rs232, the assembler will be in the lst file immediately
after the #use line. Similarly the code used for delays, will be just
after the clock definition etc..
Understand also that the declarations will 'interact', so the code
generated for the #use RS232, and the 'use PWM, will both change
if the #use DELAY changes etc... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 18, 2020 1:00 am |
|
|
Make a test program:
Code: |
#include <12F1822.h>
#use delay(internal=4M)
//=======================
void main()
{
setup_timer_1(T1_DISABLED);
while(TRUE);
}
|
Look at .LST file to see ASM code:
Code: |
.................... void main()
0003: MOVLW 6A
0004: MOVLB 01
0005: MOVWF OSCCON
0006: MOVLB 03
0007: CLRF ANSELA
0008: MOVLB 02
0009: CLRF CM1CON1
000A: CLRF CM1CON0
.................... {
.................... setup_timer_1(T1_DISABLED);
000B: BCF APFCON.T1GSEL
000C: MOVLB 00
000D: CLRF T1CON
000E: CLRF T1GCON
....................
.................... while(TRUE);
000F: GOTO 00F
.................... }
....................
0010: SLEEP
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Mon May 18, 2020 3:30 am |
|
|
and (of course), PCM here has the compiler set to generate 'SFR names'
to help make the result more readable. |
|
|
ads
Joined: 09 May 2020 Posts: 11
|
|
Posted: Mon May 18, 2020 5:22 am |
|
|
Okey thanks a lot everyone. Then it sounds like I need to learn asm language. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Mon May 18, 2020 6:38 am |
|
|
Actually PIC ASM is easy to learn as there's only 35+- instructions. Most newer PICS have MORE 'fuses' !!
A basic understanding of ASM allows you to 'see' how code executes and possible improvements either in speed(faster) or codespace(smaller). |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Mon May 18, 2020 7:12 am |
|
|
Quote: | Actually what I want is to write codes in an another compiler. To do this, I need to understand functions and how it works. Thank you all for reading. And sorry for dwelling on this subject. |
Are you trying to use the CCS built in functions for a different compiler? |
|
|
|