ABC of Electronics cosycom.com
PIC BASICS · LESSON 06

Setting Up Your First PIC Project

Every PIC project starts the same way: pick the exact chip, set the clock source, and get an empty program to compile cleanly before you write a single feature.

Starting a new PIC project in any IDE follows the same handful of steps, regardless of which exact chip or toolchain you're using:

  1. Create a new project and select your exact chip model. This matters more than it sounds — the compiler needs to know precisely which registers, how much memory, and which peripherals exist on that specific part number.
  2. Add a main source file. By convention this is called main.c, and it must contain a function named main() — the point where your program begins running after the chip powers up and finishes its internal startup sequence.
  3. Set the configuration bits (covered in full in the next lesson) — a handful of settings baked into the chip itself, separate from your program, that control things like which clock source to use and whether the watchdog timer is active.
  4. Build the project. This runs the compiler and checks for errors before anything is written to a chip.
main.c — the smallest project that will compile and run
// A minimal PIC program: it does nothing yet, but it proves
// the toolchain is set up correctly if it compiles without errors.

void main(void) {
    while(1) {
        // The main loop. Real code goes here.
        // An empty loop like this just keeps the chip running.
    }
}

Notice the structure: everything happens inside main(), and inside that, almost everything happens inside a while(1) loop — a loop whose condition is always true, so it repeats forever. This is the standard shape of nearly every embedded program you'll write: a small amount of one-time setup code, followed by an infinite loop that runs continuously as long as the chip has power.

KEY TAKEAWAY
A PIC program has no natural "end" the way a desktop program does. It boots, runs setup code once, then loops forever — because the chip has nowhere else to go and nothing else to run.

Once this empty project compiles without errors, you have a working pipeline from code to chip. The next lesson covers the configuration bits you'll typically set right after creating a new project, before writing any real logic.