Ayne New Member Jan 18, 2007 #1 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
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
eblc1388 Active Member Jan 18, 2007 #2 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.
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.
Nigel Goodwin Super Moderator Most Helpful Member Jan 18, 2007 #4 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.
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.