View Single Post
Mentor
31Aug2008,16:00  
xpi0t0s's Avatar
Your delay loop isn't written correctly. Try dry running it on paper and you should see what's wrong with it. Remember decfsz means decrement and skip the next instruction if zero, so if the dec doesn't set it to zero it'll do the goto, and if it does it'll jump to the next decfsz.

Compare with the following code taken from one of the Velleman kit K8048 examples:
Code:
DELAY_ROUTINE   MOVLW   D'100'         ;54 Generate approx 10mS delay at 4Mhz CLK
                MOVWF   TIMER2
DEL_LOOP1       MOVLW   D'100'	       ;60	
                MOVWF   TIMER1
DEL_LOOP2       BTFSC	PORTA,SW1
		GOTO	MENU
		BTFSC	PORTA,SW2
		GOTO	MENU
		BTFSC	PORTA,SW3
		GOTO	MENU
		BTFSC	PORTA,SW4
		GOTO	MENU
		DECFSZ  TIMER1,F
                GOTO    DEL_LOOP2
                DECFSZ  TIMER2,F
                GOTO    DEL_LOOP1
		RETLW   0
There's an inner loop and an outer loop. For your solution you'll need four nested loops.

> the program should be running every five minutes

Don't mean to nitpick but if this is the case the delay should be 2.5 minutes, not 5 minutes. Or do you mean the program should toggle the state of PortB.0 every five minutes?

How accurate does it need to be? If it needs to be exactly every five minutes without any kind of drift (apart from thermal) then you'll need to take the exact RC time into account, the time to do the bsf/bcf and the time to call a subroutine.