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.

Delay Symbol Question

Status
Not open for further replies.
Just a quick question. What does the $ symbol mean/equate in this code mean? It is not in my pic mcu quickchart. The code needs to go into a 16f870. I found this code in a delay code generator at piclist.com

; Delay = 0.5 seconds
; Clock frequency = 4 MHz

; Actual delay = 0.5 seconds = 500000 cycles
; Error = 0 %

cblock
DELAYP5
DELAYP5_1
DELAYP5_2
endc

DelayP5
;499994 cycles
movlw 0x03
movwf DELAYP5
movlw 0x18
movwf DELAYP5_1
movlw 0x02
movwf DELAYP5_2
DelayP5_0
decfsz DELAYP5, f
goto $+2
decfsz DELAYP5_1, f
goto $+2
decfsz DELAYP5_2, f
goto DelayP5_0

;2 cycles
goto $+1

;4 cycles (including call)
return
 
$+2 means goto the next 2 instruction.
Code:
decfsz DELAYP5_1, f
goto $+2
decfsz DELAYP5_2, f
goto DelayP5_0
If DELAYP5_1 is not zero, then go to-->goto DELAYP5_0

EDIT: you can use MPLAB to see the disassembler listing (if not mistaken), see where address it goes.
 
Last edited:
$ is the symbol for Present Location

1. goto $ will loop forever given no interrupts intervene.
2. goto $ + X will skip forward X instructions.
3. goto $ - X will skip backward X instructions.

P.S. When a delay routine is this ugly, you should just make up your own and make it paramatized so that one routine can suffice for most your long delay times.
 
FYI, $+11 is not the next 11 instruction but next 17. $+0B is the next 11th instruction. I've tried without a '0', i.e. $+B and it doesn't work.
 
You must always be away of the default radix or use definitive expressions.
If you want to skip eleven you do this:
GOTO $ + .11
GOTO $ + 0X0B
GOTO $ + 0BH
GOTO $ + B'00001011'

Or do this:
RADIX DEC
GOTO $ + 11

This is true for every single line of opcode and not just goto's.
 
If not mistaken, it changes the default way that the compiler interprets numerals from a base (or radix) of sixteen (hex) to a base of ten (decimal). Otherwise, it is good common practice to pre/post-fix all numerals as donniedj shows at the top of his post above.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top