GPIO Library
GPIO library includes a set of routines for easier handling of the General Purpose Input/Output (GPIO) pin functions.
Library Routines
GPIO_Pin_Config
Prototype |
char GPIO_Pin_Config(char pinNum, char dir, unsigned long config);
|
Description |
The function will configure the desired pins according to the parameters used.
|
Parameters |
pinNum : pin(s) we wish to configure. Pin number ranges from _GPIO_PIN_NUM_0 to _GPIO_PIN_NUM_66 .
dir : direction of the desired pins :
Value |
Description |
_GPIO_DIR_INPUT |
Configure pin as input. |
_GPIO_DIR_OUTPUT |
Configure pin as output. |
_GPIO_DIR_OD_OUTPUT |
Configure pin as an open drain output. |
_GPIO_DIR_NO_CHANGE |
Don't change previously set pin direction. |
config : desired function and configuration of the pin (these values can be OR-ed for a desired combination) :
Value |
Description |
_GPIO_CFG_PULL_UP |
Configure pin(s) as pull-up. |
_GPIO_CFG_PULL_DOWN |
Configure pin(s) as pull-down. |
_GPIO_CFG_PULL_NONE |
Pin(s) don't have pull-up/pull-down configuration. |
_GPIO_CFG_PULL_KEEPER |
Enable pin-keeper function. |
_GPIO_CFG_DRIVE_4mA |
4mA pin(s) output drive strength. |
_GPIO_CFG_DRIVE_8mA |
8mA pin(s) output drive strength. |
_GPIO_CFG_DRIVE_12mA |
12mA pin(s) output drive strength. |
_GPIO_CFG_DRIVE_16mA |
16mA pin(s) output drive strength. |
_GPIO_CFG_SLEW_RATE_FAST |
Fast slew rate control. |
_GPIO_CFG_SLEW_RATE_SLOW |
Slow slew rate control. |
_GPIO_CFG_SCHMITT_ENABLE |
Enable Schmitt trigger function. |
_GPIO_CFG_SCHMITT_DISABLE |
Disable Schmitt trigger function. |
_GPIO_CFG_SPEC_NONE |
No special function on the desired pin(s). |
_GPIO_CFG_SPEC_FUNC_1 |
Special function 1 on the desired pin(s). See datasheet for the special function availability for the desired pin. |
_GPIO_CFG_SPEC_FUNC_2 |
Special function 2 on the desired pin(s). See datasheet for the special function availability for the desired pin. |
_GPIO_CFG_SPEC_FUNC_3 |
Special function 3 on the desired pin(s). See datasheet for the special function availability for the desired pin. |
_GPIO_CFG_NO_CHANGE |
Don't change previously set pin configuration. |
|
Returns |
_GPIO_STATUS_OK - if there were no errors,
_GPIO_STATUS_ERROR - if an error occured.
|
Requires |
Nothing.
|
Example |
GPIO_Pin_Config(_GPIO_PIN_NUM_0, _GPIO_CFG_DRIVE_8mA | _GPIO_CFG_PULL_NONE | _GPIO_CFG_SCHMITT_DISABLE | _GPIO_CFG_SLEW_RATE_FAST);
|
Notes |
None.
|
Prototype |
char GPIO_Pin_Digital_Input(char pinNum);
|
Description |
The function will configure the desired pin(s) as digital input. By default, the function will also configure the pin(s) as follows :
- Pull-up/down configuration disabled,
- Schmitt trigger disabled,
- Fast slew rate enabled.
|
Parameters |
pinNum : pin(s) we wish to configure as input. Pin number ranges from _GPIO_PIN_NUM_0 to _GPIO_PIN_NUM_66 .
|
Returns |
_GPIO_STATUS_OK - if there were no errors,
_GPIO_STATUS_ERROR - if an error occured.
|
Requires |
Nothing.
|
Example |
// set pin 0 as digital input
GPIO_Pin_Digital_Input(_GPIO_PIN_NUM_0);
|
Notes |
None..
|
GPIO_Pin_Digital_Output
Prototype |
char GPIO_Pin_Digital_Output(char pinNum);
|
Description |
The function will configure the desired pin(s) as digital output. By default, the function will also configure the pin(s) as follows :
- Pull-up/down configuration disabled,
- Schmitt trigger disabled,
- Fast slew rate enabled.
|
Parameters |
pinNum : pin(s) we wish to configure as input. Pin number ranges from _GPIO_PIN_NUM_0 to _GPIO_PIN_NUM_66 .
|
Returns |
_GPIO_STATUS_OK - if there were no errors,
_GPIO_STATUS_ERROR - if an error occured.
|
Requires |
Nothing.
|
Example |
// set pin 0 as digital output
GPIO_Pin_Digital_Output(_GPIO_PIN_NUM_0);
|
Notes |
None.
|
GPIO_Pin_Write
Prototype |
char GPIO_Pin_Write(char pinNum, char pinValue);
|
Description |
The function will write the desired value to the desired pin(s).
|
Parameters |
pinNum : number of pin(s) we wish to configure as input. Pin number ranges from _GPIO_PIN_NUM_0 to _GPIO_PIN_NUM_66 .
pinValue : value that that we wish to write to the desired pin :
Value |
Description |
_GPIO_PIN_VALUE_0 |
Logical 0 value. |
_GPIO_PIN_VALUE_1 |
Logical 1 value. |
|
Returns |
_GPIO_STATUS_OK - if there were no errors,
_GPIO_STATUS_ERROR - if an error occured.
|
Requires |
The desired pin must previously set as output.
|
Example |
GPIO_Pin_Write(_GPIO_PIN_NUM_0, _GPIO_PIN_VALUE_1)
|
Notes |
None.
|
GPIO_Pin_Read
Prototype |
char GPIO_Pin_Read(char pinNum);
|
Description |
The function will read the current value from the desired pin.
|
Parameters |
pinNum : pin number from which we wish to read the value. Pin number ranges from _GPIO_PIN_NUM_0 to _GPIO_PIN_NUM_66 .
|
Returns |
_GPIO_PIN_VALUE_0 - logical 0 value read,
_GPIO_PIN_VALUE_1 - logical 1 value read,
_GPIO_STATUS_ERROR - if an error occured.
|
Requires |
The desired pin must previously set as input.
|
Example |
read_value = GPIO_Pin_Read(_GPIO_PIN_NUM_0);
|
Notes |
None.
|
GPIO_Config
Prototype |
char GPIO_Config(char *port, char pin_mask, char dir, unsigned long config);
|
Description |
The function will configure the desired pins according to the parameters used.
|
Parameters |
port : port we wish to use. Valid values :
Value |
Description |
GPIO_PORT_00_07 |
GPIO port consisting of pins 0 - 7. |
GPIO_PORT_08_15 |
GPIO port consisting of pins 8 - 15. |
GPIO_PORT_16_23 |
GPIO port consisting of pins 16 - 23. |
GPIO_PORT_24_31 |
GPIO port consisting of pins 24 - 31. |
GPIO_PORT_32_39 |
GPIO port consisting of pins 32 - 39. |
GPIO_PORT_40_47 |
GPIO port consisting of pins 40 - 47. |
GPIO_PORT_48_55 |
GPIO port consisting of pins 48 - 55. |
GPIO_PORT_56_63 |
GPIO port consisting of pins 56 - 63. |
GPIO_PORT_64_66 |
GPIO port consisting of pins 64 - 66. |
pin_mask : pins we wish to configure (these values can be OR-ed for a desired combination) :
Value |
Description |
_GPIO_PINMASK_0 |
Pin 0 mask. |
_GPIO_PINMASK_1 |
Pin 1 mask. |
_GPIO_PINMASK_2 |
Pin 2 mask. |
_GPIO_PINMASK_3 |
Pin 3 mask. |
_GPIO_PINMASK_4 |
Pin 4 mask. |
_GPIO_PINMASK_5 |
Pin 5 mask. |
_GPIO_PINMASK_6 |
Pin 6 mask. |
_GPIO_PINMASK_7 |
Pin 7 mask. |
_GPIO_PINMASK_ALL |
All pins masked. |
dir : direction of the desired pins :
Value |
Description |
_GPIO_DIR_INPUT |
Configure pin as input. |
_GPIO_DIR_OUTPUT |
Configure pin as output. |
_GPIO_DIR_OD_OUTPUT |
Configure pin as open drain output. |
config : desired function and configuration of the pin (these values can be OR-ed for a desired combination) :
Value |
Description |
_GPIO_DIR_INPUT |
Configure pin as input. |
_GPIO_DIR_OUTPUT |
Configure pin as output. |
_GPIO_DIR_OD_OUTPUT |
Configure pin as an open drain output. |
_GPIO_DIR_NO_CHANGE |
Don't change previously set pin direction. |
config : desired function and configuration of the pin (these values can be OR-ed for a desired combination) :
Value |
Description |
_GPIO_CFG_PULL_UP |
Configure pin(s) as pull-up. |
_GPIO_CFG_PULL_DOWN |
Configure pin(s) as pull-down. |
_GPIO_CFG_PULL_NONE |
Pin(s) don't have pull-up/pull-down configuration. |
_GPIO_CFG_PULL_KEEPER |
Enable pin-keeper function. |
_GPIO_CFG_DRIVE_4mA |
4mA pin(s) output drive strength. |
_GPIO_CFG_DRIVE_8mA |
8mA pin(s) output drive strength. |
_GPIO_CFG_DRIVE_12mA |
12mA pin(s) output drive strength. |
_GPIO_CFG_DRIVE_16mA |
16mA pin(s) output drive strength. |
_GPIO_CFG_SLEW_RATE_FAST |
Fast slew rate control. |
_GPIO_CFG_SLEW_RATE_SLOW |
Slow slew rate control. |
_GPIO_CFG_SCHMITT_ENABLE |
Enable Schmitt trigger function. |
_GPIO_CFG_SCHMITT_DISABLE |
Disable Schmitt trigger function. |
_GPIO_CFG_SPEC_NONE |
No special function on the desired pin(s). |
_GPIO_CFG_SPEC_FUNC_1 |
Special function 1 on the desired pin(s). See datasheet for the special function availability for the desired pin. |
_GPIO_CFG_SPEC_FUNC_2 |
Special function 2 on the desired pin(s). See datasheet for the special function availability for the desired pin. |
_GPIO_CFG_SPEC_FUNC_3 |
Special function 3 on the desired pin(s). See datasheet for the special function availability for the desired pin. |
_GPIO_CFG_NO_CHANGE |
Don't change previously set pin configuration. |
|
Returns |
_GPIO_STATUS_OK - if there were no errors.
|
Requires |
Nothing.
|
Example |
GPIO_Config(&GPIO_PORT_00_07, _GPIO_PINMASK_0 | _GPIO_PINMASK_1, GPIO_DIR_OUTPUT, _GPIO_CFG_DRIVE_8mA | _GPIO_CFG_PULL_NONE | _GPIO_CFG_SCHMITT_DISABLE | _GPIO_CFG_SLEW_RATE_FAST);
|
Notes |
None.
|
Prototype |
char GPIO_Digital_Input(char *port, char pin_mask);
|
Description |
The function will configure the desired pin(s) as digital input. By default, the function will also configure the pin(s) as follows :
- Pull-up/down configuration disabled,
- Schmitt trigger disabled,
- Fast slew rate enabled.
|
Parameters |
port : desired port on which the function will be applied. Valid values :
Value |
Description |
GPIO_PORT_00_07 |
GPIO port consisting of pins 0 - 7. |
GPIO_PORT_08_15 |
GPIO port consisting of pins 8 - 15. |
GPIO_PORT_16_23 |
GPIO port consisting of pins 16 - 23. |
GPIO_PORT_24_31 |
GPIO port consisting of pins 24 - 31. |
GPIO_PORT_32_39 |
GPIO port consisting of pins 32 - 39. |
GPIO_PORT_40_47 |
GPIO port consisting of pins 40 - 47. |
GPIO_PORT_48_55 |
GPIO port consisting of pins 48 - 55. |
GPIO_PORT_56_63 |
GPIO port consisting of pins 56 - 63. |
GPIO_PORT_64_66 |
GPIO port consisting of pins 64 - 66. |
pin_mask : desired pin(s) on which the function will be applied (these values can be OR-ed for a desired combination) :
Value |
Description |
_GPIO_PINMASK_0 |
Pin 0 mask. |
_GPIO_PINMASK_1 |
Pin 1 mask. |
_GPIO_PINMASK_2 |
Pin 2 mask. |
_GPIO_PINMASK_3 |
Pin 3 mask. |
_GPIO_PINMASK_4 |
Pin 4 mask. |
_GPIO_PINMASK_5 |
Pin 5 mask. |
_GPIO_PINMASK_6 |
Pin 6 mask. |
_GPIO_PINMASK_7 |
Pin 7 mask. |
_GPIO_PINMASK_ALL |
All pins masked. |
|
Returns |
_GPIO_STATUS_OK - if there were no errors.
|
Requires |
Nothing.
|
Example |
// Set GPIO_PORT_00_07 pins 0 and 1 as input
GPIO_Digital_Input(&GPIO_PORT_00_07, _GPIO_PINMASK_0 | _GPIO_PINMASK_1);
|
Notes |
None.
|
GPIO_Digital_Output
Prototype |
char GPIO_Digital_Output(char *port, char pin_mask);
|
Description |
The function will configure the desired pin(s) as digital output. By default, the function will also configure the pin(s) as follows :
- Pull-up/down configuration disabled,
- Schmitt trigger disabled,
- Fast slew rate enabled.
|
Parameters |
port : desired port on which the function will be applied. Valid values :
Value |
Description |
GPIO_PORT_00_07 |
GPIO port consisting of pins 0 - 7. |
GPIO_PORT_08_15 |
GPIO port consisting of pins 8 - 15. |
GPIO_PORT_16_23 |
GPIO port consisting of pins 16 - 23. |
GPIO_PORT_24_31 |
GPIO port consisting of pins 24 - 31. |
GPIO_PORT_32_39 |
GPIO port consisting of pins 32 - 39. |
GPIO_PORT_40_47 |
GPIO port consisting of pins 40 - 47. |
GPIO_PORTG |
GPIO PORTG. |
GPIO_PORT_56_63 |
GPIO port consisting of pins 56 - 63. |
GPIO_PORT_64_66 |
GPIO port consisting of pins 64 - 66. |
pin_mask : desired pin(s) on which the function will be applied (these values can be OR-ed for a desired combination) :
Value |
Description |
_GPIO_PINMASK_0 |
Pin 0 mask. |
_GPIO_PINMASK_1 |
Pin 1 mask. |
_GPIO_PINMASK_2 |
Pin 2 mask. |
_GPIO_PINMASK_3 |
Pin 3 mask. |
_GPIO_PINMASK_4 |
Pin 4 mask. |
_GPIO_PINMASK_5 |
Pin 5 mask. |
_GPIO_PINMASK_6 |
Pin 6 mask. |
_GPIO_PINMASK_7 |
Pin 7 mask. |
_GPIO_PINMASK_ALL |
All pins masked. |
|
Returns |
_GPIO_STATUS_OK - if there were no errors.
|
Requires |
Nothing.
|
Example |
// Set GPIO_PORT_00_07 pins 0 and 1 as output
GPIO_Digital_Output(&GPIO_PORT_00_07, _GPIO_PINMASK_0 | _GPIO_PINMASK_1);
|
Notes |
None.
|
Copyright (c) 2002-2015 mikroElektronika. All rights reserved.
What do you think about this topic ?
Send us feedback!
Want more examples and libraries?
Find them on