---
+ Post New Thread
Results 1 to 5 of 5
  1. #1
    Member level 2
    Points: 1,377, Level: 8

    Join Date
    Feb 2009
    Posts
    51
    Helped
    0 / 0
    Points
    1,377
    Level
    8

    The concept of BIT Masking using ANDing and ORing Opertion in 'C'

    8051 BIT MASKING:


    I have to use same PORT (SAY P1) for BCD to 7-Segments and other for four different Switches.

    My Question is:

    How to mask BITS/PINS which does not cause any effect to other pins when i have to acces PORT for BCD to 7 -Segment
    Decoder.

    Please Clear me concept of BIT Masking using ANDing and Oring Opertion in 'C'

    Thanks

    Karan

    •   Alt22nd May 2009, 14:38

      advertising

        
       

  2. #2
    Advanced Member level 5
    Points: 160,151, Level: 95
    Awards:
    Downloads2nd Helpful Member

    Join Date
    Oct 2004
    Location
    West Coast
    Posts
    7,943
    Helped
    2302 / 2302
    Points
    160,151
    Level
    95

    mask concept in 8051

    AND them with a "1" and OR them with a "0" ..

    rgds,
    IanP



    •   Alt22nd May 2009, 17:46

      advertising

        
       

  3. #3
    Member level 2
    Points: 1,377, Level: 8

    Join Date
    Feb 2009
    Posts
    51
    Helped
    0 / 0
    Points
    1,377
    Level
    8

    bit masking in c

    Thank For Reply...


    But Please write that more clear.
    ...



    •   Alt22nd May 2009, 19:27

      advertising

        
       

  4. #4
    Advanced Member level 2
    Points: 5,571, Level: 17
    Kurenai_ryu's Avatar
    Join Date
    Jun 2006
    Location
    Bolivia
    Posts
    573
    Helped
    127 / 127
    Points
    5,571
    Level
    17

    masking bits

    I think its OR with a "1" to turn on a bit
    and AND with a "0" to turn off a bit...

    for example to turn on bit 3 (P1.3)
    Code:
    P1 |= (1<<3); // 0000 1000 in binary, it's bit 3 at 1
    to turn off the same bit 3 (P1.3)
    Code:
    P1 &= ~(1<<3); // 1111 0111 in binary, it's bit 3 at 0
    but as far as I remember... you could use port bit definition to work on individuals bits...
    Code:
    #include <reg51.h>
    sbit pin=P1^3; //bit P1.3 is named pin
    
    ...
    
    {
    pin=1; //to turn on...
    pin=0; to turn off...
    }
    well that's bit masking... buuuut maybe you need to out 4 bits for the bcd decoder, leaving the other 4 bits as inputs for the switches...

    let's make it the lower nibble to the bcd decoder (like a 74LS47) and the upper nibble to the 4 individual switches...

    Code:
    #include <reg51.h> //or someone with port definitions...
    sbit SW1=P1^4; // to read the switches...
    sbit SW2=P1^5;
    sbit SW3=P1^6;
    sbit SW4=P1^7;
    
    /* routine to out a 4 bit bcd number..*/
    void bcd_out(unsigned char bcd){
     if(bcd>9) bcd=0xF;//turn off, invalid numbers...
     P1=0xF0 | bcd; /*upper bits are inputs, leave them  with 1, lower bits are outputs... out the bcd number */
    }
    the PORT initial value of 0xFF makes the switches as inputs and the bcd decoder (like 7447) shut down...

    this code, is for something like keil C for 8051...(maybe RIDE will work to!)

    Hope it helps...



  5. #5
    Member level 2
    Points: 1,377, Level: 8

    Join Date
    Feb 2009
    Posts
    51
    Helped
    0 / 0
    Points
    1,377
    Level
    8

    keil bcd c 8051

    Thanks a lot...



+ Post New Thread
Please login