![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
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 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. | |
| |
| | #2 |
|
$ 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
| |
| |
| | #3 | |
|
Thanks for replying Quote:
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 | ||
| |
| | #4 |
|
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. | |
| |
| | #5 |
|
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.
| |
| |
| | #6 |
|
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
Code: Label1
decfsz d1, f
goto Label2
decfsz d2, f
Label2
goto Label3
decfsz d3, f
Label3
goto Delay2sec_0
__________________ bananasiong | |
| |
| | #7 |
|
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
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. | |
| |
| | #8 | |
| Quote:
![]() In this code: Code: Delay2sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f Have a look at Figure 13-1 on page 103 ![]() 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. | ||
| |
| | #9 |
|
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 | |
| |
| | #10 | |
| Quote:
| ||
| |
| | #11 |
| Code: decfsz d1, f 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/ | |
| |
| | #12 | |
| Quote:
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. | ||
| |
| | #13 | |
| Quote:
I thought this instruction says ‘Decrement the register (in this case d1) by the number that follows the comma. | ||
| |
| | #14 | |
| Quote:
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
__________________ 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. | ||
| |
|
| 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 |