This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

#define COUNT 2000

can any one give me the meaning of following line

#define COUNT  2000
#define KEY2    0x2F
#define KEY1    0xF8

COUNT,KEY2,KEY1 are the name's given which we going to use next in the prog. but what is 2000,0x2F,0xF8 is address i.e memory location or simply just value.

  • "can any one give me the meaning of following line"

    Other than the author or provider of the software, no.

    "or simply just value."

    As far as the snippet you've provided goes, they are just values. How they might subsequently be used (or abused) elsewhere is completely impossible to tell!

    Today's lesson is: always fully comment all definitions!

    The comments should answer your questions!

  • i have some sample prog. in that some are act like address while some are limit's value(higher and lower limit value) some number's are used twise or thrise that are definatly not addresses. they are also not a value. so what is that

  • That is all totally valid!

    Numbers in and of themselves are abstract!

    Even in real life, No pure number ever has any meaning in itself - only when you know the context does it become meaningful.

    eg, "three" on its own is meaningless; it only gains meaning when you know what the "three" relates to - three apples, or three miles, or house number three, or third turning, etc, etc, etc,...

    Do you actually understand what #define does?

  • Simple Macros
    A simple macro is merely an abbreviation for a fragment of code. It is often called a manifest constant because it defines a name for a constant value.
    
    Macros must be defined using the #define directive before they can be used. For example:
    
    #define LEN 128
    defines a macro named LEN. When LEN is used in your program (or in preprocessor directives) it is replaced with the text 128. So, a C statement like
    
    char buffer[LEN];
    is expanded by the preprocessor into
    
    char buffer[128];
    and is subsequently compiled by the compiler.
    
    
    

    i read the above and most cover the all related topic of this wher the link put me

  • "i read the above"

    Good.

    And did you understand it?

    Are you now clear why it is totally impossible to answer your original question?

    Are you now able to go back to your "sample" code and see what it is doing?

  • i uderstand little bit

    #define COUNT  2000
    #define KEY2    0x2F
    #define val    0xF8
    

    COUNT 2000 means value assign to COUNT KEY2 0x2F means port location address val 0xF8 means read the value from given address

  • "i uderstand little bit"

    No, apparently you don't.

    "COUNT 2000 means value assign to COUNT"

    No, it doesn't.
    There is no assignment here.

    re-read the text that you pasted earlier:

    #define LEN 128
    

    defines a macro named LEN. When LEN is used in your program (or in preprocessor directives) it is replaced with the text 128. That is all it does - nothing more, nothing less. The preprocessor simply goes through your source text; everywhere it finds "LEN" it replaces it with "128" This is basic 'C' stuff - nothing specifically to do with Keil, embedded systems, or the 8051. You need to go back to your 'C' textbook. "KEY2 0x2F means port location address" It has no specific meaning at all - it is just a pure text substitution. You (or the author of the code) may choose to use it with that meaning, but it is not inherent in the #define you show "val 0xF8 means read the value from given address" No: again, it says nothing about reading, values, or addresses.

  • Hmmm... don't know what went wrong there!!

    #define LEN 128
    


    defines a macro named LEN. When LEN is used in your program (or in preprocessor directives) it is replaced with the text 128.

    That is all it does - nothing more, nothing less.
    The preprocessor simply goes through your source text; everywhere it finds "LEN" it replaces it with "128"

    This is basic 'C' stuff - nothing specifically to do with Keil, embedded systems, or the 8051.
    You need to go back to your 'C' textbook.

    "KEY2 0x2F means port location address"

    It has no specific meaning at all - it is just a pure text substitution.
    You (or the author of the code) may choose to use it with that meaning, but it is not inherent in the #define you show

    "val 0xF8 means read the value from given address"

    No: again, it says nothing about reading, values, or addresses.

  • #define COUNT 2000

    it mean's when ever the COUNT appears replace it with 2000;

    #define val 0x0f

    it mean's when ever the val appears goto the memory location 0x0f and pop-up the value

  • or it's meaning is totally un explanable because it know's only by auther

  • #define COUNT 2000
    it mean's when ever the COUNT appears replace it with 2000

    Correct!

    #define val 0x0f
    it mean's when ever the val appears goto the memory location 0x0f and pop-up the value

    No!!
    It has exactly the same meaning as in the first example!

    It means purely and simply that wherever val appears it will be replaced with 0x0f

    eg,

    #define val 0x0f
    
    int fred;
    int array[16];
    
    fred = val;      // assigns the value 15 to fred
    
    array[val] = 3;  // assigns the value 3 to array[15]
    
    if( fred > val ) // Tests if the value of fred is greater than 15
    


    Remember, 0x0F (hex) is 15 (decimal)

  • "its meaning is totally un explanable because it known only by author"

    Absolutely - if the author is thoughtless enough to not provide any documentation (whether in the form of comments ot otherwise).

    As you say this is "sample" code, you need to ask yourself whether your time is going to be better spent trying to understand the "sample", or if you'd be better off just writing it yourself from scratch!

  • As you say this is "sample" code, you need to ask yourself whether your time is going to be better spent trying to understand the "sample", or if you'd be better off just writing it yourself from scratch!

    do not waste time "asking yourself", you WILL "be better off just writing it yourself from scratch"

    The only value of "sample" code I know of comes after you have written the code for what you want to do yourself. At such time you understand what it is all about and, at that time, sometimes - not always a look at "sample" code can give a hint to where the error in what you wrote is.

    Erik

  • i have put one more question in forum can u answer that sinciarly i.e. truly