Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 16th January 2008, 01:37 PM   (permalink)
Smile EQU and #define

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..
__________________
Simran..
8051 Specialist..
simrantogether is offline  
Old 16th January 2008, 03:33 PM   (permalink)
Default

#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.
__________________
Pete
picprojects.org.uk
geko is offline  
Old 16th January 2008, 03:36 PM   (permalink)
Default

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
__________________
Superman returns..
bananasiong is online now  
Old 17th January 2008, 05:52 AM   (permalink)
Smile 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..
__________________
Simran..
8051 Specialist..
simrantogether is offline  
Old 17th January 2008, 06:41 AM   (permalink)
Default

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.
__________________
Superman returns..
bananasiong is online now  
Old 17th January 2008, 07:01 AM   (permalink)
Smile 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..
__________________
Simran..
8051 Specialist..
simrantogether is offline  
Old 17th January 2008, 07:05 AM   (permalink)
Default

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
__________________
Gayan

My Website
http://gsmicro.blogspot.com/
Gayan Soyza is offline  
Old 17th January 2008, 07:44 AM   (permalink)
Smile Hi..

Quote:
Originally Posted by Gayan Soyza
Mostly a bit can identify with a define directive
Can we use # define for byte purpose...


Quote:
Originally Posted by Gayan Soyza

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..
__________________
Simran..
8051 Specialist..
simrantogether is offline  
Old 17th January 2008, 07:58 AM   (permalink)
Default

Quote:
Originally Posted by simrantogether
Can we use # define for byte purpose...
Yes

Quote:
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.

Quote:
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.
__________________
Gayan

My Website
http://gsmicro.blogspot.com/

Last edited by Gayan Soyza; 17th January 2008 at 10:00 AM.
Gayan Soyza is offline  
Old 17th January 2008, 10:38 AM   (permalink)
Default

Quote:
Originally Posted by simrantogether
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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 17th January 2008, 11:11 AM   (permalink)
Smile 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..
__________________
Simran..
8051 Specialist..
simrantogether is offline  
Old 17th January 2008, 11:26 AM   (permalink)
Default #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
__________________
Agustín Tomás
In theory, there is no difference between theory and practice. In practice, however, there is.
atferrari is online now  
Old 17th January 2008, 11:29 AM   (permalink)
Smile Well...

Quote:
Originally Posted by atferrari
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..
__________________
Simran..
8051 Specialist..
simrantogether is offline  
Old 17th January 2008, 12:00 PM   (permalink)
Default

And what do you put in PIC assembler?, bear in mind this is simply a text substitution - substituting the wrong instructions isn't going to work.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 17th January 2008, 12:25 PM   (permalink)
Smile That means...

That means we are to put comma...

I'll remember...

Regards,

Simran..
__________________
Simran..
8051 Specialist..
simrantogether is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Substituting a 16x2 LCD display for 16x1 LCD display? Dawny Electronic Projects Design/Ideas/Reviews 19 11th October 2008 09:58 AM
Help needed ASM to HEX with MPLAB Virus Micro Controllers 39 26th December 2007 04:30 PM
PIC12f675 MERV Micro Controllers 18 10th December 2007 08:18 PM
RS232 Converter e.chain Micro Controllers 0 6th October 2007 07:19 PM
Stepper motor circuit for PIC16f877 flemmard Electronic Projects Design/Ideas/Reviews 6 28th September 2007 03:58 PM



All times are GMT. The time now is 01:00 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker