Close

Delay loop code in ASM PIC16F628 / PIC16F819

A project log for Micro tutorials for microcontrollers

Tutorials and advice for those who are new in developing the MCU programming skills

marius-taciucMarius Taciuc 05/02/2018 at 05:460 Comments

In the previous videos I've been explaining how to initialize the ports of the PIC16f628 microcontroller. This other video shows how to write a delay loop and blink some LEDs for fun. The code of the main loop and of the delay loop is listed below in case you want to copy-paste it:  Check also funelectronicstoday.com for more fun projects.

;MAIN LOOP----------------

REPEAT
    MOVLW 0X00
    MOVWF PORTB
    CALL DELAY 
 
    MOVLW 0X01
    MOVWF PORTB
    CALL DELAY
    
    MOVLW 0X02
    MOVWF PORTB
    CALL DELAY
    
    MOVLW 0X04
    MOVWF PORTB
    CALL DELAY
    
    MOVLW 0X08
    MOVWF PORTB
    CALL DELAY
    
    CLRF PORTB 
    
    CALL DELAY

     
 
 GOTO REPEAT ; END OF MAIN LOOP 
 

DELAY
 CLRF DELAY1
 CLRF DELAY2

DELAYLOOP 
 DECFSZ DELAY2,F
 GOTO DELAYLOOP
 
 DECFSZ DELAY1,F
 GOTO DELAYLOOP
 
 
 RETURN

Discussions