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 CCS Technical Support

#define and #byte

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



Joined: 12 Sep 2003
Posts: 10

View user's profile Send private message

#define and #byte
PostPosted: Wed Mar 24, 2004 10:10 am     Reply with quote

Hello,
Can someone please clarify the difference between a #define and #byte.
When I define the different registers, I thought I would use

#define PORTA 0x05

but then I get an error when I do

PORTA =0;

When I am defining EEPROM variables should I use #define or #byte?

Thanks,
mle
truevenik



Joined: 03 Feb 2004
Posts: 5

View user's profile Send private message

partial answer
PostPosted: Wed Mar 24, 2004 10:43 am     Reply with quote

hi,

#define PORTA 0x05
PORTA = 0
is equivalent to just writing
0x05 = 0 (try to assign 0 to a litteral value = error -this is like writing 3=1)

#byte PORTA = 0x05
PORTA = 0
I think is equivalent to writing
*0x05 = 0 (store 0 in an address = no error)

In general, when you do #define <a> <b>, the compiler blindly goes through and replaces all occurences of <a> with <b> - its almost like find-replace in a text editor. #byte is different: Normally, when you define a variable (eg. int x), the compiler decides which memory address to use. #byte allows you to explicitly tell the compiler to use a specific RAM address for the variable - it associates a RAM address with a name.

I don't know what you mean by defining eeprom variables. the above code just names a register in the register file (RAM).
To store to EEPROM if I remember correctly, you have to put an address in a register, and data in another register. both of these registers can be written in exactly the same way you would write something to portA.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Mar 24, 2004 11:17 am     Reply with quote

You might want to consider keeping your code as portable as possible. To do this you would use output_a(0) which will write all zero's to the port.

Happy frustrations.

Ronald
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