View previous topic :: View next topic |
Author |
Message |
jose Guest
|
Mapping of Internal Registers in ANSI-C |
Posted: Wed Apr 13, 2005 9:34 pm |
|
|
I would like to know if this implementation works with CCS for PIC. The reason why i dont want to use #byte is because of the porting issues.
Please suggest me the best method to map io's and yet portable to all platforms
/*** PORT_B ***/
typedef union {
char BB;
struct {
char BIT_7 :1;
char BIT_6 :1;
char BIT_5 :1;
char BIT_4 :1;
char BIT_3 :1;
char BIT_2 :1;
char BIT_1 :1;
char BIT_0 :1;
} Bits;
}PORTB;
extern volatile PORTB PORT_B @ 0x0001;
or can somebody explain me what "#byte" implemented.
Thank You. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 13, 2005 9:51 pm |
|
|
The following code would be more portable than #byte statements,
but I have to ask, how often do you plan to change compilers ?
Even if you're making a product that is intended for use with
different compilers, I think it would be better to port it to each
compiler than to try to debug some "universal" source code.
Look at Peter Anderson's website.
http://www.phanderson.com/PIC/PICC/index.html
He tries to make his code be semi-universal, by avoiding the
use of the CCS delay_ms(), etc., functions. But by doing so
he gives up the flexibility to change the crystal frequency
and have the delay functions automatically be adjusted for
the new frequency. Even he uses the #byte statements.
See his register definitions file.
http://www.phanderson.com/PIC/PICC/CCS_PCM/defs_f84.html
So my main question to you would be, why bother ?
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#define TrisB 0x86
#define PortB 0x06
main()
{
*TrisB = 0x00;
*PortB = 0x55;
while(1);
} |
|
|
|
jose Guest
|
Re.Mapping of Internal Registers in ANSI-C |
Posted: Wed Apr 13, 2005 10:19 pm |
|
|
Thank you for the advice,
But how can i access bits in the registers using the similar method.
Thank you
Jose |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Apr 14, 2005 7:10 am |
|
|
For portability you shouldn't be using PORTB. Instead, you should be using something more descriptive like "data_port". All of these declarations should be in a header file and you would use a different header file for each compiler. |
|
|
jose Guest
|
|
Posted: Mon Apr 18, 2005 7:01 pm |
|
|
Thank you for your advice Mark,
I hope this implementation would work on all the platforms and it doesnt take up the ram area.
Please comment on this implementation.
Thank you
regards
Jose
typedef volatile char SP;
typedef union {
SP BB;
struct {
SP BIT_7 :1;
SP BIT_6 :1;
SP BIT_5 :1;
SP BIT_4 :1;
SP BIT_3 :1;
SP BIT_2 :1;
SP BIT_1 :1;
SP BIT_0 :1;
} Bits;
}PORTB;
#define REG_PORTB ((PORTB *)0x00)
void main() {
.......
.....
REG_PORTB->Bits.BIT_1 = 0;
REG_PORTB->BB = 0;
} |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
|
|