Compact quicky for long delays

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sometimes people ask for "long delays". I came to this one, because it requires only 1 variable and appears to have a simple formula.
(Not tested yet)
I use it for the initial startup delay for 44780LCD.
With 1 more push you get a cubed delay value.

delay:		push	temp		;
dec:		dec 	temp		;
			brne 	dec			;
			pop 	temp		;3*temp*temp + 3*temp +2 + ret
			dec 	temp		;
			brne 	delay		;
			ret

;(temp-1) x {(groteloop-kleineloop) + (temp-1)x kleineloop} + 1x rechtdoor
;groteloop=2+1+1+2+1+2=9  kleineloop=1+2=3     rechtdoor=2+1+1+2+1+1=8+ret
;(temp-1) x {9 + (temp-1)x3} + 8 + ret
;3*temp*temp + 3*temp +2 + ret