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.

loop time out

Status
Not open for further replies.

homemade24

New Member
still trying to learn assembly

If I'm thinking right this would loop until PORTA,1 is set
but if I needed it to carry on if PORTA,1 does not set in say 20 sec.
what would be the best way to do it in assembly


BTFSC PORTA,1
GOTO AUNT NANCY'S
GOTO $-2
GOTO UNCLE Bob'S

something like this is how I would do it in Pic Basic Pro

A VAR WORD
For A= 0 TO 20000 '20 SEC.
Pause 1
IF PORTA,1 =1 Then
goto aunt Nancy's

EndIF
Next A
goto uncle Bob's


thanks to all
 
Hi,

Labels need to be one word in assembler e.g. AUNT_NANCY'S, UNCLE_Bob'S.


As for the time maybe something like;
Code:
BTFSC Timer1_done_bit ;has timer 1 timed out (overflowed)?
GOTO UNCLE_Bob'S      ;yes it has
BTFSC PORTA,1         ;no it has not
GOTO AUNT_NANCY'S  
GOTO $-4

UNCLE_Bob'S:
bcf     Timer1_done_bit

Note:
('Timer1_done' is a made up label)
 
Last edited:
You can do it pretty much the same as your basic program,

Code:
		movlw	high(.20000)+1
		movwf	CounterHi
		movlw	low(.20000)
		movwf	CounterLo
WaitPortA	call	Delay1mS
		btfsc	PORTA,1
		goto	Done
		decfsz	CounterLo,F
		goto	WaitPortA
		decfsz	CounterHi,F
		goto	WaitPortA
Done		nop

The Delay1mS code is also rather simple,
Code:
Delay1mS	movlw	.249
DelayLoop	addlw	.255
		btfss	STATUS,Z
		goto	DelayLoop
		return
This assumes a 4MHz oscillator.

Mike.
 
Thanks Guy just what the doctor ordered
different people have to learn things different ways
and hate to say it but I'm one of the one that has to do it on a "as need be bases"
because tomorrow when I wake up I will have forgot not only how I did something
BUT WHY I EVEN DID IT
as always thanks
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top