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?
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.
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.
Your "little" C program doesn't use printf, does it?
printf is a very powerful and, therefore, very large function - it can easily eat up most of the demo code limit!
I think everybody moving from asm to C had such beliefs initially. After a while you learn that C is the way to go where nominal "waste and inefficiencies" do not matter and the percentage where (you think) it matters (and you write an assembly module) will be constantly shrinking, but - in my opinion, never go to zero.
If it weren't for the fact that I suspect you have a rather rigid idea of what 'nominal' means I'd have congratulated you for taking a balanced view...
and it is interesting to see the same beliefs emerging in people moving from C to C++...
Yes. The conversation usually goes like this:
Have you used C++ on the 8051?
No! It's for PCs. Too slow. Too much overhead.
Have you actually tried it?
[silence]
So far my little C program has consumed 3K of the 4K limitation so I am VERY dissappointed with the efficiencies I see so far.
You may well find that a small program that occupies 3k written in 'C' would occupy 300 bytes an assembly. That doesn't mean that a 600 byte assembly program would occupy 6k in 'C'. If you don't understand why, ask and I'll explain.
Unless you are pushing your 8051 derivative to the limit in terms of code size or speed than 'C' is almost certainly a good choice. I would suggest you persist with it but you will have to accept that you will have to buy the real version of the toolchain.
The code size limit you are approaching is designed, for obvious reasons, to prevent you from doing any serious work with it.
Don't ignore the fact that the availability of C++ compilers is not so good for the 8051 chip - changing from a good C compiler to a bad C++ compiler can offset any tests.
But one thing with C++ is that virtual methods do not map well on the 8051.
Having established that certain standard features of 'C' don't map well onto the 8051, it should come as no surprise that certain of the additional, standard features of C++ also don't map well onto the 8051.
But, since the former didn't disqualify 'C' from being a valid tool for the 8051, I very much doubt that the latter necessarily disqualifies C++ as a valid tool for the 8051...
But it does very much depend upon the availability of a decent compiler...
If it weren't for the fact that I suspect you have a rather rigid idea of what 'nominal' means I'd have congratulated you for taking a balanced view... I'd say that the paragraph following 'nominal' says it all.
Yes, since i am in the "big volume league" I am not in favor of spending $1 more per unit of hardware to avoid a module or two being in assembler.
Of course, if you are in favor of the comfort of the coder (programmers need no 'comfort') then your attitude would be different and that fact that $1 (often many times over) can break or make a sale would be no concern of yours.
The most I have ever saved by writing an assembler module is $0.83 but that sold 860.000 units (you do the math)
Erik
Indeed.
I think the Ceibo offering translates C++ into C then compiles it with Keil, so perhaps all that is required is a decent translator, which may well be a rather easier thing to write than an optimising compiler. I don't know how much less 'efficient' the resulting object code is.
I think that the biggest problem here is that a user of a new tool (using C or C++) must spend time looking at the code, or at least have a very good knowledge how the language works internally together with a trust in the compiler vendors abilities.
It is so easy to look at a source code line that looks trivial, and assume that a trivial C or C++ source line must translate into similarly trivial assembler. But if the processor don't have any suitable instructions or addressing modes, major performance losses may be the result of the code.
Since C++ has operator overloading, virtual methods, ... it increases the probability that the compiler must work with pointers (cheap for most processors, but not a traditional 8051) and the amount of assembler code for a single C++ line may significantly increase.
In the end, the problem isn't with the tool but with the user. But sometimes it is better to warn people to not select a too sharp tool unless they are sharp enough to know how to use the tool.
Another thing is of course that most (all?) C++ compilers for 8051 only has a subset of C++. A fully compliant C++ RTL would require huge amounts of code and data, but the user would not really gain any advantages since a 8051 chip is not used for problems where all features are meaningful.
Bingo!
I am using printf for fun. Thanks for the tip. Now I can get rid of printf and replace it with atan and maybe be under the 4K limit.
This project is a very small project and should be done in less than 2K.
As I said, I'm a newbie to all this compiler stuff and Andy (and others) have given me good clues to work on.
I'd say that the paragraph following 'nominal' says it all.
I read, and quoted, the one and only paragraph in your post.
"The most I have ever saved by writing an assembler module is $0.83 but that sold 860.000 units (you do the math)"
To compute the real net saving, we'd have to know the cost of writing the assembler; ie, the cost of the extra time that it took you to manually optimise it into assembler.
(I don't doubt that there was a real net saving)
Lou; Since cost and size of code was a concern, suggest that you look at some of the ARM Cortex-M3 devices by Luminary, ST and NXP. The eval tools have a 16K limit offset by 16K. Also, there are other tools that support C and C++. Cost of the chips are well within reach of the Silabs devices. SiLabs does offer the EC2 USB interface for target debug in your kit where you would need to purchase some type of JTAG iterface device for the selected ARM chip. You get a 16/32 bit chip at the 8 bit price with more memory and often higher clock speeds. Take a look at some of the data sheets linked on this website. Bradford
Lou, I have had to get used to what has passed above. When you speak to people, phone or face to face, they suddenly become members of the human race. The days of PLM51 have sadly passed: now there was an elegant and efficient little compiler, but then it was designed by the guys who made the uCs (85, 51, 80, 88, 86/7, 186/7, 286/7, 386/7..... and you could port between them).
If the C bots could get rid of "unsigned character", when they mean "byte", allow base 2 in the source, and get rid of most of the darned braces I would be happy to meet 1/2 way. As it is C is the only show in town and all things to all men. I have had to learn to accept the compromises.
BTW does anyone know if there is a token I can use to create a NOOP instruction in C51 source code?
Some of what you said went over my head (ie PLM51).
Just an update. I have pretty much completed the project in assembly with maybe 1000 bytes of code (about 1/4 that required by C in my estimation) and it does it's conversion in 100us. This includes 32bit divide and is before I have implemented any optimizing - the code is *** code though that I strung together with my limited knowledge of the limited instruction set of the 8051. That's just my opinion, mind you. Evidently, there are many instructions not available on the 8051 that I found with other MCUs. Oh well.
I aint a pro but when I got a hold of a pdf version of the keil assembly manual via the black market (keil does not know one exists) I felt right at home.
I love assy. But, to be fair, doing the feasibility analysis (first attempt) in C was easy and worthwhile.
If you have 1000 bytes of ASM and 4000 bytes with C Either you are a master ASM programmer, or a Poor Embedded C programmer. That or are using a poor compiler.
Do not take it Personal. Coding for an a limited memory Embedded System is not the same as for the desk top. Embedded C programs get large because statements that produce a large amount of code look the same as those that do not. Like using int as a loop counter (less than 255). You would not use a 16 bit signed value in ASM, but many pepper their C code with it. Printing with printf() that is over a 1K right there. Large Memory model? Click And on and on.
Yes, it is a shame that Keil has stopped doing the '51 manuals as PDF documents.
:-(
Either you are a master ASM programmer, or a Poor Embedded C programmer. That or are using a poor compiler.
Or he forgot to turn on the compiler optimizations, used the wrong memory model, etc. But I guess that would fall under "inexperienced embedded C programmer".
View all questions in Keil forum