Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Clearing the Second Variable

Status
Not open for further replies.

Suraj143

Active Member
This coding I have inside ISR. What I need is to make the output to be low after passing the value in Minute variable. But before going low it must pass the output high section.

My problem is without clearing the Second variable it will miss 5 seconds or I have to add 65 to Second variable. Here I have cleared Second variable.

Is my coding ok?

Code:
ISR	decfsz	COUNT,F
	goto	Away
	movlw	.100		;
	movwf	COUNT		;generating 1 sec part
								
	incf	Second,F
	movf	Second,W	;has it reached 5 sec?
	xorlw	.5
	btfss	STATUS,Z
	goto	Away1
	btfss	Enable,1	;check the Enable bit?
	goto	Away1
	[COLOR="Red"]bsf	PORTB,0[/COLOR]		;turn ON after 5 seconds
	nop			
	bcf	Enable,1	;turn off enable bit
	[COLOR="Red"]clrf	Second	[/COLOR]					
Away1	movf	Second,W
	xorlw	.60
	btfss	STATUS,Z
	goto	Away					
	clrf	Second			
	incf	Minute,F
	movf	Minute,W
	xorlw	.5		;has it reached 5 min?
	btfss	STATUS,Z
	goto	Away
	clrf	Minute
	[COLOR="Red"]bcf	PORTB,0[/COLOR]		;turn off after 5 mins
	bsf	Enable,1
 
I don't understand what you are trying to do. Should bit 0 of port b be on for 5 seconds every 5 minutes?

Mike.
 
Thanks Mike
PORTB,0 must turn ON 5 mins & off period is 5seconds.Thats what I did.I want to confirm is this ok?
 
You code looks like it will work. Does it work?

I can't help thinking that it would be simpler to count the 5 seconds rather than minutes. You can then check for your count being 60.

Something like,
Code:
ISR	decfsz	COUNT,F
	goto	Away
	movlw	.100		;
	movwf	COUNT		;generating 1 sec part	
	incf	Second,F
	movf	Second,W	;has it reached 5 sec?
	xorlw	.5
	btfss	STATUS,Z
	goto	Away1
	bsf	PORTB,0		;turn ON after 5 seconds
	clrf	Second
	incf	Count5,F
Away1	movf	Count5,W
	xorlw	.60
	btfss	STATUS,Z
	goto	Away					
	bcf	PORTB,0		;turn off after 5 mins
	clrf	Count5

Note, the 60 is simply the number of 5 second periods in 5 minutes and shouldn't be confused with seconds in a minute.

Mike.
 
WOW You got it, your method is short & sweet.

Thanks for that so I dont need to check the Enable bit everytime.
Thats the secret in your coding.

Thanks Mike for the very useful codings.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top