3
\$\begingroup\$

I want to do PIC programming in embedded C. But I don't know the language well. Please help me by suggesting some good sites for getting an idea about C programming.

\$\endgroup\$
  • \$\begingroup\$ Have you learned a programming language before? \$\endgroup\$ – J. Polfer Sep 3 '10 at 22:00
13
\$\begingroup\$

Microcontrollers like the PIC are very unforgiving to the learner. If you're setting out trying to learn C for the first time, practice on a PC first. Test your code as much as you can on your PC where you have a good debugger and protection from memory faults.

Once you're confident that your logic is working right, then compile your code for the PIC.

\$\endgroup\$
  • 2
    \$\begingroup\$ +1 The PIC is not a C friendly platform anyway, and the last place I would try to learn C. \$\endgroup\$ – old_timer Sep 11 '10 at 2:24
6
\$\begingroup\$

I'd recommend getting K&R because I like to read a book as I learn a language, but if you're looking for an online resource, Wikibooks' C Programming isn't a bad read.

Alternatively, for a topical resource, look at http://www.cprogramming.com or http://www.cplusplus.com - Note that both are C/C++ sites, you must be wary of the differences. You don't want to use C++ for your PIC projects.

When doing native (PC) programming, follow links to the Opengroup.org Single Unix Specification. Also be aware of the cross-referenced and searchable Linux kernel source code at http://lxr.linux.no/

The comp.lang.c mailing list (Searchable Google Groups page) and its FAQ are also useful. Daniweb's C forum and, of course, the "C" tag on Stackoverflow are also more sources for specific questions.

Last, a Google search for "C Language" + keyword is a good starting point for many questions, and usually yields better results than just the letter C.

\$\endgroup\$
  • \$\begingroup\$ Provided a C++ compiler even exists for PIC, I see nothing wrong with using the language in an embedded device. There are some great benefits to be had using an object-oriented language, even in constrained environments. \$\endgroup\$ – blalor Feb 28 '11 at 11:05
  • \$\begingroup\$ @blalor - For a beginner, I didn't want to get into those issues. See "Is C++ suitable for embedded systems" for more discussion of the issue. \$\endgroup\$ – Kevin Vermeer Feb 28 '11 at 13:56
5
\$\begingroup\$

Get The C Programming Language by Kernighan and Ritchie. They invented C and it's the best introduction to the language there is.

Some of the low-cost C compilers for the PIC are rather non-standard. Microchip's C18 for the PIC18 and Hi-Tech's C for the smaller PICs would be better; free versions of both compiler are available.

\$\endgroup\$
  • 1
    \$\begingroup\$ Make sure to get the second edition, with the "ANSI C" box on the cover: amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/… The original is for an older version of C (1978). The 2nd edition is for 1988 ANSI C, and you should be aware that it does not cover the C99 standard. \$\endgroup\$ – Kevin Vermeer Aug 29 '10 at 17:06
2
\$\begingroup\$

Once you are ready to apply your C skills to the PIC, I would get a development board, and one of the following books, depending on whether you are dealing with 8-bit (PIC1x), 16-bit (PIC24) or 32-bit (PIC32) devices:

Programming 8-bit PIC Microcontrollers in C: with Interactive Hardware Simulation

Microcontrollers: From Assembly Language to C Using the PIC24 Family

Programming 32-bit Microcontrollers in C: Exploring the PIC32

all available on Amazon (along with lots of similar titles covering PICs and C).

Note: I would shy away from 8-bit PICs lower than the PIC18, as they are not as well suited to the C language.

\$\endgroup\$
2
\$\begingroup\$

If you're really interested in learning PICs and c, I would say you can check out 123 PIC Microcontroller Experiments for the Evil Genius. This is how I got started with PICs. However, I would at the minimum recommend purchasing the PIC Kit 2 as the 1 doesn't program nearly as many things.

I have really enjoyed playing with the PICs, the HI-TECH compiler for the 16 series (and probably other series) is free for the MPLAB environment.

Good luck. I'm actually attempting to come up with a RTOS (Real Time Operating System) for a 16F913, just to try it out.

\$\endgroup\$
  • \$\begingroup\$ Sorry, I didn't include a site....I actually just used microchips site www.microchip.com , and their datasheets for the chip you're using! \$\endgroup\$ – onaclov2000 Sep 2 '10 at 21:41
1
\$\begingroup\$

Thinking in C. There are some bugs, but it's a great free ebook from Bruce Eckel.

\$\endgroup\$
1
\$\begingroup\$

It all depends on how you learn, but I find its easier to learn with a distinct objective when your'e learning. If you want to specifically learn C for PICs, here's my recommendations:

Ironically, I'd pick up an Arduino and not a PIC setup. Programming PIC chips in C has a very large learning curve that assumes you know how to read datasheets, burn code into chips, etc. Arduinos do not have this. You program Arduinos in C (*). If you know nothing/vary little about programming or writing in C or with microcontrollers and don't know where to start or what to do, the example code that comes with it is very simple and will allow you to get up and running quickly. The documentation for the Arduino is easy to read with minimal experience. A trip to an electronic store and the Arduino board will give you a way to get started.

In conjunction with that, I would read a book or a tutorial on C.

In addition, I would find someone else who knows how to program PICs or microcontrollers in C and work with them. A subject like this has a huge learning curve, but a person who can interact with you and help you fill in the gaps is huge.

(*) - It does use a form of avr-gcc in the backend, correct? I haven't dug into the Arduino IDE source code.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy