I am trying to learn assembly programming with MPLAB X and a PIC18F1320 microcontroller. I have been following the MPASM User's Guide (http://ww1.microchip.com/downloads/en/DeviceDoc/33014J.pdf) and have gotten an LED to blink from the RB0 pin on my microcontroller. I wrote a program to make an LED blink once every 512 ticks. I am having trouble figuring out how to change the delay from 512 to a variable quantity so I can change it somewhere else in the code. Ideally, the line
movf 0xFF,count1
would be replaced with
count1=delay1
where delay1 is the variable set to 0x20 earlier in the code.
Here is the code:
#include "p18F1320.inc"
CONFIG OSC = INTIO1 ; Oscillator Selection bits (Internal RC oscillator, CLKO function on RA6 and port function on RA7)
cblock 0x20 ;start of data section
count1 ;delay variable
delay1 ;length of delay
endc
org 00 ;\
movwf PORTB ; |
movlw 0x00 ; |
movwf TRISB ; |--Start program and configure I/O pins
movlw 0x00 ; |
movwf ADCON1 ; |
movlw b'00000110' ;/
movwf delay1 ; Set the variable delay1=0x20
movlw 0x20 ;/
loop call BLINKONCE ; Blink loop
goto loop ;/
BLINKONCE ;\
bsf PORTB,4 ; |
call DELAY ; |--makes I/O pin RB4 turn on and off once with a delay in between
bcf PORTB,4 ; |
call DELAY ;/
DELAY
movf 0xFF,count1 ;I want to be able to set count1=delay1 right here
loop2 decfsz count1, 1 ; Delay loop with length=count1
goto loop2 ;/
return ; end program
end ;/
THANKS!