libpic170x  0.2
Ease of use library for PIC16(L)1705/1709 chips
Classes | Macros | Functions | Variables
io_control.h File Reference

GPIO input/output library allowing to write to and read from IO pins. More...

#include <stdint.h>
#include <stdbool.h>
Include dependency graph for io_control.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  PinDef
 Record to store a collection of registers and masks related to a pin. More...
 

Macros

#define PIN_INPUT_MODE_DIGITAL   0
 See pin_set_input_mode())
 
#define PIN_INPUT_MODE_ANALOG   1
 See pin_set_input_mode())
 

Functions

void pin_set_pin_mode (const PinDef *def, bool output)
 
bool pin_get_input (const PinDef *def)
 
void pin_set_output (const PinDef *def, bool on)
 
void pin_set_input_mode (const PinDef *def, uint8_t input_mode)
 

Variables

const PinDefPIN_RA0
 PIN_RA0 defintion.
 
const PinDefPIN_RA1
 PIN_RA1 defintion.
 
const PinDefPIN_RA2
 PIN_RA2 defintion.
 
const PinDefPIN_RA3
 PIN_RA3 defintion.
 
const PinDefPIN_RA4
 PIN_RA4 defintion.
 
const PinDefPIN_RA5
 PIN_RA5 defintion.
 
const PinDefPIN_RB4
 PIN_RB4 defintion.
 
const PinDefPIN_RB5
 PIN_RB5 defintion.
 
const PinDefPIN_RB6
 PIN_RB6 defintion.
 
const PinDefPIN_RB7
 PIN_RB7 defintion.
 
const PinDefPIN_RC0
 PIN_RC0 defintion.
 
const PinDefPIN_RC1
 PIN_RC1 defintion.
 
const PinDefPIN_RC2
 PIN_RC2 defintion.
 
const PinDefPIN_RC3
 PIN_RC3 defintion.
 
const PinDefPIN_RC4
 PIN_RC4 defintion.
 
const PinDefPIN_RC5
 PIN_RC5 defintion.
 
const PinDefPIN_RC6
 PIN_RC6 defintion.
 
const PinDefPIN_RC7
 PIN_RC7 defintion.
 

Detailed Description

GPIO input/output library allowing to write to and read from IO pins.

The library defines a set of pin_ functions that operate on pin-defintions. Pin definitions are also defined in this library but depend on the chip setting that was used to compile the library. Pin-definitions are named PIN_Rxx, where xx stands for the pin name according to the data sheet for the used chip. Example: PIN_RC2.

Note that all pins are always defined, however, since the the PIC16(L)F1705 has less pins than the PIC16(L)F1709, some pin defintions will be set to NULL. Here a defintion checklist for the two supported PIC chips:

Pin PIC16(L)F1705 PIC16(L)F1709
PIN_RA0
PIN_RA1
PIN_RA2
PIN_RA3
PIN_RA4
PIN_RA5
PIN_RB4 NULL
PIN_RB5 NULL
PIN_RB6 NULL
PIN_RB7 NULL
PIN_RC0
PIN_RC1
PIN_RC2
PIN_RC3
PIN_RC4
PIN_RC5
PIN_RC6 NULL
PIN_RC7 NULL

For a working example on how to use the library, check the "blink" example, in this repository.

Definition in file io_control.h.

Function Documentation

◆ pin_get_input()

bool pin_get_input ( const PinDef def)

Reads the input value from the the given pin. Returns the value the PORTx register if the pin is configured as input. If the pin is configured as output, the returned value will be the value of LATx, meaning the result will be the value of the intended output (see pin_set_pin_mode()).

Parameters
defThe pin to read the input state from.
Returns
True if the input is high.

Definition at line 118 of file io_control.c.

◆ pin_set_input_mode()

void pin_set_input_mode ( const PinDef def,
uint8_t  input_mode 
)

Configures the input mode of a given port.

  • PIN_INPUT_MODE_DIGITAL configures a pin as digital input.
  • PIN_INPUT_MODE_ANALOG configures a pin as analog input (the default after reset).

Note that some chip modules require pins to be in a certain mode.

Parameters
defThe pin to set the input mode for.
input_modeSet to PIN_INPUT_MODE_ANALOG or PIN_INPUT_MODE_DIGITAL.

Definition at line 141 of file io_control.c.

◆ pin_set_output()

void pin_set_output ( const PinDef def,
bool  on 
)

Sets the digital output to the given state (LATx register). Will only have an effect if the pin has been set to output-mode before.

Parameters
defThe pin to write.
onTrue to set output high, false to set the output to low.

Definition at line 129 of file io_control.c.

◆ pin_set_pin_mode()

void pin_set_pin_mode ( const PinDef def,
bool  output 
)

Configures a pin as input or output. Writes the corresponding TRISx register.

Parameters
defPin to configure.
outputSet to true to make it an output, false to make it a digital input.

Definition at line 106 of file io_control.c.