Continue to Site

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.

EQU and #define

Status
Not open for further replies.
Hi all,

I wanted to ask in assembly of pic - the difference between EQU and # define.

EQU I understood but confusion in # define as the following line in book says...

" A #define on the other hand tells the assembler to substitute two values where it finds a certain word e.g. #define led portb.4

Wherever the assembler finds the word led, it substitutes 6.4 (or portb.4) in it's place. "

Can anyone make me understand above statement...

Main thing i understood that # define is used as generic - that we can make changes only at one part of program and all the program the values shall be changed automatically...

Regards,

Simran..
 
#define led portb.4

Anywhere mpasm finds the word 'led' it will substitute the string 'portb.4'

The part about '6.2' is simply because somwhere else 'portb' has already been set (probably in the procesor INC file) using portb EQU 6 - Why six? Because 6 is the address of portb in the data memory area.
 
Hi,
#define can be used for instructions, such as
Code:
#define on bsf PORTB, 0
#define off bcf PORTB, 0
but equ is often used for values, such as the address location of the general purpose registers.

These are my applications for equ and #define
 
Hi ...

Hi Geko and Bananasiong...

Thanks... I understood...

One last question...

EQU has two purposes... 1. Assigning names to registers 2. assigning values to variables..

Am i right...

Regards,

Simran..:)
 
Hi,
General purpose registers are used for storing variables as well. So basically they are the same. That equate directive is for us to differentiate the registers easier, instead of the memory location, we can equate the name.
 
Ok...

Ok...

e.g.

Sam EQU #3 ; it means that sam is a variable with constant value 3 ...

and Sam EQU 3 ; it means that Sam is name given to register number 3 ...

I hope i am right because i have more practice for C than assembly...

Regards,

Simran..:)
 
Mostly a bit can identify with a define directive

Code:
# define LED PORTB,0	;portB 0 bit is the LED

Equ mostly used for SFR or for variables

Code:
	PORTB 	equ 	06h		;SFR address is 06h
	TIME   	equ 	20h		;your GPR address is 20h

A special bit also can use the equ mark

Code:
C      EQU    0 	;carry bit is the zero bit in STATUS R
 
Hi..

Gayan Soyza said:
Mostly a bit can identify with a define directive

Can we use # define for byte purpose...


Gayan Soyza said:
A special bit also can use the equ mark

C EQU 0 ;carry bit is the zero bit in STATUS R

how the compiler comes to know that C is a bit and not a byte name...

is it predefined that c always means carry in mp - assembler...

Regards,

Simran..:)
 
simrantogether said:
Can we use # define for byte purpose...
Yes

how the compiler comes to know that C is a bit and not a byte name...
Who knows.If it is a decimal value assembler detects as a decimal value.If its a hex thing firstly assembler searching if its a own SFR or not.

is it predefined that c always means carry in mp - assembler...
If you write your own self contain register programs without include file for different PICs you will understand this.You need to equal the SFR as well. If you call the include file no need equal.But need to equal the other GPR's or use cblock.
 
Last edited:
simrantogether said:
Can we use # define for byte purpose...




how the compiler comes to know that C is a bit and not a byte name...

It doesn't need to 'know', it's simply a text substitution (both equ and define), the assembler first runs through the code and replaces all occurances of ' C ' with ' 0 ' as you told it to - there's no such thing as bits or bytes, just ASCII text.

People seem to find equ and define difficult to understand?, but when you realise it's just a simple text substitution it becomes easy - think 'search and replace' from your word processor.
 
I got it sir...

I got it sir...

EQU is simply to match the register with its name..

and #define is almost same but we can actually give name to particular pins also...

Problem was that - I misread one statement in Book...

It was written '#define led Portb.6' while i read it as ' #define led Portb,6 '

Hence i got confused...

Regards,

Simran..
 
#define

This is from a file I am currently using (note the comma):

#DEFINE LED_RED LATA,1
#DEFINE LED_GREEN LATA,2
#DEFINE LED_YELLOW LATA,3
 
Well...

atferrari said:
This is from a file I am currently using (note the comma):

#DEFINE LED_RED LATA,1
#DEFINE LED_GREEN LATA,2
#DEFINE LED_YELLOW LATA,3


Hi,

Do we have to put comma or Dot ... This is the main question...

Note that in embedded C we usually put ' Dot ' ..

Regards,

Simran..
 
For sure it is comma. Just check the datasheet under the instruction set summary. All the formats of the instructions are there.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top