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   



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.

Instruction Description
BSF f , b The Bit 'b' in file register 'f' is Set (1).

BCF f , b The Bit 'b' in file register 'f' is Cleared (0).

BTFSS f , b If the bit 'b' in file register 'f' is 1, then the following instructions is not executed and a 'NOP' is executed instead. If the bit is 0, the instructions is executed normally.

BTFSC f , b If the bit 'b' in file register 'f' is 0, then the following instructions is not executed and a 'NOP' is executed instead. If the bit is 1, the instructions is executed normally.

SWAPF f , d The upper and lower nibbles of file register 'f' are exchanged. 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:



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:






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 24 August 2013, 23:25:48 user ravi wrote:   [reply @ ravi]
    • Thank you for explaining all the nuances in the pic assembler programming.
      A well presented explanation of the workings of pic devices.
     






    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