Giter Club home page Giter Club logo

pic16f15244-ioc-example's Introduction

MCHP

Transmit "Button pressed" using Interrupt-on-Change with PIC16F15244

The 'pic16f15244-ioc-example' code example uses the PIC16F15244 Curiosity Nano Development board to demonstrate how to transmit "Button pressed!" to a PC terminal application each time the Nano's push-button (SW0) is pressed. The example highlights the use of the Interrupt-on-Change (IOC) and EUSART (Enhanced/Addressable Universal Asynchronous Receiver Transceiver) modules.

PIC16F15244 Curiosity Nano Development Board:

Curiosity Nano Development Board

Related Documentation

Software Used

Hardware Used

  • PIC16F15244 Curiosity Nano
  • Micro-USB to USB 2.0 cable

Setup

  1. Connect the PIC16f15244 Curiosity Nano board to a PC using the Micro-USB to USB 2.0 cable.
  2. If not already on your system, download and install MPLABX IDE version 6.10 (or newer).
  3. If not already on your system, download and install the XC8 C-Compiler version 2.41 (or newer).
  4. Open the 'pic16f15244-ioc-example.X' project as shown in Figure 1.
Figure 1: Open Project Window

Open Project Window

  1. Click -> Project Properties button to open the Project Properties window. Select the Curiosity tool from the Tools drop-down menu as shown in Figure 2.
Figure 2: Select the Nano in Project Properties Window

Select Tool

  1. Press the 'Make and Program Device' button to program the PIC (see Figure 3). Verify that the device was successfully programmed (see Figure 4).
Figure 3: 'Make and Program Device' Button

Program Device Button

Figure 4: Program Complete

Program Complete

  1. For Windows PC: Open a terminal program. For this example, Tera Term was used as the terminal program.

a. Select the port that is used by the Nano board as shown in Figure 5.
b. Configure the serial port as shown in Figure 6.

Figure 5: Select the USB Port

Select USB Port

Figure 6: Configure the Serial Port

Configure Serial Port

  1. For MacOS: Open a terminal program. For this example, open a Terminal.app window. We shall use screen as the terminal program.

a. With the project loaded in MPLAB & the Curiosity Nano board connected to the Mac's USB port: Find the tty device being used:

```zsh  
% ls -l /dev | grep tty.usb          # search for a tty.usb connection  
crw-rw-rw-  1 root    wheel           18,   4 May  8 01:06 tty.usbmodem14102  
%  
```  

b. start screen in Terminal.app & configure the serial port in one command:

```zsh
% screen  /dev/tty.usbmodem14102 9600  
```  

This creates a connection to the serial port and enables messages to appear "screen" on Terminal.app when the button is pushed.
Note: The tty will change from time to time, but will always begin with `.usbmodem`

Operation

After the Nano board is programmed, the EUSART module will transmit the string "Button pressed!" to the PC terminal window each time push-button SW0 is pressed.

Input pin RC2 is connected to the output of SW0. Pin RC2 is pulled to a logic 'HIGH' state during normal operation. When SW0 is pressed, the internal circuit of the button makes a complete connection, allowing the voltage to flow through the pin to ground. When this transition of a logic 'HIGH' to logic 'LOW' occurs, IOC hardware detects this change and issues a negative-edge interrupt. The Interrupt Service Routine (ISR) will then clear the IOCCF flag and transmit the string 'Button pressed!' over the EUSART. The IOC edge selection can be configured in MCC as shown in Figure 7.

Figure 7: IOC Edge Selection in MCC

IOC Edge Selection

Output pin RC0 is configured as the TX output through PPS. Nano hardware also connects pin RC0 to the USB receive line, allowing a quick connection to the PC terminal without any additional wires or USB bridge circuits.

The EUSART module is configured to use the printf() function call that it built in to the XC8 libraries. In MCC, check the 'Redirect Printf to USART' check-box as shown in Figure 8, and the additional function calls are added to the project. Example 1 shows the use of the printf() function in the IOC ISR.

Figure 8: 'Redirect Printf to USART' Check-box

STDIO to USART

Example 1: IOCCF Interrupt Service Routine Code Snippet
void SW0_ISR(void)
{
    // Add custom IOCCF2 code
    // Call the interrupt handler for the callback registered at runtime
    if(SW0_InterruptHandler)
    {
        SW0_InterruptHandler();
    }
    IOCCFbits.IOCCF2 = 0;
}

static void SW0_UserCallback(void)
{
     printf("Button pressed! \r\n");
}

Summary

The 'pic16f15244-ioc-example' code example uses the PIC16F15244 Curiosity Nano Development board to demonstrate how to transmit 'Button pressed!' to a PC terminal window each time push-button SW0 is pressed. The example uses the Interrupt-on-Change (IOC) module to detect a positive to negative-edge transition on the input pin, and the EUSART module to transmit the string 'Button pressed!' to the PC terminal window.

Figure 9: Button Pressed!

Terminal Window

pic16f15244-ioc-example's People

Contributors

aku-work avatar ashishmakthal avatar jams100000-mchp avatar jason-layton avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.