Objective
The Core Independent Peripherals within the latest PIC® 8-bit microcontrollers offer the opportunity to perform hardware functions without the Central Processing Unit (CPU) core running any code. This can be extremely useful for applications that need to perform applications without interruption from the main application. This simple example shows how to set up and use theConfigurable Logic Cell (CLC) peripheral and its JK Flip Flop option to control an LED through an I/O port. The clock of the JK Flip Flop comes from the internal 31 kHz internal oscillator, routed through atimer. The image shows the block diagram of the project. As you can see, the control runs completely independently from the CPU.
Materials
Hardware Tools (Optional)
| Tool | About | Purchase |
|---|---|---|
| | |
Software Tools
| Tool | About | Installers | Installation Instructions | ||
|---|---|---|---|---|---|
| Windows | Linux | Mac OSX | |||
MPLAB® X Integrated Development Environment | | | | | |
![]() MPLAB® Code Configurator Dynamic Code Generation | | | |||
MPLAB® XC8 C Compiler | | | | | |
Exercise Files
| File | Download | Installation Instructions | ||
|---|---|---|---|---|
| Windows | Linux | Mac OSX | ||
Project and Source Files | | | | |
Curiosity Board User Guide/Schematic | | | | |
Connection Diagram
The curiosity board has four LEDs prewired to the I/O pins shown below. This project controls the D7 LED.
| Hardware Function | Pin | Setting |
|---|---|---|
| IO_LED_D4 | RA5 (2) | Output |
| IO_LED_D5 | RA1 (18) | Output |
| IO_LED_D6 | RA2 (17) | Output |
| IO_LED_D7 | RC5 (5) | Output |
Procedure
1
Create a Project
Create a new project and select thePIC16F1619 along with theCuriosity Board andMPLAB® XC8 compiler. If this is your first time creating a project, click on the link below to expand the directions.
If this is your first project please visit the"MPLAB Xpress: Create a Project" page.
3
System Setup
FromProject Resources chooseSystem Module to open theSystem Setup window within MCC.
- In the clock settings, make sure you selectINTOSC
- Select the system clockFOSC.
- Set Internal Clock to4MHz_HF setting.
- Check thePLL Enabled box.
- The Curiosity Board uses a programmer/debugger on board (PKOB) and uses a Low Voltage Program method to program the MCU, therefore we must enable low voltage programming by checking theLow-voltage programming Enable box.
4
Timer 6 Setup
Add the TMR6 peripheral to the project from the Device Resources area of MCC by scrolling down to theTimer entry and expand the list by clicking on the arrow. Now double click-on theTMR6 entry to add it to theProject Resources list. Then click on theTMR6 to open the Timer 6 configuration setup screen.
- Check theEnable Timer box
- SelectClock Source LFINTOSC,Postscaler 1:1, andPrescaler 1:32
- Set Timer period value to "100.129 ms"
- Set External Reset Source toT6IN, and Control mode setting toRoll over pulse,
- Set Start/Reset Option toSoftware Control (this will inhibit hardware reset of timer).
- Leave theEnable Timer Interrupt box unchecked.
5
CLC Setup
Add the CLC1 peripheral to the project from the Device Resources area of MCC by scrolling down to theCLC entry and expand the list by clicking on the arrow. Now double click-on theCLC1 entry to add it to theProject Resources. Then click on theCLC1 to open the Timer 6 configuration setup screen.
Select theJ-K Flip-Flop with R tab from the logic functions (mode) list. Let’s connect J and K to a high logic level. The logic diagram can be modified by just clicking on the connections.
- Set first input signal toT6_postscaled_out
- Connect the first input signal toGate 1 by clicking on the input line toGate 1.
- SetGate 2 andGate 4 outputs toInverted by clicking on theoutput line.
With the inputs of Gate 2 and Gate 4 grounded and then the output inverted this sets the J and K inputs of the JK flip-flop to always high. The R pin is set low by Gate 3 setup which didn't require any changes from the default.
Connecting I/O pin
The output of the CLC JK Flip Flop needs to be connected to the LED. We can do that using thePeripheral Pin Select (PPS) feature built into the device. The MCC does the setup code for us so all that is needed is to change the blue lock for the PortC 5 pin to green in the CLC1OUT row of the Pin Manager Grid. This will connect the output of the Flip-FlopFlop to the I/O pin using the PPS.
6
Generate Driver Code
Click on theGenerate button in theProject Resources of the MCC screen to have the MCC create the drivers and a basemain.c file for the project.
7
main.c
The generatedmain.c file doesn't need any additional code because this application runs within the core independent peripheral hardware separate from the CPU.
while (1) { // Add your application code }/** End of File*/9
Make sure your Curiosity Board is connected to the USB port. Then, click onMake and Program Device. This will build the project again and launch the programmer built into the Curiosity Board. In the Output window, you should see a series of messages and when successful it will end with a "Programming and Verify Successful" message.
Output Window:
Connecting to MPLAB Starter Kit on Board...Currently loaded firmware on Starter Kit on BoardFirmware Suite Version.....01.41.07Firmware type..............Enhanced MidrangeTarget detectedDevice ID Revision = 2004The following memory area(s) will be programmed:program memory: start address = 0x0, end address = 0x7ffconfiguration memoryProgramming...Programming/Verify completeIf it's the first time the programmer is connected to the board, the programming tool may need to download the proper operating firmware for the exact device. You may see a series of messages if this occurs. This should only happen once.
Downloading Firmware…
Downloading bootloader
Bootloader download complete
Programming download…
Downloading RS…
RS download complete
Programming download…
Downloading AP…
AP download complete
Programming download…
Firmware Suite Version…..01.34.11
Firmware type…………..Enhanced Midrange
Results
The D7 LED will begin to blink on the Curiosity Board. This shows the CIP hardware is controlling the LED I/O pin even though there is no code in thewhile (1) loop ofmain.c.
Analysis
The CIP peripherals, and especially the CLC, can be built to perform various logical functions and take the burden off the main processor. It's almost like having two microcontrollers in one package.
Conclusions
The CLC module has many different configuration options. These should be explored beyond this simple project. Fortunately, the steps shown here to set up the CLC are common with any other similar type of project you may develop with these very useful peripherals.











