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 CBLOCK and DEFINE

Status
Not open for further replies.

patricktran

New Member
Hi, I am confused with these 2.
The Equ is used for defining a register of general purpose. The Cblock is for a consecutive group of varialbes, and Define is for a pin of a port.
They are all confusing. Could someone please give me a clearer explanation?
Thanks alot.
 
equ- Define Assembler Constant.
four equ 4 ;assigned the numeric value of 4 to label four

cblock-Define a Block of Constants. ;Define a list of named constants. Each <label> is assigned a value of one higher than the previous <label>. The purpose of this directive is to assign address offsets to many labels. The list of names end when an endc directive is encountered.

#define-Define a Text Substitution Label ;This directive defines a text substitution string. Wherever <name> is encountered in the assembly code, <string> will be substituted.

Strongly recomend it to read the MPASM Assembler Help.
This are cut's from the HELP manual.

STEVE
 
Yeah, thanks csaba911. If I need a register to store a value, and this value can be changed over the program, and I see people use EQU. This is certainly not a constant, as it can be changed.
In assembly, I dont see a clear barrier between constant and varialbe, unlike in Java:
final private int i = constant i
private int i = variable i
 
You'll find that your code contains constant values that reappear over and over. In these cases, you can greatly improve the readability of your code by using constants.
If I need a register to store a value, and this value can be changed over the program, and I see people use EQU. This is certainly not a constant, as it can be changed.
Can you change the memory location once is ben set ?!
The location of the register is constant !
Code:
W      EQU     H'0000'
F      EQU     H'0001'
INDF   EQU     H'0000'
TMR0   EQU     H'0001'
PCL    EQU     H'0002'
STATUS EQU     H'0003'
FSR    EQU     H'0004'
PORTA  EQU     H'0005'
PORTB  EQU     H'0006'
The value here is CONSTANT
Code:
movf    tmr0,w
or
movf    tmr0,indf ; have the same result, because their value is =0
You can write
Code:
movwf     0x20 ;mov the content of W to memory 0x20
movf      0x20,0 ;get the value of mem 0x20 and move it to the W reg
;or
temp_var  equ    0x20 ;memory location "constant value"
movwf     temp_var ;mov the content of W to memory temp_var =0x20
movf      temp_var,w ;get the value of mem temp_var=0x20 and move it to the W=0 reg
If you have 30 mem address, thing can get out of hand easy if you try to remember all the mem location by their addres.

#define control 0x19,7
control is = address 0x19 bit 7

Maybe I can't explane to you, but at least I know how to use them.

STEVE
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top