Thread: map bits and pins

  1. #1
    Registered User
    Join Date
    Aug 2022
    Posts
    5

    map bits and pins

    Hi,
    I have unsigned char myvar, i got 5 bits and 5 pins 30, 40, 50, 60 and 70. need to map the bits to pins so that I loop though each bit in myvar and sets its pin High or low. I am using array but like to learn a clever way like using structs, unions, etc.

  2. #2
    Registered User
    Join Date
    Apr 2021
    Posts
    148
    Don't. You want the exact opposite of a "clever way."

    Try using a struct, instead:

    Code:
    struct {
        int8_t bp_pin_id;
        uint8_t bp_bit_mask;
        int8_t bp_set_state;
    } Bits_to_pins = {
    { 30, 0x40, PIN_HIGH },
    { 40, 0x01, PIN_LOW },
    { 50, 0x02, PIN_LOW },
    { 60, 0x80, PIN_HIGH },
    { 70, 0x08, PIN_LOW },j
    };

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing particular bits and detecting toggled bits
    By Nordomus in forum C++ Programming
    Replies: 11
    Last Post: 04-13-2018, 12:07 PM
  2. Extracting certain bits from sequence of bits
    By lucaspewkas in forum C Programming
    Replies: 5
    Last Post: 10-06-2007, 12:22 AM
  3. Buying RAM (how many pins?)
    By Stan100 in forum Tech Board
    Replies: 2
    Last Post: 08-15-2005, 07:00 PM
  4. New idea on conveting byte to bits/bits to byte
    By megablue in forum C Programming
    Replies: 10
    Last Post: 10-26-2003, 01:16 AM
  5. copy some bits into a 8 bits binary number
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 05-29-2002, 10:54 AM

Tags for this Thread