Tuesday, 15 July 2014

microcontroller - How to move a variable's value into another variable in assembly -


I am trying to learn assembly programming with MPLAB X and a PIC18F1320 microcontroller. I am following the MPASM User's Guide () and want to snooze my microcontroller with RB0 Pin. I wrote a program to apply the LED blinking once in every 512 ticks. I'm having trouble finding out how to change the delay from 512 to a variable quantity, I can change it somewhere else in the code. Ideally

  will be replaced with movf 0xFF, count1  

  count1 = delay1  

Where delay is already set the variable to 0x20 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) CPL 0x20; Counting the data section count 1; Delay delay delays 1; Delay length Andrag ORG 00; \ Movwf PORTB; | Movlw 0x00; | Movwf TRISB; | --start program and configured I / O pin movlw 0x00; | Movwf ADCON 1; | Movlw b'00000110 '; / Movwf delay1; Variable delay 1 = 0x20 movlw 0x20; Set up / Loop calls BLINKONCE; Loop loop goto loop; / BLINKONCE; \ Bsf PORTB, 4; | Call delays; | - BCF PORTB, I / O pin RB 4 on and off with a delay between 4; | Call delays; / Daily movf 0xFF, count 1; I want to be able to set count1 = delay1, here loop2 decfsz count1, 1; Delay loop with length = count 1 goto loop 2; / Return; End program end; /  

Thanks!

After the device on PIC 18, to do what you are doing movff < / Code> instructions - Copy a value between two registers movf instructions only allows you to copy the value from a registered register.

As well as instructions are coming out at the beginning of your movlw and movwf program. To load a constant value from program memory in the work memory, call movlw , then copy the value from the movwf registering in the data store. .

This site contains an online PIC simulator and tutorials that show how all this works in more detail:


No comments:

Post a Comment