libpic170x
0.2
Ease of use library for PIC16(L)1705/1709 chips
|
GPIO input/output library allowing to write to and read from IO pins. More...
#include <stdint.h>
#include <stdbool.h>
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 PinDef * | PIN_RA0 |
PIN_RA0 defintion. | |
const PinDef * | PIN_RA1 |
PIN_RA1 defintion. | |
const PinDef * | PIN_RA2 |
PIN_RA2 defintion. | |
const PinDef * | PIN_RA3 |
PIN_RA3 defintion. | |
const PinDef * | PIN_RA4 |
PIN_RA4 defintion. | |
const PinDef * | PIN_RA5 |
PIN_RA5 defintion. | |
const PinDef * | PIN_RB4 |
PIN_RB4 defintion. | |
const PinDef * | PIN_RB5 |
PIN_RB5 defintion. | |
const PinDef * | PIN_RB6 |
PIN_RB6 defintion. | |
const PinDef * | PIN_RB7 |
PIN_RB7 defintion. | |
const PinDef * | PIN_RC0 |
PIN_RC0 defintion. | |
const PinDef * | PIN_RC1 |
PIN_RC1 defintion. | |
const PinDef * | PIN_RC2 |
PIN_RC2 defintion. | |
const PinDef * | PIN_RC3 |
PIN_RC3 defintion. | |
const PinDef * | PIN_RC4 |
PIN_RC4 defintion. | |
const PinDef * | PIN_RC5 |
PIN_RC5 defintion. | |
const PinDef * | PIN_RC6 |
PIN_RC6 defintion. | |
const PinDef * | PIN_RC7 |
PIN_RC7 defintion. | |
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.
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()).
def | The pin to read the input state from. |
Definition at line 118 of file io_control.c.
void pin_set_input_mode | ( | const PinDef * | def, |
uint8_t | input_mode | ||
) |
Configures the input mode of a given port.
Note that some chip modules require pins to be in a certain mode.
def | The pin to set the input mode for. |
input_mode | Set to PIN_INPUT_MODE_ANALOG or PIN_INPUT_MODE_DIGITAL. |
Definition at line 141 of file io_control.c.
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.
def | The pin to write. |
on | True to set output high, false to set the output to low. |
Definition at line 129 of file io_control.c.
void pin_set_pin_mode | ( | const PinDef * | def, |
bool | output | ||
) |
Configures a pin as input or output. Writes the corresponding TRISx register.
def | Pin to configure. |
output | Set to true to make it an output, false to make it a digital input. |
Definition at line 106 of file io_control.c.