Configuration Bits & the Oscillator
Configuration bits are a small set of chip-wide settings that live outside your program. Getting them right — especially the oscillator setting — is what makes the difference between a chip that runs and one that seems dead.
Separate from the program you write, every PIC has a small block of configuration bits — sometimes called fuse bits — that are programmed into the chip alongside your code but control hardware-level behavior rather than program logic. They're set once, typically at the top of your source file or through the IDE's configuration tool, and they take effect before your main() function ever runs.
| Setting | What it controls |
|---|---|
| Oscillator source | Whether the chip uses its internal oscillator or an external crystal/resonator for its clock |
| Watchdog timer | An independent timer that resets the chip if your code ever hangs or gets stuck |
| Power-up timer | A short delay after power-on before the program starts, to let the supply voltage stabilize |
| Brown-out reset | Automatically resets the chip if the supply voltage dips too low to run reliably |
| Code protection | Prevents the program memory from being read back out of the chip once written |
The oscillator source deserves special attention, because getting it wrong is the single most common reason a first PIC project appears completely dead. Many chips ship configured, by default, to expect an external crystal — and if none is connected, the chip never generates a working clock signal at all, so no code runs, no pins toggle, nothing. Most PIC16-family chips include a built-in internal oscillator that's accurate enough for the projects in this series, which avoids the extra crystal and two capacitors an external oscillator would need.
// Use the internal oscillator, disable the watchdog timer,
// and enable the power-up timer for a stable start.
#pragma config FOSC = INTOSC // internal oscillator
#pragma config WDTE = OFF // watchdog timer disabled
#pragma config PWRTE = ON // power-up timer enabled
With configuration bits set, the chip has everything it needs to start running your program predictably. The next lesson moves into the registers you'll use most: the ones that turn pins into digital inputs and outputs.