CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

#byte vs #device - When to use? - SOLVED

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

#byte vs #device - When to use? - SOLVED
PostPosted: Fri Oct 08, 2010 10:29 am     Reply with quote

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: 1903

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 10:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 12:29 pm     Reply with quote

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: 1903

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 12:35 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 08, 2010 1:00 pm     Reply with quote

wicked!...

that explains why #Byte was working intermitently....

.... thank you....

Gabriel.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group