c language sample codes and Book - Page 1
Forum section: electronics / general

author: ect_09
author_rank: Contributor
timestamp: October 21, 2014, 07:25:44 am
content: am looking for the sample code and book where i can learn the C language for micro controller.please give me suggestion.Regards,

author: Kjelt
author_rank: Super Contributor
timestamp: October 21, 2014, 07:46:33 am
content: 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

author: Unknown
author_rank: Unknown
timestamp: October 21, 2014, 07:47:31 am
content: http://lmgtfy.com/?q=books+on+microcontroller+programming+with+examples

author: Kostas
author_rank: Regular Contributor
timestamp: October 21, 2014, 07:47:57 am
content: 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".

author: true
author_rank: Frequent Contributor
timestamp: October 21, 2014, 09:00:05 am
content: 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.

author: con-f-use
author_rank: Unknown
timestamp: October 21, 2014, 11:53:54 am
content: "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".Microcontrollers specific books depend on what uCs by what vendor you want to program, I'd agree with Kostas.

author: Palmitoxico
author_rank: Regular Contributor
timestamp: October 21, 2014, 03:08:06 pm
content: 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!

author: zapta
author_rank: Super Contributor
timestamp: October 21, 2014, 05:09:16 pm
content: For samples just look at Arduino examples. They are mostly C with a few C++ extensions.

author: SirNick
author_rank: Frequent Contributor
timestamp: October 21, 2014, 06:09:13 pm
content: 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.

author: the_memristor
author_rank: Newbie
timestamp: October 23, 2014, 05:43:34 am
content: 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!

author: ect_09
author_rank: Contributor
timestamp: October 28, 2014, 11:17:34 am
content: Thanks

author: old gregg
author_rank: Regular Contributor
timestamp: November 09, 2014, 10:19:14 pm
content: I don't know for a book, but for microcontroller programing aspect, you can find good things onnewbiehack.com

author: 22swg
author_rank: Frequent Contributor
timestamp: November 10, 2014, 10:14:24 am
content: 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

author: Stonent
author_rank: Super Contributor
timestamp: November 10, 2014, 02:13:19 pm
content: 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.

author: mikerj
author_rank: Super Contributor
timestamp: November 11, 2014, 07:29:57 pm
content: Quote from: Stonent on November 10, 2014, 02:13:19 pmNot quite true, you can use formatted I/O and file streams etc. if you have the hardware and don't mind the overheads.

author: FPGAcrazy
author_rank: Contributor
timestamp: November 11, 2014, 07:54:58 pm
content: 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.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.I guess their are much better books. Wanted to point this out for a long time.Keep in mind I like the bookUnderstanding 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.

author: dannyf
author_rank: Super Contributor
timestamp: November 11, 2014, 08:38:06 pm
content: 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.

author: con-f-use
author_rank: Unknown
timestamp: November 11, 2014, 09:22:49 pm
content: Sorry danny but that's just horrible advice.

author: Kjelt
author_rank: Super Contributor
timestamp: November 12, 2014, 07:51:41 am
content: Quote from: con-f-use on October 21, 2014, 11:53:54 amI 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.

author: ehughes
author_rank: Frequent Contributor
timestamp: November 12, 2014, 04:44:19 pm
content: Some Starter Videos, projects if you are interested :Bare metal bring up with the FRDM-KL25Z ($13 board):https://community.freescale.com/docs/DOC-93960https://community.freescale.com/docs/DOC-95170They are not all encompassing but some of the MCU intro videos may help. THere are examples for getting started doing basic board bring upSome 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