Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 13th November 2008, 02:34 AM   #1
Default Delay Question

Hello everyone 'Good Morning' Its Morning here

Code:
Delay2sec
			;1999996 cycles
	movlw	0x11
	movwf	d1
	movlw	0x5D
	movwf	d2
	movlw	0x05
	movwf	d3
Delay2sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay2sec_0

			;4 cycles (including call)
	return
These are the codes generated from a delay generator website.

I am interested in knowing $? and $+2? What does it mean?

If this is simple question don't flare at me point me to good website so I can read more about PIC.

Learning PIC is more fun than writing reports Just a side comment
__________________
Hesham Ismail Mohammed Sharif
Thank me if you want

Last edited by uaefame; 13th November 2008 at 02:35 AM.
uaefame is offline  
Old 13th November 2008, 03:01 AM   #2
Default

$ is assembly for the current program counter value. It points to the next instruction to be executed so if the next instruction takes 2 bytes "goto $+2" skips the next instruction
Ubergeek63 is offline  
Old 13th November 2008, 03:14 AM   #3
Default

Thanks for replying

Quote:
$ is assembly for the current program counter value. It points to the next instruction to be executed so if the next instruction takes 2 bytes "goto $+2" skips the next instruction
Can You explain more?

I understand that d1 is loaded with a value of 0x11 which is 17 decimal.

decrease 1 from it, it will be 16 right. Then goto $+2? This line confuses me?
__________________
Hesham Ismail Mohammed Sharif
Thank me if you want
uaefame is offline  
Old 13th November 2008, 03:18 AM   #4
Default

You'll find the older 16F have a few quirks that are gone in the 18F
Wait till you hit the RMW bug. The good news is the new 14bit core fixes the quirks of the older 14bit core. Also seems the older 33 instruction core is at the end of development in favor of the updated 44 instruction core.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is online now  
Old 13th November 2008, 03:48 AM   #5
Default

A good way to understand what is going on is to run the simulator in MPLAB. You can single step and watch the registers change. There is also a stopwatch so that you can see how long loops take.
Diver300 is offline  
Old 13th November 2008, 05:27 AM   #6
Default

Hi,

goto $

is go to the current program location, which is also the same as:

Label
goto Label

while goto $+2, it can be said go to the next two program location. So:

Code:
    decfsz    d1, f
    goto    $+2
    decfsz    d2, f
    goto    $+2
    decfsz    d3, f
    goto    Delay2sec_0
is also the same as:

Code:
Label1
    decfsz    d1, f
    goto    Label2
    decfsz    d2, f
Label2
    goto    Label3
    decfsz    d3, f
Label3
    goto    Delay2sec_0
__________________
bananasiong
bananasiong is offline  
Old 13th November 2008, 06:12 AM   #7
Default

Do you think, it should look like this

Code:
Label1
    decfsz    d1, f
    goto    Label2  
Label2
    goto    Label3
    decfsz    d2, f  
Label3
     decfsz    d3, f
     goto    Delay2sec_0
Or Am I wrong?

I understand goto $ very well explained when you explained goto $+2 I was lost.

BTW, I am interested in activating stopwatch in simulation any idea what to do or press?

Sorry for my Newbie questions!!

Thanks in advance
__________________
Hesham Ismail Mohammed Sharif
Thank me if you want

Last edited by uaefame; 13th November 2008 at 06:13 AM.
uaefame is offline  
Old 13th November 2008, 06:38 AM   #8
Default

Quote:
Originally Posted by uaefame View Post
Do you think, it should look like this

Code:
Label1
    decfsz    d1, f
    goto    Label2  
Label2
    goto    Label3
    decfsz    d2, f  
Label3
     decfsz    d3, f
     goto    Delay2sec_0
Or Am I wrong?
No, it should not look like that. You are wrong!

In this code:
Code:
Delay2sec_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
goto $+2 means move the program counter from the current program memory location to current memory location + 2. So PC + 1 = decfsz d2,f. And PC + 2 = the next goto $+2. That means it skips right to the bottom every time until that variable finishes counting down and becomes zero.

Have a look at Figure 13-1 on page 103
Delay Question-bleh.jpg
Each instruction takes 14 bits. Each time the program counter increments, it moves 14-bits higher in memory (to the next instruction).

Goto $+1 means move the PC (Program Counter) from the current position to the current position + 1 (increment it). In other words it just goto's to the next instruction. Pointless of course, since it was going there anyway.

Goto $+2 means move the PC two instructions ahead, skipping the next instruction. You can do the same thing with a label, but for little short skips like that, why bother? It's obvious (not to you yet, but you'll get it. ) what you're doing.

Clear as mud, right?
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 13th November 2008 at 07:30 AM.
futz is offline  
Old 13th November 2008, 07:48 AM   #9
Default

The OP was lost because he sees "GOTO $+2" meaning GOTO$ first, then adds 2 to the value of whatever variable.

Of course it should be GOTO(current address+2).
__________________
L.Chung
eblc1388 is offline  
Old 13th November 2008, 09:07 AM   #10
Default

Quote:
decfsz d1, f
what is f? how is it 1?
t.man is offline  
Old 13th November 2008, 09:17 AM   #11
Default

Quote:
Originally Posted by t.man View Post
what is f? how is it 1?
Code:
decfsz d1, f
The instruction is: decrement the value in 'd1' register and place the result back into 'd1' .
The 'f' is the part of the instruction which tells the program where put the result of the decrement.
If the Instruction was decfsz d1, W it would decrement 'd1' and put the result in 'W', the working register.

OK.
__________________
Eric " Good enough is Perfect "
I will NOT answer PM's requesting technical help, please use the Forum
PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/
ericgibbs is offline  
Old 13th November 2008, 09:38 AM   #12
Default

Quote:
Originally Posted by ericgibbs View Post
Code:
decfsz d1, f
The instruction is: decrement the value in 'd1' register and place the result back into 'd1' .
The 'f' is the part of the instruction which tells the program where put the result of the decrement.
If the Instruction was decfsz d1, W it would decrement 'd1' and put the result in 'W', the working register.

OK.


I thought this instruction says ‘Decrement the register (in this case d1) by the number that follows the comma.

Last edited by t.man; 13th November 2008 at 11:18 AM.
t.man is offline  
Old 13th November 2008, 09:39 AM   #13
Default

Quote:
Originally Posted by ericgibbs View Post
Code:
decfsz d1, f
The instruction is: decrement the value in 'd1' register and place the result back into 'd1' .
The 'f' is the part of the instruction which tells the program where put the result of the decrement.
If the Instruction was decfsz d1, W it would decrement 'd1' and put the result in 'W', the working register.

OK.


I thought this instruction says ‘Decrement the register (in this case d1) by the number that follows the comma.
t.man is offline  
Old 13th November 2008, 10:10 AM   #14
Default

Quote:
Originally Posted by t.man View Post
I thought this instruction says ‘Decrement the register (in this case d1) by the number that follows the comma.
No, the decfsz d1,f and other 'dec's always change the contents of d1 reg by '1'.
Likewise a incf d1,f would always increment the contents of d1 reg by '1'.

If you wanted to change the contents of d1 reg by more than '1' you could use
add or sub intructions.

EDIT:
All of these instructions are on the PIC datasheet
Attached Thumbnails
Delay Question-esp01-nov.-13.gif  
__________________
Eric " Good enough is Perfect "
I will NOT answer PM's requesting technical help, please use the Forum
PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/

Last edited by ericgibbs; 13th November 2008 at 10:22 AM.
ericgibbs is offline  
Reply

Tags
delay, question

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
time delay relay question firealarmfrea785 Electronic Projects Design/Ideas/Reviews 1 23rd May 2008 04:01 AM
PIC Delay question Trevors Micro Controllers 7 22nd April 2008 01:33 PM
time delay question Chaos Electronic Projects Design/Ideas/Reviews 0 28th December 2007 07:41 PM
Delay Loop Question Broz Micro Controllers 10 11th December 2007 07:24 PM
Delay Symbol Question hotrodhed120 Micro Controllers 6 15th March 2007 05:58 PM



All times are GMT. The time now is 04:51 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker