Hello all,
I have been programming the 8051 chip using assembly for small programs and applications such as A to D converter, alarm clock, etc. In which I have learned that it is a great pain to do more complicated projects with assembly, as the number of lines of codes get larger and harder to track.
I have downloaded the uVision 4 C complier to try to replace assembly, but I'm having difficulties learning how to use it. I have had C/C++ programming before, but I must admit it has been a while since I used it.
Are there any tutorials on programming the 8051 using C?
Also, I have been trying to duplicate my counter project (counting from 0 to 99 using assembly code) with C. I have it count from 0 to 9, but I could not figure out how to do decimal adjust using C. Any idea? In assembly the code is simply DA
Thanks all, Woozie
I know, I never denied I don't need to learn C, I also didn't say I'm a pro at C. Hence I'm here to ask for help. If I knew the answers to my questions are "you don't know C, learn it", then I would probably just went straight there to begin with, and answer the questions myself sooner or later. Don't get me wrong, I'm not saying all these replies are not helpful, it really strike me hard to make myself think how little do I know about C versus embedded. Although I would be much more appreciated if anyone could give me a hand and guide me to the right direction while pointing out my problems, than just pointing out my problems without additional help to correct my problem.
I really appreciated your example code, I will run your code and see what happens while I will learn C to stop embarrassing myself.
Thanks.
"I would be much more appreciated if anyone could give me a hand and guide me to the right direction while pointing out my problems"
But your fundamental problem is precisely that you need to spend time learning the 'C' language!
That is absolutely fundamental. We cannot build anything further until you have laid that foundation.
You've just shown that yourself: Jon gave you some 'C' code, but you couldn't uderstand it - because you haven't got that basic foundation to enable you to understand 'C' code!
"I really appreciated your example code,"
andrew is absolutely right: you don't need sample code. all you need is to pick up a good C book and understand it.
at this point, giving you sample code does more harm to you.
I'm not sure I would go THAT far. I think most of us learned a lot of what we know about programming by examining other people's code and trying to figure out how it worked. However, I didn't learn much by asking other to tell me the answers. I worked hard to figure things out for myself.
The example code I gave is trivial. There's nothing tricky about it. It uses typical C operators. Now it's time for the OP to break out a C book and see what it is that % and / and << do. If he has written assembly code and taken elementary to middle school math, it won't be hard.
Jon
I found it more helpful to learn by looking at other people's code and comparing them to see which one is more efficient. But that's my personal learning style.. I do not wish anybody to give me the entire program to solve my problem, and I didn't ask for one either.
The only things I wasn't sure about that line of code was the % and <<, but now I know. Thanks for the explanation.
"I found it more helpful to learn by looking at other people's code"
I agree. the downside with that risk, especially by taking a random stranger's code, often out of context or without context, before you have a good understanding of the language, may lead to incorrect understandings.
what I would suggest is a good class / book in C, and then going through well written code pieces side by side with your book / class materials.
"going through well written code pieces"
The trouble there is: how does a novice know whether code is "well-written" or not?
And the trouble with a book is that you can't interact with it: you can't ask it to explain again; it can't look at your work to see where you're going wrong; it can't adjust to your particular strengths & weaknesses.
"what I would suggest is a good class"
Absolutely!
"And the trouble with a book is that you can't interact with it"
I guess that's why books are useful only for humans, not machines.