Home     Contact     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
   
 Home      Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   



Value Loading Instructions

The most basic operations that needs to be done will be the value loading. These operations have to do with loading a binary, decimal or hexadecimal value on the W register or to a register. Before we start with the instructions, it would be good to explain how to choose each time a different base for your value loading:



Binary base

The 8-bit 16F88 micro controller can load binary values up to 8-bits. If you try to load binary values larger than 8-bits, only the first 8 bits will be taken into account and the rest will be omitted. To represent a binary value you use the following type:


  • b'10101010'

The 'b' letter before the value tells the compiler that a binary number follows. The quote are necessary to be added. Just like the decimal human-orientated base, if a binary number needs less than 8-bits to be represented, all zeros on the left side of the number can be omitted. For example, the decimal number 234 is the same as the 000234. The following example represents the decimal number 30 in binary form with two equal ways:


  • b'00011110'
  • b'11110'



Decimal base

The decimal base is human-orientated. This means that it is easier to understand the number 131 what means, rather than to see it in binary (b'10000011') or hexadecimal (0x83) base. The 16F88 8-bit system can handle decimal values up to 255 (b'11111111'). Same as above, if a larger number is entered, the higher bits will be omitted. To represent a decimal number, you follow the next type:


  • d'35'

The letter 'd' before the number tells the compiler that a decimal number will follow. The quotes are necessary.




Hexadecimal base

That is another useful base that you may need to know how to use. It is most useful because number representations such as memory positions use this base. To represent a hexadecimal number, you use the follow form:


  • 0xa2

Unlike before, the type does not require a letter before the number. Instead, the '0x' is used and no quotes should enclose the number. The 8-bit system that we use can handle hexadecimal numbers up to 0xff. Larger numbers will act as previously mentioned.




The instructions

Instruction Description
MOVLW k Loads a literal value 'k' to the W register

MOVWF f Moves the value from the W register to the file register 'f'

MOVF f , d Loads a value from the register 'f'. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'.


Now, let's see the instructions one by one:



MOVLW k

A most basic instruction is the literal value loading. As you will see, there is no direct way of loading a literal value to a file register. First, the value needs to be loaded to the W register and the W register shall be moved to the file register. This instruction affects to no Status bits.



Example
          movlw b'11011010';A binary value is loaded to the W register
          movlw d'218'     ;The same value in decimal base  is loaded to the W register
          movlw 0xda       ;The same value in hex base  is loaded to the W register




MOVWF f

This instruction is used to move the value in the W register to the file register 'f'. This instruction affects to no Status bits.



Example
;This example requires that you have declare a file register for example
;TempRegister          equ 0x20  
          movlw d'80'             ;the W register has the decimal value '80'
          movwf TempRegister      ;The TempRegister register has now the value '80'



MOVF f , d

This instruction is used to load a value from the file register. If d is 0 the value will be loaded to the W register, if d is 1 the value will be loaded back to the file register 'f'. The status that may be affected from this instruction are:

  • Z - Zero

There is a strange operation with this instruction. If you call it with the destination 'd'=1, then a value will be loaded from register 'f' back to register 'f'. So what? This instruction with destination 'd'=1 is used only to test for zero register. Because it has an affect on the Zero Status, if the register loaded is '0', the Zero Status shall be set on call. The instruction works the same way if the destination was 0 (W register) but it could be so that we want to test for zero register without destroying the W register.



Example
;This example requires that you have declare a file register for example
;TempRegister          equ 0x20  
          movlw d'80'             ;the W register has the decimal value '80'
          movwf TempRegister      ;The TempRegister register has now the value '80'
          movlw d'10'             ;the W register has the decimal value '10'
          movf TempRegister,0     ;The W register has now the decimal value '80'
   








Confirm your knowledge

There is an online test to check your knowledge on this page. You may reveal the test with the following button:






Previous page ---- Next page



Go back to the book contents

Go to the discussion forum of this book





 

Comments

  Name

  Email (shall not be published)

  Website

Notify me of new posts via email


Write your comments below:
BEFORE you post a comment:You are welcome to comment for corrections and suggestions on this page. But if you have questions please use the forum instead to post it. Thank you.


      

  • At 30 September 2013, 20:55:18 user Mario wrote:   [reply @ Mario]
    • Thank you for the good site .I'm French Canadian from Quebec city.
      Your site is very funny for learn pic programming.
     






    No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise without the prior written permission of the author.

    Read the Disclaimer


    All trademarks used are properties of their respective owners.
    Copyright © 2007-2009 Lazaridis Giorgos.
    All rights reserved.






     HOT in heaven!


  • Disclaimer
  • Book Contents
  • Discussion forum

  • Basics
  • What will you need
  • Choosing the right PIC
  • The MPLAB
  • Getting familiar with the MPLAB environment
  • Creating a new project
  • Open and close projects
  • Creating new files and including them in the project
  • Your very first assembly program
  • Compile a program and transfer to the PIC
  • Section 1: Beginner's theory
  • Memory Organization
  • The Data Memory Organization
  • The Program Memory Organization
  • The instructions
  • General knowledge about instructions
  • Value Loading Instructions
  • Program Flow Instructions
  • Mathematic Instructions
  • Logic Function Instructions
  • Bit Orientated Instructions
  • Byte Orientated Instructions
  • Miscellaneous Instructions
  • The Basic Special Function Registers
  • The Status Register
  • The Option_Reg Register
  • The TRIS and PORT registers
  • Beginner's PIC Tutorials
  • How to use our PIC Tutorials
  • A Pushbutton turning an LED on and off
  • A Simple LED Flasher
  • Interfacing Multiple Switches - The internal Pull-Up resistors
  • An LED Sequencer
  • Interface a Single 7seg Digit
  • Interface Multiple 7seg Digits
  • A 3-digits Decimal Counter
  • A Clever Button
  • Section 2: Intermediate theory
  • Instruction Cycle Duration and Calculated Delays
  • The Timer Modules - Timer0
  • The Timer Modules - Timer1
  • The Timer Modules-Timer2



  • NEW in heaven!



    New Theory: AC electric motor working principle






     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS   

    Site design: Giorgos Lazaridis
    © Copyright 2008
    Please read the Terms of services and the Privacy policy