microcontroller - How to move a variable's value into another variable in assembly -
i trying learn assembly programming mplab x , pic18f1320 microcontroller. have been following mpasm user's guide (http://ww1.microchip.com/downloads/en/devicedoc/33014j.pdf) , have gotten led blink rb0 pin on microcontroller. wrote program make led blink once every 512 ticks. having trouble figuring out how change delay 512 variable quantity can change somewhere else in code. ideally, line
movf 0xff,count1
would replaced
count1=delay1
where delay1 variable set 0x20 earlier in code.
here code:
#include "p18f1320.inc" config osc = intio1 ; oscillator selection bits (internal rc oscillator, clko function on ra6 , 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 , configure i/o pins movlw 0x00 ; | movwf adcon1 ; | movlw b'00000110' ;/ movwf delay1 ; set 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 , off once delay in between bcf portb,4 ; | call delay ;/ delay movf 0xff,count1 ;i want able set count1=delay1 right here loop2 decfsz count1, 1 ; delay loop length=count1 goto loop2 ;/ return ; end program end ;/
thanks!
on pic18 device can use movff
instruction after - copy value between 2 registers. movf
instruction allows copy value register working register.
also ordering of movlw
, movwf
instructions @ start of program front. call movlw
load constant value out of program memory working register, movwf
copy value out of working register data memory.
this site has online pic simulator , tutorials explains how works in more detail:
Comments
Post a Comment