View previous topic :: View next topic |
Author |
Message |
mle
Joined: 12 Sep 2003 Posts: 10
|
#define and #byte |
Posted: Wed Mar 24, 2004 10:10 am |
|
|
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
|
partial answer |
Posted: Wed Mar 24, 2004 10:43 am |
|
|
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
|
|
Posted: Wed Mar 24, 2004 11:17 am |
|
|
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 |
|
|
|