Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

delay code >> pleaz help

Status
Not open for further replies.

solidsnike

Member level 1
Joined
Apr 16, 2006
Messages
37
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,526
hiiii everybody

this is delay call function for 5 minutes but when i used on my pic16f84a and applyed my circuit it didnot operate >>>

i need konw what ia meaning by ( cblock ) in this code
Code:
cblock
	d1
	d2
	d3
	d4
	endc

and what is meanining by ($+2)


Code:
; Delay = 300 seconds
; Clock frequency = 4 MHz

; Actual delay = 300 seconds = 300000000 cycles
; Error = 0 %

	cblock
	d1
	d2
	d3
	d4
	endc

			;299999995 cycles
	movlw	0x54
	movwf	d1
	movlw	0xA1
	movwf	d2
	movlw	0xFD
	movwf	d3
	movlw	0x02
	movwf	d4
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	$+2
	decfsz	d4, f
	goto	Delay_0

			;5 cycles
	goto	$+1
	goto	$+1
	nop


and thanks
 

Cblock assigns an incremental constant number to each defined member inside it. This infact are the ram locations for that member/variable.
In your case, suppose RAM starts from 0x20 then
d1 will be located at RAM address 0x20
d2 will be located at RAM address 0x21
d3 will be located at RAM address 0x22
d4 will be located at RAM address 0x23


$+2 means address greater by 2 words than the current instruction address.
$ means address of the current instruction being executed.

Example
Here: GOTO Here
is same as
GOTO $
 

    solidsnike

    Points: 2
    Helpful Answer Positive Rating
thankx very much for help

but If you can explain this part pleaz >> i need to know when ($+2) is come what the next instruction will be executed in this part (Delay_0 or decfsz d2, f )

Code:
Delay_0
decfsz   d1, f 
   goto   $+2 
   decfsz   d2, f 
   goto   $+2 
   decfsz   d3, f 
   goto   $+2 
   decfsz   d4, f 
   goto   Delay_0

and in this part

Code:
goto   $+1 
   goto   $+1 
   nop
 

yes vsmGuy is right?!
 

Click on "Helped me" button if I helped you.
 

solidsnike said:
thankx very much for help

but If you can explain this part pleaz >> i need to know when ($+2) is come what the next instruction will be executed in this part (Delay_0 or decfsz d2, f )

Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto $+2
decfsz d4, f
goto Delay_0

I this case when $+2 is encountered, PC will goto Delay_0. The instructions that will be executed are shown in green.

solidsnike said:
and in this part

Code:
goto   $+1 
   goto   $+1 
   nop
goto $+1 will simply goto next instruction...it is used only to waste time to generate delay.
 

    solidsnike

    Points: 2
    Helpful Answer Positive Rating
look to the code below .... the delay code of 4 second is in the red color.... and the main code in the black .... when insert the delay code to the main code and convert it to the Hex file ... there is no error and the process is success ...... ,and when loaded to the pic the loading is success but the code not opreate well and the led on the port B0 remain on .... and the led on the port B2 is remain off

can any body tell me .... if there are errors in my code ... i'm using picf84a and loaded many code before and are operating very well without errors



processor 16f84a
include <p16f84.inc>
__config _RC_OSC & _WDT_OFF & _PWRTE_ON


; Program


cblock
d1
d2
d3
d4
endc



org 0 ; start at address 0
; At startup, all ports are inputs.
loop
; Set Port B to all outputs.
movlw 0x00 ; w := binary 00000000
tris PORTB ; copy w to port B control reg
; Put a 1 in the lowest bit of port B.
movlw 0x01 ; w := binary 00000001
movwf PORTB ; copy w to port B itself
call Delay
movlw 0x04
movwf PORTB
call Delay ; Stop by going into an endless loop
goto loop


Delay
;3999994 cycles
movlw 0x23
movwf d1
movlw 0xB9
movwf d2
movlw 0x09
movwf d3
Delay_0
decfsz d1, f
goto Delay_0
s1 decfsz d2, f
goto s1
s2 decfsz d3, f
goto s2


;4 cycles (including call)
return

end ; program ends here
 

dont forget me pleaz.... i need your help
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top