View previous topic :: View next topic |
Author |
Message |
szlovak
Joined: 27 May 2006 Posts: 2
|
Header files |
Posted: Sat May 27, 2006 6:07 pm |
|
|
Hello
I've started using PCM compiler. And I have a question: why I have to do myself header file with definitions of all special function registers like: TMR0, INDF, STATUS and so on ?? There are significant difference
in many registers between PIC chips. I found in few places in internet header files for some chips, but it seems like there were no such files in CCS. And I need such header files for pic16f84a, pic10f200, 12f508, 16f872, 16f628. Where is it or how can make it easily (automatic)?
PS I found file called "Sfr.txt" and it looks like it has all the data but with strange format |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat May 27, 2006 7:00 pm |
|
|
...
Last edited by dyeatman on Sat May 27, 2006 8:50 pm; edited 1 time in total |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: Header files |
Posted: Sat May 27, 2006 7:46 pm |
|
|
szlovak wrote: | Hello
I've started using PCM compiler. And I have a question: why I have to do myself header file with definitions of all special function registers like: TMR0, INDF, STATUS and so on ?? There are significant difference
in many registers between PIC chips. I found in few places in internet header files for some chips, but it seems like there were no such files in CCS. And I need such header files for pic16f84a, pic10f200, 12f508, 16f872, 16f628. Where is it or how can make it easily (automatic)?
PS I found file called "Sfr.txt" and it looks like it has all the data but with strange format |
You are correct. There have been some posted that you could use or make your own. CCS does not include register definitions in their header files. |
|
|
Ttelmah Guest
|
|
Posted: Sun May 28, 2006 3:10 am |
|
|
It is worth saying though, that for 99% of programs, you should not need these definitions. CCS attempts to encourage you not to directly access such registers, because as soon as you do this, it potentially makes the code 'non portable' to other PICs.
Best Wishes |
|
|
szlovak
Joined: 27 May 2006 Posts: 2
|
|
Posted: Mon May 29, 2006 6:09 am |
|
|
So when it is very necessary and can't be done without direct access? |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Mon May 29, 2006 8:18 am |
|
|
szlovak wrote: | So when it is very necessary and can't be done without direct access? |
If you absolutely can't do it with built-in functions or if it is for personal reasons, then just write your own.
But keep in mind that your code is now MUCH less portable among chip variations. Especially if you cross between families (10F to 12F to 16F to 18F etc).
Since the #include you need for each part has a unique identifier for the chip, you could write your register header such that it took advantage of the #defines. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 29, 2006 4:17 pm |
|
|
Quote: | So when it is very necessary and can't be done without direct access? |
If you really think this is essential, you could write a small DOS program
program in C, with MSVC, to parse the Microchip ".inc" files that are
provided with MPLAB and convert them to your header files.
For example, P16F628.H has a lot of equates in it like this:
Code: |
INDF EQU H'0000'
TMR0 EQU H'0001'
PCL EQU H'0002'
STATUS EQU H'0003'
FSR EQU H'0004'
PORTA EQU H'0005'
PORTB EQU H'0006'
|
The conversion program would produce output like this:
Code: |
#byte INDF = 0x00
#byte TMR0 = 0x01
#byte PCL = 0x02
#byte STATUS = 0x03
#byte FSR = 0x04
#byte PORTA = 0x05
#byte PORTB = 0x06 |
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Jun 01, 2006 12:14 pm |
|
|
I almost always define my own registers and rarely use the in-built functions. This requires more programming but I have more control and less problems with compiler "features". This will also force you to read the datasheet and gain a better understanding of the chip. |
|
|
|