Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 4th November 2009, 01:03 PM   #1
Default loop problem.

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
..
..
..
..
Quote:
Is it possible to use the DECFSZ command?

Thanks!

Last edited by Roger_NO; 4th November 2009 at 01:05 PM.
Roger_NO is offline  
Old 4th November 2009, 01:09 PM   #2
Default

Of course it is, that's what it's there for - check my tutorials where it's used a LOT - one example, the RS232 receive and transmit routines.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 5th November 2009, 07:09 AM   #3
Default 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
Roger_NO is offline  
Reply

Tags
loop, problem

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
open loop and closed loop control systems waheeda Electronic Projects Design/Ideas/Reviews 2 27th March 2009 05:20 PM
loop time out homemade24 Micro Controllers 3 12th February 2009 02:33 PM
Ac Loop Oscillator magnetman12003 Electronic Projects Design/Ideas/Reviews 1 29th March 2008 10:33 PM
help in vhdl for loop abilash Electronic Projects Design/Ideas/Reviews 2 8th April 2007 08:54 AM
FOR loop in C eblc1388 Micro Controllers 12 10th January 2007 11:24 PM



All times are GMT. The time now is 04:47 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker