Curiosity Nano Out-of-the-Box — Use Case for CLB Using the PIC16F13276 Microcontroller With MCC Melody
This repository provides an MPLAB® X project that comes preloaded on the PIC16F13276 Curiosity Nano Evaluation Kit when the user first plugs it in. It consists of a state machine demonstration of the Configurable Logic Block (CLB) peripheral that controls the behavior and/or brightness of the on-board LED.
More details and code examples on the PIC16F13276 can be found at the following links:
- PIC16F13276 Product Page
- PIC16F13276 Code Examples on Discover
- PIC16F13276 Code Examples on GitHub
- CLB Peripheral Page
- Online, Stand-Alone CLB Configuration Tool
- MPLAB® X IDE v6.30.0 or newer or MPLAB® Tools for VS Code®
- MPLAB® XC8 v3.10.0 or newer
- PIC16F1xxxx_DFP v1.29.444 or newer
- The PIC16F13276 Curiosity Nano Development board is used as a test platform:

To program the Curiosity Nano board with this MPLAB X project, follow the steps provided in the How to Program the Curiosity Nano Board chapter.
The CLB peripheral on the PIC16F13276 acts as a button debouncer and state machine for the LED. On power-up, the LED blinks at (nominally) 7.8 Hz. All other states of the state machine change the brightness of the LED via Pulse Width Modulation (PWM) dimming, which is synthesized inside the CLB as well. The push button, SW0, on the Curiosity Nano is debounced within the CLB and used to advance the state machine. The CLB circuit is presented in the image below:

The table below shows the behavior for each button press.
| State | LED Behavior |
|---|---|
| 0 | The LED blinks at (nominally) 7.8 Hz |
| 1 | Brightness level 1 (12.5%) |
| 2 | Brightness level 2 (25%) |
| 3 | Brightness level 3 (37.5%) |
| 4 | Brightness level 4 (50%) |
| 5 | Brightness level 5 (62.5%) |
| 6 | Brightness level 6 (75%) |
| 7 | Brightness level 7 (87.5%) |
Note: The percentages are calculated based on the active LOW condition.
The following peripheral and clock configurations are set up using the MPLAB Code Configurator (MCC) Melody for the PIC16F13276:
-
Configuration Bits:
- CONFIG1:
- CONFIG3:
-
CLB Synthesizer Library:
-
CRC:
- Auto-configured by CLB
-
Pin Grid View:
In the demo below, each press of the SW0 button advances the state machine, changing the behavior or brightness of the on-board LED on the Curiosity Nano board.
The CLB peripheral on the PIC16F13276 device manages button debouncing and LED state control, including PWM dimming, for the Curiosity Nano kit. The preloaded project demonstrates these features through a state machine that changes the LED’s behavior with each button press.
This chapter demonstrates how to use the MPLAB X IDE to program a PIC® device with an Example_Project.X. This is applicable to other projects.
-
Connect the board to the PC.
-
Open the
Example_Project.Xproject in MPLAB X IDE. -
Set the
Example_Project.Xproject as main project.
Right click the project in the Projects tab and click Set as Main Project.
-
Clean and build the
Example_Project.Xproject.
Right click theExample_Project.Xproject and select Clean and Build.
-
Select PICxxxxx Curiosity Nano in the Connected Hardware Tool section of the project settings:
Right click the project and click Properties.
Click the arrow under the Connected Hardware Tool.
Select PICxxxxx Curiosity Nano (click the SN), click Apply and then click OK:
-
Program the project to the board.
Right click the project and click Make and Program Device.




