Manual 2 for C?

Brian Z

New Member
Hey all, somewhat off topic question here but I don't know who else to ask. Picaxe is the only microcontroller I have ever used (as Basic is the only language I know), and I am wanting to learn the C programming language to help me use other microcontrollers as well. I am having a hard time learning it. Is there an equivalent to the Picaxe manual 2 for the C programming language? I bought the Make: AVR Programming book, but I don't understand the commands and the syntax of C, and I keep thinking back to manual 2 for Picaxe Basic.

Thanks for any advice,
Brian Z
 

bryanl

Member
Manual 2 for the PICAXE, the command dictionary, mostly covers what is called a library of pre-written routines in the C world. Instead of commands, a c program would call a function in a library. Most microcontroller manufacturers provide libraries for their devices. The Arduino is particularly popular because its usual development environment has libraries of functions to work with most common peripherials just like the PICAXE commands. Many times you'll find people that sell 'shields' or Arduino compatible peripheral sensors and devices also provide a C library to make it easy to use it with the Arduino.

The differences in syntax are really rather minor. C tends to add punctuation to define scope or terminate a statement.

C provides a lot more nuance when it comes to the types of variables you can use. PICAXE is like assembly in that the variables you can use are based simply on the hardware it runs on. That means words and bytes and arithmetic is unsigned integer. In C, you have bytes, words, integers, floating point numbers, and signed arithmetic (all provided by built in libraries that are a part of the language definition). Note that mcu C compilers often fudge a bit on the standards for built in functions as the processors and memory just aren't there to do them right.

Microchip has a free C compiler and development environment for the PIC as used by PICAXE called MPLAB-X and their manuals for it are reasonably decent (see http://www.microchipc.com/sourcecode/ ). http://www.mikroe.com/products/view/11/book-pic-microcontrollers/ is a free book that covers the territory for beginners.

If you really want to go to town, check out http://chipkit.net/ - about the same price as the Arduino but based on a 32 bit Microchip MCU with a free development environment and a lot of attention to Arduino compatability.

One of the other major issues to keep an eye on in using mcu's is loading the 'firmware' - PICAXE makes this easy as it includes what is called a bootloader to talk to a host PC and download your program. Other hobbyist mcu systems also usually have something similar. Without this, you need a special programming device to get code from your computer to the mcu.
 

premelec

Senior Member
@matherp - is there a book like that for C+ or is C+ ++ not that much different? I'm not going to learn C but am interested in the general considerations - besides brackets and semicolons... :)
 

lbenson

Senior Member
>or is C+ ++ not that much different

I did a great deal of C programming several decades ago (Kernighan and Ritchie was my bible), but when I looked into C++ I found it way over the top for my needs, and so it continued to be for a programming career at that time. Now if you want to program professionally, mastering C++ would probably be your best gateway, even if you subsequently found that you programmed in other languages.
 

MFB

Senior Member
Ibenson, its interesting that you found C++ "over the top" because that's the initial impression that I'm having with the Arduino. Why was this language chosen for a platform that was hyped (not unlike Raspberry Pi marketing) as being great for introducing newcomers to microcomputing? C++ is probably a great language for writing large computer programmes but very long winded for many embedded tasks.

I think the PICAXE and Maximite are far more appropriate platforms for learning the basics of embedded programming.
 

lbenson

Senior Member
Good question about C++ on Arduino. I would say that unless you're just calling pre-existing functions, writing a program of any size in C++ would be a tough hill to climb for a beginner.

One thing that I particularly like about the picaxe is that you can do the easy things easily, and yet the platform has developed so that you can also do some pretty complex things as well.

Not yet looking to control a quadcopter or process video with the picaxe, though.
 

Dippy

Moderator
I'd suggest getting a demo/lite version of C compiler and having a play.
Whilst I'm not a fan of Mikroelektronika C at least it'll give you a taster.
Don't expect to learn it as quickly as PICAXE BASIC.
 

MFB

Senior Member
Anyone considering C++ for a (non-quadcoper control or video processing) microcontroller project should first investigate what's involve in performing some basic tasks, like using multiple serial ports or I2C. Before even starting to programme they will have to learn how to download and install the Softwareserial and Wire libraries. Only to fined that neither have time-out recovery and as for setting the watchdog feature! They will then have to type about half a page setting things up before even starting on the application stuff. With the PICAXE or Maximite you can get started so much more easily.
 
Top