Connect with us

Bit manipulation in pic controllers

Discussion in 'Microcontrollers, Programming and IoT' started by electronicsLearner77, Jul 18, 2017.

Scroll to continue with content
  1. electronicsLearner77


    Jul 2, 2015
    I need to check for a flag like TRUE or False. Can i use char data type or bit type? By creating bit type is it advantageous? I mean to say will it reduce execution time? Also i want the code to be portable. Please advise.
  2. Minder


    Apr 24, 2015
    If a unique bit in a word or file, BTFSS, BTFSC.
    If you want to change it or clear it etc, then one of the Math operations XORWF etc etc.
  3. Amar Dhore

    Amar Dhore

    Dec 2, 2015
    Yes it is very useful and it is a very general logic and not specific to the controller. It saves space and execution time as the processor has to deal with a variable.
    I do it like this:

    #define bit_mask (err1 | err2 | err3 | .....|err8)
    define or declare err1, ...err8 as a bit.
    You can clear a bit with simply "AND" and set with "OR" logic.
    lets say I have to set a flag for err8 then

    uint8_t flagCeck;
    flagCeck = bit_mask | err8;
    clear with
    flagCeck = bit_mask & err8;

    Hope this helps.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day