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
 
LinkBack Thread Tools Display Modes
Old 6th March 2007, 04:18 PM   (permalink)
Default Question about Nigel Goodwins tutorials

One question about the sample code provided by Nigel Goodwin

at the bottom part of the delay loops the command "goto $+2" ? Where is it going to ?


Regards
Dennis

Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0

decfsz count1 ,f
goto d1
retlw 0x00

++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++



;Tutorial 1.2 - Nigel Goodwin 2002
LIST p=16F628 ;tell assembler what chip we are using
include "P16F628.inc" ;include the defaults for the chip
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)

cblock 0x20 ;start of general purpose registers
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc

org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)

bsf STATUS, RP0 ;select bank 1
movlw b'00000000' ;set PortB all outputs
movwf TRISB
movwf TRISA ;set PortA all outputs
bcf STATUS, RP0 ;select bank 0

Loop
movlw 0xff
movwf PORTA ;set all bits on
movwf PORTB
nop ;the nop's make up the time taken by the goto
nop ;giving a square wave output
call Delay ;this waits for a while!
movlw 0x00
movwf PORTA
movwf PORTB ;set all bits off
call Delay
goto Loop ;go back and do it again

Delay movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0

decfsz count1 ,f
goto d1
retlw 0x00

end
sbdwag is offline  
Old 6th March 2007, 04:31 PM   (permalink)
Default

that means jump two lines forward.
williB is offline  
Old 6th March 2007, 04:41 PM   (permalink)
Default

Thanks Ive looked all over for that even spent 60 dollars for a book looking for that. Thought it was refering to a hex location plus two

Got any good sources for answers to questions like this one.

Thanks again

Dennis
sbdwag is offline  
Old 6th March 2007, 05:02 PM   (permalink)
Default

Quote:
Originally Posted by sbdwag
Thanks Ive looked all over for that even spent 60 dollars for a book looking for that. Thought it was refering to a hex location plus two

Got any good sources for answers to questions like this one.
Where it came from, the MPASM helpfile - $ simply refers to the current address - $+1 is a common use, essentially a NOP, but it takes twice as long as a NOP, so it makes a double length NOP.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 6th March 2007, 05:34 PM   (permalink)
Default

Code:
goto $+2
Got to be careful with that if you plan on using 18 series chips.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is online now  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Basic Transmission question CamNuge General Electronics Chat 2 8th March 2006 11:08 PM
Nigel, about your tutorials 5.1 and 5.3 atferrari Micro Controllers 4 10th August 2005 11:11 PM
Congrats to Nigel Goodwin - now an Electro Tech moderator! ElectroMaster Feedback/Comments 9 18th April 2005 09:15 PM
Hey Nigel, LCD code question.... NewGeek Micro Controllers 5 3rd September 2004 05:37 PM
Data Logging question with high speed!!!! cubdh23 General Electronics Chat 4 16th August 2004 07:33 PM



All times are GMT. The time now is 07:47 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker