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:
- 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.
- Add a main source file. By convention this is called
main.c, and it must contain a function namedmain()— the point where your program begins running after the chip powers up and finishes its internal startup sequence. - 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.
- Build the project. This runs the compiler and checks for errors before anything is written to a chip.
// 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.
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.