Wednesday, September 29, 2010

delay loops into our program

Let us put these delay loops into our program, and finish off by making it a real program by adding comments:
;*****Set up the Constants**** 
STATUS         equ       03h
TRISA             equ       85h
PORTA           equ       05h
COUNT1        equ       08h
COUNT2        equ       09h
;****Set up the port****  
bsf                   STATUS,5
movlw              00h
movwf              TRISA
bcf                   STATUS,5
;****Turn the LED on**** 
Start               movlw        02h
movwf               PORTA                                                 
;****Start of the delay loop 1**** 
Loop1          decfsz      COUNT1,1
goto              Loop1 
decfsz           COUNT2,1
goto              Loop1   
;****Delay finished, now turn the LED off**** 
 movlw              00h 
movwf              PORTA 
;****Add another delay**** 
Loop2
decfsz             COUNT1,1
goto                 Loop2    
decfsz             COUNT2,1
goto                 Loop2
;****Now go back to the start of the program
goto                 Start
;****End of the program**** 
end                              ;Needed by some compilersand also just in case we miss the goto instruction.
 
 You can compile this program and then program the PIC.  Of course, you will want to try the circuit out to see if it really does work.  Here is a circuit diagram for you to build once you have programmed your PIC.

No comments:

Post a Comment