This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

The meaning of BIT1, BIT2, BIT3....etc.....

Other Parts Discussed in Thread: MSP430F5529

Hello,

I have a very basic question.

In code composer when programming a msp4305529, I've notices that registers such as P7DIR uses the names of the bits of the registers?

Such as BIT1, BIT2....in the appropiate bit location.  

My question is how do I know what the value of BIT1, or BIT2 is?   0  or 1?????

I can't see it assigned that in the header files?

Sincerely,

Jim

  • Pressing F3 in the CCS editor should take you to the definition of whatever's under the cursor.

    In your case the BITx defines should be found in msp430f5529.h, and will look like this:

    #define BIT1                   (0x0002)
    #define BIT2                   (0x0004)
    
  • Jim Papay said:
    My question is how do I know what the value of BIT1, or BIT2 is?

    That is a very tricky question. And Robert Cowsill gave a very tricky answer. Saying BIT1 means the same thing as saying 0x0002. Saying BIT2 means the same thing as saying 0x0004.

    I would say the value of BIT1 could be either 0 or 1. The value of BIT2 could also independently be 0 or 1.

  • Yes, that is what I mean? The values shown in the header file is an address location?
    I suppose the bottom line is ..... "How should I interpret BIT1, BIT2...?
  • >The values shown in the header file is an address location?
    No. They are bit masks of 16 bit register for single bit of the register.
  • ok, now we are getting somewhere:)
    If the BIT1 has a mask of 0x0010, what is this the mask for?
    And how does it become for a single bit of what register?
  • Allow me to use an example.

    We often use a multi-digit number with a decimal point followed by two more decimal digits to express dollars and cents; e.g., 123.45

    Now what is the value of the first digit after the decimal point?

    We can answer this question in many ways. They seem to contradict with each other. But they are all correct in their own ways.

    One answer is, its value is 10 cents or 1 dime. (Meaning the number of dimes.)
    Another answer could be, the value is either 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9
    Yet another answer could be, the value is either 0, 10, 20, 30, 40, 50, 60, 70, 80, or 90 cents.
  • >If the BIT1 has a mask of 0x0010, what is this the mask for?
    >And how does it become for a single bit of what register?

    No offense, but {facepalm}. Seems, you are trying to learn C programming language hard way: by using online forum :) Those who did succeed learning it - used books and examples, some even avoided to visit library and bookshop because there's loads of learning resources on the internet. Here in this forum like to chat about msp430 specifics and it's applications, not about very basic programming questions.
  • Well that has got to be the most sarcastic answer I have received on a TI forum!!!
    I have taken C programming class, fortran, studied C++, Taught myself C#, etc.....
    I know what masking is.......I have read the data sheets and user manuals on this topic.
    I have been receiving very generalized answers to a specific question?
    It doesn't look like I will get answered a very simple question?
    Thanks for nothing and your lack of support and encouragement.
  • >I have taken C programming class, fortran, studied C++, Taught myself C#, etc.....
    It is actually hard to imagine how you missed topic we are talking about. Seriously.

    >If the BIT1 has a mask of 0x0010, what is this the mask for?
    BIT1 do not have mask 0x0010 but 0x0002 instead. It is mask for 1st (counting from 0) bit of ANY register or 16bit variable.
  • How should I interpret BIT1, BIT2...?

    They are shortcuts for accessing specific bits in a byte/word (BIT0 is just the first bit, BIT1 the second bit, and so on). They do not really have a meaning beyond that; they are just a shorter way of writing "(1 << x)".

    The bits in most registers do have a meaning, so it would not make sense to use the BITx symbols for those. The bits in the GPIO registers, however, just affect the corresponding pins, whose meaning is determined by your custom hardware. So if you wanted to check the signal at pin P2.3, you would need to read the fourth bit. This could be written either as "if (P2IN & 8)" or as "if (P2IN & (1 << 3))" or as "if (P2IN & BIT3)".

  • The problem is your a mean person and shouldn't be a part of this forum.
    And your very general in your answers leaving out important information.
  • Thank-you for answering my question. I really appreciate it.
    And thank-you for your support and kindness and understanding.
  • >And your very general in your answers leaving out important information.
    Yes. Even now I will do exactly that :D I usually _avoid_ to give "packaged solutions", try to give direction instead - leaving option for other party to walk the path to answer themselves. Especially in cases like yours where simple internet search would save whole thread.
  • "We can answer this question in many ways."
    Base don the fact that currency uses a decimal base, there is an universal answer: Each digit has 1/10 of the value of the digit left of it and 10 times the value of the diit right of it, multiplied with its cardinal value. That's by definition.
    How many chewing gums you can buy for it is a completely other thing :)

    However, the answer to the question is:
    If the BIT1 has a mask of 0x0010 then I don't know what this mask should be for.
    Because BIT1 has a value of 0b10 (== 0x0002). And it doesn't have a mask. It is/has a value. And can be used as a mask.
    Besides this, Clemens has explained properly how the BITx defines can be used. However, he didn't explain why one should use them.
    Since the value of these surely never changes, one could as well use the numeric constants.
    But it is easier to find all occurrences on BIT3 in a source code and check whether to change them, than finding all occurrences of '8' and checkign them for a required change. One should in general use defines instead of plain numbers because the define documents the meaning (by its name) and not just the value of a constant. Using "BIT2" makes clear you explicitly mean a bit and not just a number.
  • JMG,
    I consider this as a culture thing.
    circumference = BIT1 * pi * radius[
    is legal and moral, but ill-mannered.
    OCY

**Attention** This is a public forum