Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Equates vs Define

Status
Not open for further replies.

sahu

Member
What is the difference, if any between using equates (e.g. LCD_RS Equ 0x04) and using define (e.g. #define SDA 7)? When should one use equates and when should one use #define?

I note that the PICS used in the ASM have features such as
Power Up Timer, Watch Dog Timer, Brown Out Reset etc. =?
pl define..........
 

gogo2520

New Member
Hello
One example would be
PORTB equ LED
were you can turn on a LED like this
BSF LED,1 ; turns on LED 1
BSF LED,2 ;turns on LED 2
if you want to have a register set up to hold a value like for a swap or delay or whatever

lcd_Display equ 0x22
Then you can load a value to register 0x22 and later read and write to it.
movlw b'00011100' ; value you want to hold
movwf lcd_display ; place you want to store it to

I would rather use Cblock for setting registers

with define
#define LED1 PORTB,1
or
#define light PORTB,1
#define lcd_display b''00011100'

then your code would look like this
bsf LED1 ; turns on LED1
bsf light ; turns on LED1
or
movlw lcd_display ;reads the value of lcd_deisplay
movwf PORTB ; and moves to PORTB

you can add it, swap it, copy it whatever but the value of the define will not change were the value of a equ can.
There is more to it but this should give you an idea

gogo
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
#define can contain anything, equ needs to be a number. So you can do,
Code:
#define LED porta.1
Or
Code:
porta    equ  8
The first is like a search and replace. It replaces one string by another. The second is a variable with a number associated with it.

Mike.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
#define can contain anything, equ needs to be a number. So you can do,
Code:
#define LED porta.1
Or
Code:
porta    equ  8
The first is like a search and replace. It replaces one string by another. The second is a variable with a number associated with it.

The second is just a search and replace as well, but a much more limited one, it only accepts numeric values as opposed to strings.
 

Pommie

Well-Known Member
Most Helpful Member
NO, it is not a text substitution as it can't contain text it can only contain a valid mathematical expression. It is a constant value and must be able to be evaluated.

Why do you keep trying to pick holes in anything I post? I really am getting frustrated with this. Please stop.

Mike.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
NO, it is not a text substitution as it can't contain text it can only contain a valid mathematical expression. It is a constant value and must be able to be evaluated.

Why do you keep trying to pick holes in anything I post? I really am getting frustrated with this. Please stop.

I've never done so, and am not doing so now - your post was VERY confusing - I wasn't even aware it was you who posted it, I rarely read the posters name.
 

Pommie

Well-Known Member
Most Helpful Member
Well, when you debate programming with someone that's been doing it for 25 years then you should look. Your knowledge of programming is not very good. You constantly come out with things that are just plain wrong. You have done that tonight and your only defense is "I didn't look who posted".

Please stop.

Mike.
 

3v0

Coop Build Coordinator
Forum Supporter
#define is a directive to the text preprocessor,

EQU causes the compiler to create a symbol.. The compiler evaluates the RHS of the the EQU to determine the value.

EQU is not text substitution.
It creates a assembler symbol. The symbol could be changed by a second EQU (unless restricted by the assembler writers). So in this sense it has variable value but is not a program variable.

3v0
 
Last edited:

Nigel Goodwin

Super Moderator
Most Helpful Member
Well, when you debate programming with someone that's been doing it for 25 years then you should look. Your knowledge of programming is not very good. You constantly come out with things that are just plain wrong. You have done that tonight and your only defense is "I didn't look who posted".

What is your problem? - I didn't come out with any 'defence' at all, merely pointed out that I didn't realise that I was replying to your paranoid self.

The RHS of an equate is evaluated (if required - the case you gave didn't need to be) and converted to a numeric text string. This is then used in a simple text search and replace. Do you have any problem with that?.

You may have been a professional programmer, but I've been programming for over 25 years as well.
 

Pommie

Well-Known Member
Most Helpful Member
What is your problem? - I didn't come out with any 'defence' at all, merely pointed out that I didn't realise that I was replying to your paranoid self.

The RHS of an equate is evaluated (if required - the case you gave didn't need to be) and converted to a numeric text string. This is then used in a simple text search and replace. Do you have any problem with that?.

You may have been a professional programmer, but I've been programming for over 25 years as well.

No, the right hand side has to equate to a numeric value and the case I gave did need to be.

You may have been programming for 25 years but you don't understand the difference between #define and equ.

And, yes, I am paranoid because someone follows me around and questions my posts any time they can. See above. What I posted was absolutely correct but you took it upon yourself to question it.

If you still believe that what I posted was incorrect then please explain why.

Otherwise, please stop.

Mike.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
If you still believe that what I posted was incorrect then please explain why.

I already have done, but as you seem completely paranoid I'm going to add you to my ignore list so I never see any of your posts again, so I can't reply by accident - I'm not interested in replying to someone who considers any reply a personal attack, even when I had no idea who the post was even by.
 

sahu

Member
#define can contain anything, equ needs to be a number. So you can do,
Code:
#define LED porta.1
Or
Code:
porta    equ  8
The first is like a search and replace. It replaces one string by another. The second is a variable with a number associated with it.

Mike.

THANK U FOR REPPLY
define can contain anything........why?
equ needs to be a number.........why it can not contain anything ?
 

Pommie

Well-Known Member
Most Helpful Member
I already have done, but as you seem completely paranoid I'm going to add you to my ignore list so I never see any of your posts again, so I can't reply by accident - I'm not interested in replying to someone who considers any reply a personal attack, even when I had no idea who the post was even by.

Thank you.

Mike.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top