DataByte equ 0x20; DataByte is at location 0x20 in RAM--VARIABLE---
Freq equ 4; Freq is same as 4--CONSTANT-------
DataByte equ 0x41
DataByte equ 0x20; DataByte is at location 0x20 in RAM--VARIABLE---
Freq equ 4 ; Freq is same as 4--CONSTANT-------
movlw DataByte ;this would give W a value of 0x20, not the RAM content of 0x20
movwf DataByte ;this would move the value in W to RAM location 0x20
movf DataByte,W ;this would move the RAM content of location 0x20 into W
#define DataByte 0x41
constant DataByte = 0x41
DataByte equ 0x41
movf DataByte, w ; Puts data contained at address 0x41 in W
movlw DataByte ; Puts literal 0x41 in W
Joel Rainville said:BTW, note the blank space before the keyword "constant". It is needed, although MPASM will only issue a warning if you forget it. At least, the latest version of MPASM will treat is as non-critical. I don't know about earlier versions.
Also note that the #define method has the advantage of not using up any RAM space. Could be useful in smaller PICs.
Joel Rainville said:#define defines a text substitution string. Instead of defining a variable that your code will access during execution, MPASM just replaces every occurence of the #defined value in your code with a literal.
equ on the other hand, tells the assembler to reserve 8 bits of RAM to eventually store data at the address location used as a constant. So while the address is constant and can be used as a literal, the data pointed to is not, so it needs RAM allocated to be modified.
As far as I know, there is no real constant in PIC assembly, where both the address and the memory content are constant and not writable. Someone please correct me if I'm wrong, but I really doubt it.
Freq equ 4
Electrix said:Joel Rainville said:#define defines a text substitution string. Instead of defining a variable that your code will access during execution, MPASM just replaces every occurence of the #defined value in your code with a literal.
equ on the other hand, tells the assembler to reserve 8 bits of RAM to eventually store data at the address location used as a constant. So while the address is constant and can be used as a literal, the data pointed to is not, so it needs RAM allocated to be modified.
As far as I know, there is no real constant in PIC assembly, where both the address and the memory content are constant and not writable. Someone please correct me if I'm wrong, but I really doubt it.
Sorry but I still do not understand..
Code:Freq equ 4
Isn't this also a plain text(string) substitution method.
If equ does occupy RAM, which(Address) RAM does it use
Besides, I thought all assembler directives do not occupy any memory.
PS: Thanks for all your patience...
Not so fast!Joel Rainville said:Well, ok, you're right. Freq in that case doesn't reserve any RAM because you're never actually gonna write to address 0x04. And if you plan on doing so, don't! :lol: It's a reserved memory location.
Jay.slovak said:Not so fast!Joel Rainville said:Well, ok, you're right. Freq in that case doesn't reserve any RAM because you're never actually gonna write to address 0x04. And if you plan on doing so, don't! :lol: It's a reserved memory location.
The only difference is that EQU has to be a numerical value (and can be used in ASSEMBLER scripts, or to use it as a substitution while working with certain memory space - but has to be used first "MOVWF REG1") and #define is a TEXT substitution (or it can span through multiple bytes, such as #define GR_LED PORTA,4).
EQU must resolve to an integer, #define can be any text string.
EQUs and #Defines don't occupy any space!
Byte equ 0x72
Byte equ 0x72
Byte1 equ 0x72
Byte2 equ 0x72
Byte3 equ 0x72
Byte4 equ 0x72
Same hereJoel Rainville said:Sometimes my limited english vocabulary fails to clearly express my thoughts :lol: Sorry about that
REG1 equ 0x10
MOVLW REG1
MOVWF REG1
;********** Definovanie uzivatelskych registrov *******************
Fosc equ 20 ;Frekvencia Oscilatora v Mhz
#DEFINE RW PORTB,1 ;Hlavne tlacidlo
#DEFINE RS PORTB,2 ;Pomocne tlacidlo
#DEFINE E PORTB,0
#DEFINE BCKL PORTC,1
#DEFINE TL PORTB,3
#DEFINE LED PORTB,4
#DEFINE SPI_CSH PORTB,5
#DEFINE SPI_CSL PORTB,6
; #DEFINE Ul PORTC,0 ;!!
; #DEFINE Uh PORTC,1 ;!!
#DEFINE ON_OUT PORTB,7
#DEFINE ON_AUX PORTA,4
#DEFINE SWITCH PORTC,0
#DEFINE FAN PORTC,2
#DEFINE lcdBF PORTD,7
#DEFINE BEEP PORTE,2
#DEFINE OverFlow Flags,0
#DEFINE POT CONTROL,1
#DEFINE TLAC CONTROL,0
#DEFINE PC CONTROL,2
ZDRZ0 equ D'000'
ZDRZ1 equ D'001'
ZDRZ2 equ D'002'
SPIreg equ D'003'
TAB_CISLO equ D'004'
TAB_MIESTO equ D'005'
DEC_orig equ D'006'
DEC_n equ D'007'
stovky equ D'008'
desiatky equ D'009'
jednotky equ D'010'
DEC_TMP equ D'011'
Count equ D'012'
R0 equ D'013'
R1 equ D'014'
R2 equ D'015'
R3 equ D'016'
R4 equ D'017'
Uset equ D'018'
ADSEND equ D'019'
LCD equ D'020'
LCDc equ D'021'
Usense equ D'022'
Isense equ D'023'
Temp equ D'024'
Pot1 equ D'025'
Pot2 equ D'026'
Flags equ D'027'
Acc1L equ D'028'
Acc1H equ D'029'
Acc2L equ D'030'
Acc2H equ D'031'
CONTROL equ D'032'
TLATCH equ D'033'
DEMOcount equ D'034'
DEMOtab equ D'035'
INTcount equ D'036'
;************** Tabulka pridelenych napeti ku tlacidlam **********
s0 = 015*factor
s1 = 030*factor
s2 = 045*factor
s3 = 060*factor
s4 = 075*factor
s5 = 090*factor
s6 = 105*factor
s7 = 120*factor
factor equ 2
REG1 equ 0x10
MOVLW REG1
MOVWF REG1 <- I assume EG1 was actually a typo
Joel Rainville said:Also in your code
Code:REG1 equ 0x10 MOVLW REG1 MOVWF REG1 <- I assume EG1 was actually a typo
Yes, Commenting is the only way how to prevent such situations...As a reader of your code, when I see the first use of REG1 as a literal, I make a mental note that REG1 is a literal constant. If I later see that movwf where REG1 is used as a memory location, my first thought is "woops, here's a bug". It is very confusing
count_mtableequ equ 0x500 ;equates counter1 variable at RAM bank 5 (start position)
Warning[207] Found label after column 1. (count_mtableequ)
cblock 20h
Acc:0
AccLo
AccHi
Buffer:10h
Flags
Count
Keys
OldKeys
Edge
endc
cblock 70h
int_work
int_status
endc
#define b_GotByte Flags,7
#define b_Next Flags,6
In equ 1
Out equ 0
PA0 = Out ; description of this bit
PA1 = In ; ditto
PA2 = Out
PA3 = Out
PA4 = In
PA5 = In
PA6 = In
PA7 = In
TrissA equ (PA7<<7)+(PA6<<6)+(PA5<<5)+(PA4<<4)+(PA3<<3)+(PA2<<2)+(PA1<<1)+(PA0<<0)
bsf STATUS,RP0
movlw (0<<CSRC|0<<TX9|1<<TXEN|0<<SYNC|1<<BRGH|0<<TRMT|0<<TX9D)
movwf TXSTA; bit 2 = 1 therefore high speed
bcf STATUS,RP0
movlw (1<<SPEN|0<<RX9|0<<SREN|1<<CREN|0<<ADDEN|0<<FERR|0<<OERR|0<<RX9D)
movwf RCSTA
movlw (1<<GIE|1<<PEIE|0<<TMR0IE|0<<INTE|0<<RBIE|0<<TMR0IF|0<<INTF|0<<RBIF)
movwf INTCON; enable Peripheral interrupts
Pommie said:I also use the shift left function to setup registers.
EG
Code:bsf STATUS,RP0 movlw (0<<CSRC|0<<TX9|1<<TXEN|0<SYNC|1<<BRGH|0<<TRMT|0<<TX9D) movwf TXSTA; bit 2 = 1 therefore high speed bcf STATUS,RP0 movlw (1<<SPEN|0<<RX9|0<<SREN|1<<CREN|0<<ADDEN|0<<FERR|0<<OERR|0<<RX9D) movwf RCSTA movlw (1<<GIE|1<<PEIE|0<<TMR0IE|0<<INTE|0<<RBIE|0<<TMR0IF|0<<INTF|0<<RBIF) movwf INTCON; enable Peripheral interrupts
Hope someone found that interesting.
Mike.
Pommie said:I also use the shift left function to setup registers.
EG
Code:bsf STATUS,RP0 movlw (0<<CSRC|0<<TX9|1<<TXEN|0<<SYNC|1<<BRGH|0<<TRMT|0<<TX9D) movwf TXSTA; bit 2 = 1 therefore high speed bcf STATUS,RP0 movlw (1<<SPEN|0<<RX9|0<<SREN|1<<CREN|0<<ADDEN|0<<FERR|0<<OERR|0<<RX9D) movwf RCSTA movlw (1<<GIE|1<<PEIE|0<<TMR0IE|0<<INTE|0<<RBIE|0<<TMR0IF|0<<INTF|0<<RBIF) movwf INTCON; enable Peripheral interrupts
Hope someone found that interesting.
Mike.
Edit corrected error found by eblc1388
Mike said:I like that example... Incredibly creative and intuitive... Are you the one who deserves credit for coming up with that?
Regards, Mike
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?