d1 equ 0x0D //Making d1 equal 13
d2 equ 0x0E //Making d2 equal 14
d3 equ 0x0F //Making d3 equal 15
d4 equ 0x10 //Making d4 equal 16
org 0X000 //Set the following code to start at Address 0
goto Init //Jump to the beginning of the code.
//Mainly done as an interrupt thing, but not *really*
//needed unless you use interrupts
org 0X004 //Setting the code to start at Address 4
retfie //If an interrupt flag is set, it automatically jumps to 4.
//Not really needed if you're careful and make sure you're
//not setting up any Interrupts.
Init
bsf STATUS,RP0 //Switch to bank 1
clrf TRISB //Set all PORTB pins to output
clrf TRISA //Set all PORTA pins to output
bcf STATUS,RP0 //Switch back to bank 0.
clrf PORTA //Make sure PORTA pins are pulled low.
clrf PORTB //And PORTB pins, too.
Main
bsf PORTB,0 //Pull PORTB's first pin (RB0) high.
call Del5M //Call the Del5M subroutine. Skip the rest of Main for
//now.
bcf PORTB,0 //Welcome back to Main. Assuming all the dX registers
//(d1, d2, d3, and d4) are zeroed out, pull RB0 low
//again.
call Del5M //And now we go back to set up all the values and
//do that decfsz nonsense again. This time when it's
goto Main //done, we go back to the beginning of Main and
//pull RB0 high again. And it just repeats that like
//indefinitely.
Del5M
movlw 0x54 //Move the decimal 84 into W
movwf d1 //Move W into address defined in the EQU directive.
movlw 0xA1 //Just more moving values
movwf d2 //into registers. Doot de doo.
movlw 0xFD //Yep, more of the same.
movwf d3 //Weather's pretty nice today.
movlw 0x02 //Maybe I should mow the lawn.
movwf d4 //Okay, this part is done now.
Delay_0
decfsz d1, f //Here we decrease the value in the given register
//(d1 in this case). the ",f" afterwards just tells it
//to store the result back in the register it changed.
//If the register, however, is zero, the instruction
//makes the PIC skip the next instruction
goto $+2 //This instruction just says to jump two instructions.
//The $ value just means "current address", so one
//could also say "goto $-3" to go back 3 addresses,
//if the code needed that.
decfsz d2, f //Same old decfsz. Kind of a weird program flow going
goto $+2 //on here, but whatever floats their boat.
decfsz d3, f //It's early, I should probably get some breakfast.
goto $+2 //I've got some strawberry poptarts, that might do.
decfsz d4, f //Okay, almost done with this part.
goto Delay_0 //If d4 isn't zero yet, you have to go back to the
//beginning of this block of code and keep decfsz-ing
//until everything is zero. Then we move onto the
//next part.
;5 cycles
goto $+1 //These are just junk instructions, used because they
goto $+1 //take up 2 cycles each,
nop //when NOP only takes up 1 cycle and also does
return //nothing. Our Return here just makes us jump back
//to the main block. Let's go, shall we? Go back up.
end