View previous topic :: View next topic |
Author |
Message |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
#byte vs #device - When to use? - SOLVED |
Posted: Fri Oct 08, 2010 10:29 am |
|
|
hi all,
im coding a driver for an RTC and EEPROM, and few other things..
i would like to use identifiers for my CS, CE, and other similarĀ“pin numbers and fixed addresses as to be able to do something like this:
Code: | Output_high(CS_RTC); // chip select RTC |
I have CS_RTC defined as :
Code: | #define CS_RTC PIN_B2 |
and that works fine...
now when it comes to fixed addresses (like the time registers on the RTC)
i would like to do:
Code: | Spi_write(Hour_Reg); |
here is my question question:
Hour_Reg should stand for 0x8F.... lets assume.
im currently defining that as:
Code: | #byte Hour_reg = 0x8F |
what is the diference between #device and #byte?
#device for pins and #Byte for numbers?
The 0x8F gets stored in rom right?
appart form code readablitiy what are the benefits of using this?
are there any specific instances you "should" use this?
i read up on this topics, im still a bit unclear...
if you think by reading document X i can get all the info, ill be glad to read any document you suggest... post a link if possible..
....
thank you all
gabriel. _________________ CCS PCM 5.078 & CCS PCH 5.093
Last edited by Gabriel on Fri Oct 08, 2010 1:01 pm; edited 1 time in total |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Fri Oct 08, 2010 10:50 am |
|
|
The #byte locates a variable to a specific location in RAM. It's used to directly access a special function register (SFR) or to assign a variable to a specific location in RAM. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Fri Oct 08, 2010 12:29 pm |
|
|
So, by:
Code: | #byte Hour_reg = 0x8F |
Hour_reg is to be stored at location 0X8F?
should i use:
Code: | #define Hour_reg 0X8F | instead?
will the above make Hour_reg an identifier for the value 0x8F?
i would like to type Hour_reg instead of 0x8F every where such value is encontered in my code....for readability purposes... and confusion avoidance....
#define or #byte or #somthing_else?
thank you for your help _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Fri Oct 08, 2010 12:35 pm |
|
|
For what you're doing, you want #define because you're accessing a register in a chip outside of the PIC (either EEPROM or RTC).
All the #define does is it tells the compiler to take every instance of the #define text and replace it with the number that follows. Given your situation, that's definitely what you want. |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Fri Oct 08, 2010 1:00 pm |
|
|
wicked!...
that explains why #Byte was working intermitently....
.... thank you....
Gabriel. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
|