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 problem.

Status
Not open for further replies.

Roger_NO

Member
Hi,

Im tryning to get a port on my PIC16F628A to go logic high a specific number of times.

I am currently using the BSF and the BCF commands, but the code is messy and takes to much space. Is there a way to loop a specific number of times, so i dont have to repeat the BSF and BCF so many times?

Eksample "in my mind"

Code:
Start
 bsf       portb,0
 call       Delay
 bcf       portb,0
 goto     start (3 times then continue to the next line)

next line
..
..
..
..

Is it possible to use the DECFSZ command?

Thanks!
 
Last edited:
ok

ok.

Will this work?

Code:
cblock     0x20
              
              d1
              d2
              d3
              count1

endc

;Port define

 banksel    TRISA
 movlw      0xff
 movwf      TRISA 
 movlw      0x00 
 movwf      TRISB
 banksel    PORTA

;init

 movlw      d'3'
 movwf      count1
 clrf       PORTA
 clrf       PORTB
 
Start
 btfss      PORTA,0
 goto       Start
S1
 bsf        PORTB,0
 call       delay1
 bcf        PORTB,0
 call       delay1
 decfsz     count1
 goto       S1
 
Next line...



;Sub routines

delay1

        movlw	0x3F
	movwf	d1
	movlw	0x9D
	movwf	d2
Delay1_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	Delay1_0

			
	goto	$+1
end
 
Status
Not open for further replies.

Latest threads

Back
Top