Reputation: 780
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!
Upvotes: 3
Views: 3568
Reputation: 506
On the PIC18 device you can use the movff
instruction to do what you are after - copy a value between two registers. The movf
instruction only allows you to copy the value from a register into the working register.
Also the ordering of your movlw
and movwf
instructions at the start of the program are back to front. You call movlw
to load a constant value out of program memory into the working register, then movwf
to copy that value out of the working register into data memory.
This site has an online PIC simulator and tutorials that explains how this all works in more detail:
http://www.microcontrollerjs.com
Upvotes: 1