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

C

I was hoping to find on-line manuals that I could print and read on the john. So far no luck. But what I really need is how to declare variables in C.

For example, I have a sample code that has the statement:

unsigned char

and

unsigned long

What do these mean and do they limit the declaration to integers. What do i declare if I want a floating point?

Also, someone told me I cant do floating point with a Keil Compiler because of licensing issues (I got my copy from Silicon Labs and have just registered it). I will eventually need to do trig functions. What do i have to get (buy) to complete my project?

  • Before being concerned with platform-specifics, you'll want to read about the language first.

    K&R is a good tutorial.
    H&S is a good reference.

    Both are available in a form compatible with your preferred reading environment.

  • I was hoping to find on-line manuals that I could print and read on the john. So far no luck. But what I really need is how to declare variables in C.

    You don't need an on-line manual, you need actual literature on the basics of C programming. The C51 compiler manual is not a substitute for a book about C, nor is it intended to be one.

    K&R (i.e. "The C programming language" by B. W. Kernighan and D. M. Ritchie) has already been suggested, and I strongly second that recommendation. After all, it's _the_ book about C written by the guys who invented C in the first place.

    I will eventually need to do trig functions.

    Using trigonometric functions does not require use of floating point arithmetics. In fact, part of the skillset of an embedded developer is coming up with solutions that fit the capabilities of the target hardware - and the '51 is very much unsuited for floating point math (even though the C51 compiler will not try to keep the programmer from shooting himself in the foot there).

    There are other solutions, like using lookup tables and interpolation.

  • Using trigonometric functions does not require use of floating point arithmetics. In fact, part of the skillset of an embedded developer is coming up with solutions that fit the capabilities of the target hardware - and the '51 is very much unsuited for floating point math (even though the C51 compiler will not try to keep the programmer from shooting himself in the foot there).

    The embedded developer should also have the skill to assess whether the use of a professionally written, optimised and debugged floating point math library such as that supplied with the C51 compiler would either positively or negatively impact his project.

    Reinventing an already nicely developed wheel if not absolutely necessary would, frankly, be plain stupid.

  • sometimes, "reinventing the wheel" has its own merits. you do something that you have not done before. you learn something new. you get the opportunity to think about a problem - could it have been solved better? is this solution the best fitting for my application? So many of your posts read like a drumhead trial, Jack.

  • Reinventing an already nicely developed wheel if not absolutely necessary would, frankly, be plain stupid.

    A lookup table & interpolation-type approach to approximating trigonometric functions is fundamentally different from the iterative approximation used by the library functions, and therefore does not qualify as reinventing the wheel when used instead of the latter.

    But since you undoubtedly know that, my explanations must have lacked clarity to make you feel the need to comment on them.

  • sometimes, "reinventing the wheel" has its own merits. you do something that you have not done before. you learn something new. you get the opportunity to think about a problem - could it have been solved better?

    Yes, I agree with all that and am not suggesting otherwise.

    is this solution the best fitting for my application?

    This is precisely the message I'm trying to get across - use the best fitting resources to solve the problem in hand. If the advantages of using floating point outweigh the disadvantages then use it. There seems to be a prevailing attitude that certain facilities shouldn't be used merely because the 8051 is not suited to them, without bothering to consider whether it actually matters.

    So many of your posts read like a drumhead trial, Jack.

    I'm glad to hear it.

  • This is precisely the message I'm trying to get across - use the best fitting resources to solve the problem in hand.

    At the same time, you're keeping completely quiet about the other message - that the most convenient approach (or even the only approach the programmer knows) may not work in practice.

    If the advantages of using floating point outweigh the disadvantages then use it.

    Someone who is not aware of alternative approaches to a problem has no way of gauging the advantages or disadvantages of the one approach they know about.

  • At the same time, you're keeping completely quiet about the other message - that the most convenient approach (or even the only approach the programmer knows) may not work in practice.

    I advised using the 'best fitting resources' - they would hardly be the best fit if they didn't work for the task in hand.

    Someone who is not aware of alternative approaches to a problem has no way of gauging the advantages or disadvantages of the one approach they know about.

    Yes, I agree.

  • A lookup table & interpolation-type approach to approximating trigonometric functions is fundamentally different from the iterative approximation used by the library functions, and therefore does not qualify as reinventing the wheel when used instead of the latter.

    'Reinventing the wheel' was a poor choice. Consider me suitably chastised.

  • I think that's the key issue - especially with the 8051.

    Because there is a 'C' compiler, newcomers don't even realise that certain features of "normal" 'C' are really not good for an 8051.

    Floating point is one of the commonest, and it is generally the case that people have not even considered that there might be any issues - let alone evaluated those issues and come to the conclusion that floating point (or whatever) is "good enough" even so.

  • Whew! No matter where I go on the web there's always contention.

    I've been doing micro-controllers for 30+ years in assembly language. Sure, my experience is probably limited compared to you guys but give me a break. I admitted ignorance about C and ask for guidance and I create an argument?

    I'd like to think I have the brains to figure out advantages vs disadvantages. Seems to me C was invented to get the job done fast and not efficient. My plans are, if needed, to optimize the code after the feasibility study.

    Geezzzzz.

    But thanks for the clarification concerning the reference material. Furthermore, from what I can tell, there must be better solutions than that offered by Keil, anyhow. I just bought the development package thru Silicon Labs and Keil doesn't want to support it and I am having difficulty ascertaining what I must spend to lift it's 4K limits. What crap.

  • Hey,

    Are you the Lou Rosinski of the fiber optical encoder fame?

    If you are, then I want to say "You Rock!"

  • You were just an unlucky visitor - they like to sharpen their knives on each other :)

  • Yes, I do Fiber Optics. What do you do?

  • "Yes, I do Fiber Optics. What do you do?"

    I'm just a menial who's done 8051 programming for the past umpteen-plus years.

    I don't like to give too much away about myself here because I'd almost certainly be classed as a code monkey :(

    I remember seeing one of your articles a while back. Nothing to do with my field, but it was easy to read and interesting.