1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

help pls: delay programs for 5 minutes using PIC16F84A,, asm programming

Discussion in 'Assembly Language Programming (ALP) Forum' started by jn8b, Aug 27, 2008.

  1. jn8b

    jn8b New Member

    Joined:
    Aug 27, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    :embarasse could you help me with this? It is about microcontroller.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Probably best to set a timer with interrupt, then you can count the number of times the interrupt goes off. Or if you have an external real time clock it might have the functionality to interrupt you at a given time. Or if you just want to count off five minutes, write a counter subroutine, work out how long one iteration takes (remembering to take EVERYTHING into account - branches taking longer if they branch than if they don't, allowing for any interrupts etc (this also depends on how accurate you want to be)), then just count for the appropriate number of iterations to pass five minutes. So if your loop takes 100ns to count to 1, then 5 min=5*60*10,000,000=300,000,000. Count to 300 million and you're done. If you want to run something every five minutes then the counter approach will throw you off eventually unless you count all the instructions in your program (very tedious).
     
  3. jn8b

    jn8b New Member

    Joined:
    Aug 27, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    -thanks.. the program should be running every fives minutes. Yeah, it sounds difficult.

    -Can you please check this program? What's seemed to be wrong in it?

    Code:
    __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC
    
    d1	equ	0x0D
    d2	equ	0x0E
    d3	equ	0x0F
    d4	equ	0x10
    
    	org	0X000
    	goto	Init
    
    	org	0X004
    	retfie
    
    
    Init	bsf	STATUS,RP0
    	clrf	TRISB
    	clrf	TRISA
    	bcf	STATUS,RP0
    
    	clrf	PORTA	
    	clrf	PORTB
    
    Main	bsf	PORTB,0
    	call	Del5M
    	bcf	PORTB,0
    	call	Del5M
    	goto	Main
    
    Del5M	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
    	return
    
    	end
    
    -In anyway thanks a lot.

     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     
  5. jn8b

    jn8b New Member

    Joined:
    Aug 27, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    -Its doesn't need to be that exact since I will not be displaying the time (time is more difficult to be done in PIC),, we only chose five minutes as minimum for short time presentation in defense. The program will be the basis for the motors operation. Since our motor is a motor to of a washing machine its not ideal to be seconds or a minute delay.. It is most appropriate if we could to the delay for hours, but goodness we cannot even produce a good delay.

    -Somehow I notice that there something wrong with the program, but I couldn't pinpoint. I am not good in assembly. I'm still learning it by now.

    -Thanks for the codes... I'll try to figure it out..

    -hehe I'll be frank,, know what I been doing the thinking of the program for quiet sometime, but I end up knowing it as if for the first time.. as in worst.. to think that we are running out of time.. (a hateful act)

    -Thanks again..

     

Share This Page