libpic170x
0.2
Ease of use library for PIC16(L)1705/1709 chips
|
The PinIO library io_control.h allows easy control of a PIC's GPIO pins. It also provides definitions that are internally used by other libraries for interacting with pins. The current set of features is:
When a PIC is reset, all pins are set to "input, high impedance mode". Therefore, reading data from individual pins is simply done by invoking the pin_get_input(PinDef*) function. A PinDef* defines the pin for which the input state should be retrieved. All pins of supported PICs are defines as contants of the form PIN_RA0
, referring to pin RA0 on a supported PIC. If a pin is not present on a given PIC, like, for example, PIN_RB4
on a PIC16LF1705, uses of that variable will still be valid but calls to any function in io_control.h for that pin will result in NOP.
To swtich a pin from input to low-impedance output mode, you can use the function pin_set_pin_mode(). The function takes two arguments, the first being the pin to set, the second being the mode, where true
indicates that the pin should be configured in output mode, and false
that the pin should be configured in input mode.
Additionally, pins can be switched between analog and digital input modes. By default all pins are configured to use analog input mode, but for digital signals it is generally advisable to switch pins to ditigal input mode, and even required if an input pin is meant to be used with any other digital subsystem like the UART module. Switching the input mode can be done using the function pin_set_input_mode(). The function can set the input mode a pin to:
PIN_INPUT_MODE_DIGITAL
digital modePIN_INPUT_MODE_ANALOG
analog mode (the default)When intending to read digital input signals, a better example of the first code snipped shown on this page would therefore be:
If a pin has been configured as an output, it is likely that one wnnts to write out data via the pin. This can be achived by using the function pin_set_output(). The function takes a single argument, namely the intended output state of the pin.
A simple "led blink" example: