| ||
Bit Orientated Instructions Another very interesting set of instructions is the ones that have to do with the bits of a byte. The 16F88 is an 8-bit micro controller. This means that each byte will have 8 bits. Just to remind you that the most left bit is called MSB (Most Significant Bit) while the most right is called LSB (Less Significant Bit). Also, the numbering of the bits starts from zero base and counts form the LSB to the MSB. Thus, the LSB bit is the bit nmber 0 and the MSB is the bit number 7.
Now, let's see the instructions one by one: BSF f , b With this instructions you can set a bit within a register. The Status is not affected with this instruction. The 'b' can be a number from 0 to 7 corresponding to a bit position. Example ;This example requires that you have declare a file register for example ;TempRegister equ 0x20 bsf TempRegister,3 ;The bit in place 3 in register 'TempRegister' is SET (1) bsf PORTA,0 ;The bit in place 0 in register 'PORTA' is SET (1). If this ;port pin is output, the corresponding pin will become HIGH BCF f , b With this instructions you can clear a bit within a register. The Status is not affected with this instruction. The 'b' can be a number from 0 to 7 corresponding to a bit position. Example ;This example requires that you have declare a file register for example ;TempRegister equ 0x20 bcf TempRegister,3 ;The bit in place 3 in register 'TempRegister' is CLEARED (0) bcf PORTA,0 ;The bit in place 0 in register 'PORTA' is CLEARED (0). If this ;port pin is output, the corresponding pin will become LOW BTFSS f , b This instruction can be used for conditional execution of instructions. The two last lettes 'SS' stand for Skip if Set. The very next instruction after the BTFSS will be executed only if the bit 'b' withing register 'f' is NOT SET. Otherwise it will be replaced with a 'NOP' instruction and shall not be executed. The Status is not affected with this instruction. The 'b' can be a number from 0 to 7 corresponding to a bit position. Example btfss PORTA,4 ;Check bit '4' in register PORTA goto Bit_Was_Zero ;If '0' goto Bit_Was_Zero . . BTFSC f , b This instruction can be used for conditional execution of instructions. The two last lettes 'SC' stand for Skip if Clear. The very next instruction after the BTFSC will be executed only if the bit 'b' withing register 'f' is SET. Otherwise it will be replaced with a 'NOP' instruction and shall not be executed. The Status is not affected with this instruction. The 'b' can be a number from 0 to 7 corresponding to a bit position. Example btfsc PORTA,4 ;Check bit '4' in register PORTA goto Bit_Was_Zero ;If '1' goto Bit_Was_Zero . . SWAPF f , d This instruction is used to swap the nibbles of a register. When executed, the bits 0-3 will be swapped with the bits 4-7. 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'. The Status is not affected with this instruction. Example ;This example requires that you have declare a file register for example ;TempRegister equ 0x20 movlw b'11110000' ;W has the binary number '11110000' movwf TempRegister ;TempRegister has the binary number '11110000' swapf TempRegister,1 ;The nibbles in TempRegister are swaped ;Now TempRegister has the value '00001111' 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 |