Conditional Wake-Up from SLEEP using the CLC


This example uses two simultaneous conditions to wake the PIC16F18855 from sleep mode. The first is when the push button on the MPLAB® Xpress Development Board is pressed and the second is a transmission attempt detected on the RX pin of the Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART) peripheral. Each of these conditions alone won’t wake the device. Only when both the push button is pressed and held simultaneously at the same time data is received on the EUSART RX pin, then and only then will the Microcontroller (MCU) wake up.


Many applications need to conserve power like battery-powered or energy-harvesting designs. It is common in such applications to place the MCU into a low-power SLEEP Mode. This mode disables the MCU clock and the Central Processing Unit (CPU) stops executing code.

The MCU is kept in this SLEEP mode until a specific event trigger called a Wake-up has occurred indicating that something in the application requires attention. This is usually done with some sort of a pin state change.

There is a problem though….what if the MCU is only needed to make system changes when two or more conditions are present.

Traditionally this is done using a single pin change that wakes the MCU. The CPU then checks to see if other inputs have changed that constitute the specific condition. If those inputs have not changed then the MCU is placed back into SLEEP mode having just wasted power unnecessarily by waking and performing the check.


A lower power alternative is available that makes use of the Configurable Logic Cell (CLC) peripheral available on many 8-bit PIC® Microcontrollers including the PIC16F18855 on the MPLAB Xpress Development Board.

Since the CLC is able to continue running even in SLEEP mode and the MCU can be woken by an interrupt created by a CLC interrupt, it is possible to conditionally wake the device.



Hardware Tools (Optional)

Tool About Purchase
MPLAB® Xpress
Development Board

Software Tools

Tool About Installers
Windows Linux Mac OSX
Integrated Development Environment

Exercise Files

File Download
Windows Linux Mac OSX
Project and Source Files
Board Schematic


To follow along with these steps, MPLAB Xpress Development Board should be open and the user should be logged in so that the MPLAB Code Configurator plug-in can be used.


Create Project

Create a new project in MPLAB Xpress Development Board for a PIC16F1855 using the MPLAB Xpress Development Board called conditionalWakeCLC.

Instructions are below if this is your first project.


Open MCC

Open the MPLAB Code Configurator (MCC).

The default System settings can be used.

Instructions are below if this is your first project.



Select the EUSART from the MCC peripheral menu. The EUSART block is located under Device Resources section of the MCC.


Setup the EUSART peripheral as follows:

  • 9600 is selected from the Baud Rate drop-down menu
  • Enable Transmit checkbox is selected
  • Redirect STDIO to USART checkbox is selected to allow printf() to be used

Double clicking on the EUSART opens the EUSART setup window:



CLC setup

Scroll through the Device Resources section and locate the CLC peripheral. Add CLC1 to the project by double-clicking on it.


Select the CLC1 peripheral under Project Resources to open the Easy Setup dialog and configure as follows:

  • Select Enable CLC Interrupt as this CLC will be the Wake-up source for the PIC16F18855 out of low power SLEEP mode
  • Select Enable Rising Interrupt. This will trigger the interrupt when the output of the CLC1 peripheral goes from LOW to HIGH
  • Choose AND-OR from the CLC Mode drop-down menu
  • Connect the CLCIN0 to the top input of the OR 1gate and the CLCIN1 to the second input of the OR 2 gate
  • Negate both OR gate outputs

The Easy Setup for the CLC1 peripheral should now resemble the image below:



Pin Manager

Navigate to the Pin Manager and connect the following peripheral signals to the listed pins:

  • CLCIN1 signal to the RA5 pin connected to the pushbutton on the MPLAB Xpress Board
  • CLCIN0 signal to the RC1 pin
  • RC0 pin to the TX signal and RC1 pin to the RX signal

NOTE: The RC0 pin is shared by both the CLCIN0 signal of the CLC1 and the RX input signal of the EUSART. This capability is due to the Peripheral Pin Select (PPS) capabilities of the PIC16F18855. When pins are shared by more than one peripheral, the lock icon in the Pin Manager is replaced by a chain link icon.


Generate Code

Generate the code based on the above setting by clicking on the Generate button at the top right of the IDE and then click OK in the Generation Completed dialog


Edit Main.c

Navigate to the MPLAB Xpress IDE and open the main.c source file in the Project pane.

Inside of the main() uncomment the INTERRUPT_GlobalInterruptEnable(); macro to enable global interrupts and the INTERRUPT_PeripheralInterruptEnable() macro to enable peripheral interrupts. The CLC1 peripheral was configured to utilize interrupts that will be used to wake the PIC16F18855 from low power SLEEP mode.

Next, add code that will:

  1. Notify the user that the MCU is about to go into a low power state by transmitting a message over the EUSART
  2. Place the device into low power SLEEP
  3. Notify the user if and when the MCU is woken by the conditions defined in the CLC1 configuration

Scroll down through the main() to the while(1) loop. Inside of the loop add the following code just below the //Add your application code comments:


Program Xpress Board

Compile the project by clicking on the Make and Program Device button and then drag the .hex file to the Xpress board shown in the file manager.


Once the MPLAB Xpress board is programmed, open a terminal program such as CoolTerm and connect to the COM port assigned to the board.

Push the RESET button on the MPLAB Xpress Development Board.


This will restart code execution on the MCU and output the notification that the device is going into SLEEP mode.


Pressing the pushbutton alone on the MPLAB Xpress Development Board will result in no messages printing to the terminal program window.


Using the mouse, click inside of the terminal window and hit the return key. The program will indicate that a message has been transmitted over the COM port. Again, no messages should print to the terminal program window.

Finally, while pressing the push button, click inside of the terminal program window with the mouse and hit the enter key. This time the notification will appear inside of the terminal window indicating that the MCU has awoken since the conditions defined during CLC1 configuration have been met. After 500 ms the notification that the device going back into SLEEP mode will be printed to the terminal window confirming the MCU is now back in a low power mode.



Although the EUSART and a push button were used as the CLC inputs, the user should note that other on- and off-chip input sources can be used. These could include other sensors, timer outputs, and even other CLCs. Any of these signals can be used in conjunction with logical operations such as OR, XOR or AND operations or even combine this with state machine behavior by incorporating flip-flops, waking the device from Sleep only when a very specific combination occurs.

© 2016 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.