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.

Define.. want to understand

Status
Not open for further replies.

Ayne

New Member
Can we define a constant to our SFR like below???

&

supose i define a constant x = PORTB,3 like below
Code:
#define   x     PORTB,3
if i change the the value of x then the whole PORTB will effected or just bit 3 of PORTB will be effected??

Code:
movlw   b'10110110'
movwf   x
what will be the result ???
Code:
PORTB = 10110110
OR
Code:
PORTB.3 = 0
 
In your case, occurance of "x" will be replaced by "PORTB,3" before the source file is processed by assembler or compiler.

If you change the #define to other things, "x" will be substituted by other thing too.

You code does not make sense.
Code:
movlw   b'10110110'
movwf   x                ;<<<< wrong !!!

because it substituted into "movwf PORTB,3" and movwf moves 8-bit at a time.

Your remaining questions have nothing to do with the above ASCII replacement.
 
Essentially all define and equate do is a simple text substitution during assembly, as do those in the inc file. In your example, because it makes no sense, the assembler will generate an error.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top