EEVblog Electronics Community Forum
Electronics => Microcontrollers => Topic started by: ect_09 on October 21, 2014, 07:25:44 am
-
am looking for the sample code and book where i can learn the C language for micro controller.
please give me suggestion. :scared:
Regards,
-
Do you know c? If not start with The c handbook from Kernighan and Richie.
Then choose an application book for your specific microcontroller and last start doing exercises and make mistakes since those are the only ones you really will learn from ;)
-
http://lmgtfy.com/?q=books+on+microcontroller+programming+with+examples (http://lmgtfy.com/?q=books+on+microcontroller+programming+with+examples)
-
There is no such thing as C language for microcontollers. There is the C programming language and there are endless libraries that can be used in C code. The registers and peripherals of a uC have nothing to do with the language itself, but a manufacturer, or third party, might supply a library that can be used to write code for a specific uC. So, IMHO, you'd better get a generic book about C and learn the language. The rest is uC specific stuff that differs between vendors and uCs. The classic book about C is "The C programming language (http://en.wikipedia.org/wiki/The_C_Programming_Language)".
-
Kostas, there seems to be an obvious language barrier, but that aside, it is a bit ingenious to say that. Yes, there isn't "C for micros," but embedded or constrained system development is a lot different from desktop or user-interactive development normally seen today. "The rest (of the) uC specific stuff," as applied with the language, is exactly what ect_09 is trying to learn.
-
"The C Programming Language" has become a little old these days. Having taught C classes at two universities, I'd recommend K. N. King's book "C Programming: A Modern Approach (http://knking.com/books/c/)".
Microcontrollers specific books depend on what uCs by what vendor you want to program, I'd agree with Kostas.
-
The major differences between microcontroller development and computer programs development in C is that you have a very limited memory (RAM and ROM) and you normally have to deal with microcontroller's specific registers.
Some hints for embedded programming:
- Try to avoid dynamic memory allocation (malloc & free);
- It's common to find microcontrollers with less than 1Kbytes RAM;
- Your stack is really small (16~256 bytes for most 8-bit microcontrollers), avoid declaring large arrays of data inside functions;
- Only powerful microcontrollers have floating point units, so prefer use fixed point math or your binary will get large and slow;
- Standard C functions like printf and scanf aren't always implemented on some microcontroller's libraries, and when they are you need additional configuration before use.
Buy some dev board from atmel or microchip and start writing some code!
-
For samples just look at Arduino examples. They are mostly C with a few C++ extensions.
-
I like O'Reilly's Practical C Programming. That's how I learned. I recommend starting on a PC, as there's enough to learn as it is. Get through the book and try some of the programming challenges to become comfortable with C.
Then, pick up an Arduino. It's a great way to get started with digital electronics, and micros in particular. The IDE is really simple, but awful once you get to projects of any substantial size. Use it until you start running into its limitations, then learn to use Atmel Studio instead.
By that point, you're no longer a noob, just an inexperienced embedded developer. So follow your whims and practice practice practice. Branch out to other vendors and platforms as you feel inclined to do so. The rest of the journey isn't in a book, it just takes time.
-
Take a look at this: https://www.eevblog.com/forum/microcontrollers/embedded-programming-mooc-to-be-re-offered/
The mentioned course is for free and offers a good entry to beginner!
-
Thanks
-
I don't know for a book, but for microcontroller programing aspect, you can find good things on newbiehack.com (https://newbiehack.com/)
-
C and micro book together are not really necessary or ideal as they will be micro specific . if you have micro assembler experience then you are half way there , I found "C for Dummies 6 in 1 " by Dan Gookin easy to understand he also has sample files on a website , easy to find mcu specific examples on the web to paste and modify and learn at the same time. You will need a platform to test your results, a simple breadboard setup will do. ( and i didn't mention a single micro company 8)
-
Basically all that applies for microcontrollers is basic logic operators, math, if then , for loops, arrays and variables. All the PC style outputs don't work on the MCU.
-
Basically all that applies for microcontrollers is basic logic operators, math, if then , for loops, arrays and variables. All the PC style outputs don't work on the MCU.
Not quite true, you can use formatted I/O and file streams etc. if you have the hardware and don't mind the overheads.
-
Hi,
Sorry, I do not know any good books. But one thing I see coming back is the K&R book "The C Programming Language". It is adviced by many people here to beginners in C.
I like to point out that this book is really difficult to start with. |O I program C for almost 20 years and like it as a language reference. :-+ But for beginners this is really a terrible book. :--
It is great when you use it as a reference and know what you are doing. It is very complete, but not easy to read. :box:
I guess their are much better books. Wanted to point this out for a long time. Keep in mind I like the book
Understanding C is more than only the language. You also need to understand the architecture of the platform you like to target. Most limitations will come from this.
My two cents. ;)
-
I think you need a few types of books here:
1) K&R: to know the basics of C. It is a book to start with;
2) coding manuals / style books: most large firms have them.
3) coding "tricks" / traps: not a systematic way to learn C but a good way to avoid tricky mistakes. Read it only when you consider yourself to be 'fairly' good in C.
I wouldn't buy any "C on mcu" book: C is C. With minor exceptions, what you learned coding on a PC goes to coding in an enbedded environment.
-
Sorry danny but that's just horrible advice.
-
"The C Programming Language" has become a little old these days. Having taught C classes at two universities, I'd recommend K. N. King's book "C Programming: A Modern Approach (http://knking.com/books/c/)".
I ordered this book after your post, I find it a bit too expensive (€75) but it is well written and I can now second it to recommend it to starters for getting the hang of C instead of K&R which might be to steep.
Also the explicit mentioning what parts are C (K&R-C), C89 and C99 are splendid since still not everyone uses a C99 compiler these days.
Good recommendation.
-
Some Starter Videos, projects if you are interested :
Bare metal bring up with the FRDM-KL25Z ($13 board):
https://community.freescale.com/docs/DOC-93960
https://community.freescale.com/docs/DOC-95170
They are not all encompassing but some of the MCU intro videos may help. THere are examples for getting started doing basic board bring up
Some projects that use FRDM but are more focused on DSP. Intended for just out of college students who have never coded any DSP, etc who need something a little more advanced than an LED blinker to get started.
https://community.freescale.com/docs/DOC-99621