| ||
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:
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:
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:
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:
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
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:
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: Comments
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. |
|
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 |