CCS-C Examples of Easy Pic 'n Code

A page devoted to simple CCS C code examples for the PIC microcontroller.

CCS at makes a C compiler for the rest of us that costs between $99 and $350 depending on which version you buy - I have the $99 one for DOS and Mid Range PIC chips - called CCS-PCM. It is meant to ease the programmer's task in preparing code for the Microchip PIC Microcontroller (Visit Microchip Website For More Information about the PIC).

Starting out with the C compiler may not be as clear as it could be - especially if you are new to PIC programming. While there are several sites that have PIC code and have great resources, the examples shown on the sites usually depend on a particular kind of evaluation board or piece of hardware. This page expects very little formal hardware. You should be able to breadboard up a PIC and get it kicking over. That's about it.

First off - there is no substitute for understanding the PIC before you start programming. I highly recommend you get Easy Pic'n by Benson (ISBN 0-9654162-0-8) from Dontronics or HVW Technology or Amazon or somewhere similar. Go through the book and teach yourself assembler. The software to do it is free from Microchip. It will only take you a couple of days to get through the book (or less if you want to pull an all-nighter).

The rest of this page assumes you know a little about PIC architecture, have installed CCS on your computer, and are just wondering what to do next.

Benson's Easy Pic 'n has some great (and simple) .asm examples in it and I decided to convert some of the ideas to C code. The following are those conversions. All the examples depend on you having a 16F84 PIC that you have figured out how to load with .hex code from the C compiler using a programmer. There are tons of programmers out there - I use one from Peter Anderson's Site and I have recently acquired a PICSTART Plus (available from Digikey and elsewhere).

'Suggested' Parts List To Experiment With These Programs

1. Solderless Breadboard (JE25 from Jameco)

2. PIC (16F84) from Digikey, Dontronics, Peter Anderson, etc

3. Two 8 switch DIP switches (I pulled mine from a couple of old modem boards but they are also available from Radio Shack and elsewhere).

4. Several SPST switches - either push button or toggle.

5. Several LEDs (or better yet, an 8 LED bar from Radio Shack)

6. A 7 segment display for one of the programs (also available from the Shack).

7. A 5 volt power supply for the breadboard (7805 setup of some sort).

Nice to have parts

8. 555 timer IC for signal generation.

9. 74HCT04 chip for a bounceless (sort of) half monostable multivibrator. See the Easy Pic 'n book for hookup.

10. A wall wart power supply.

My Eval Board (click for bigger picture),
which uses most of the parts listed above. Yours
doesn't have to have all this - mine just kept
growing 'til it got to this state.

Finally, The Programs

The following code was written quite quickly and is surely not the best. However, it did work with my setup. I welcome critiques on ways to make it better. Send me email at

Did you try the code and it wouldn't compile? READ THIS:

LOOKING AT C CODE ON A WEB BROWSER SUCKS. DOWNLOAD THE ZIP FILE AND LOOK AT IT in notepad or a proper editor. If you click on the links, some code will be hidden. Be sure to download and install the first file as defs_f84.h

0. Peter Anderson's Bit Definitions for 16F84 (used in examples below)
1. Pict2c.c Show PORT A switch status on PORT B
2. Pict5c.c Demonstrate the status register after a math function
3. Pict7c.c Timer/Counter demonstration (output a square wave)
4. Pict10c.c Simple bit testing and manipulation
5. Pict11c.c Event count
6. Pict13c.c Bit rotation demo
7. Pict14c2.c 7 Segment Display demo (lookup table)
8. Pict15c.c Basic interrupt demonstration
9. Pict17c.c Using timing interval from external clock
10. Pict21c.c Event counting demo
11. All the above examples in a zip file

Other Simple But Informative Files for CCS

12. Embedded assembly code example - written by Peter Anderson (note: nothing to do with Easy Pic'n , it is a program by Peter Anderson used to check out his Morgan PIC Programmer. However, it is a simple example of embedding .asm code in a CCS source file)
13. rs2321.c Hello world! on a serial 'Pic An LCD' by BGMicro - this example alone justifies using C!
14. A simple SSC controller (discussion)
15. A CCS driven Serial LCD (basic construction)