SECTION III-7: MOVF Instruction in the PIC micro-controller

The  MOVF mnemonic is intended to perform MOVFW.

 

MOVF fileReg, D

 

If D=0, it copies the content of fileReg to WREG. If D=1, the content of fileReg is copied to itself. Typically we use the MOVF instruction to bring data into WREG from I/O pins, sometimes we use it to copy fileReg to itself for the purpose of testing fileReg contents. Examine the difference between the MOVWF and MOVF instructions. We used the MOVWF instruction earlier to move data to special function registers such as Port B. Also widely used to load fixed (literal) data into the RAM locations of the file register because there is no way we can load data into the file register directly.

The MOVF instruction is widely used to bring data from I/O ports such as Port B into the CPU. We also use the MOVF instruction to bring data into WREG from any special function registers from any location in the Generam Purpose RAM in order to perform arithmetic and operations on them.

In examples below, the only time we use the "MOVF fileReg, F" instruction to copy data from fileReg to itself is when we want to affect the flag bits of the status register.

 

Program to get data from the Special function registers of the Port B and send it to the Special function register of PORT C continuously.
AGAIN MOVF     PORTB, W ;bring data from Port B into WREG
            MOVWF  PORTC  ;send it to Port C
            GOTO AGAIN ;keep doing it forever

 

 

 

 

  

Program to get data from the Special function registers of the Port B. Add the value 5 to it and semd it to the Special function registers of Port C
MOVF     PORTB, W ;bring data from Port B into WREG
ADDLW   05H  ;add 5 to WREG
MOVWF  PORTC ;copy WREG to PORTC

 

 

 

 

  

More From Iamtechnical.com

Advertisement:

SiteLock