Port Driver¶
Port driver provides abstraction for accessing and controlling an entire port of your microcontroller.
Using Port driver you can configure a port as digital input or output, write to a port and read from a port.
To use this library
Header: #include "drv_port.h"
memake: MikroSDK.Driver
Initialization¶
Before using other driver functions, user has to define driver context variable and initialize it, as shown below:
port_t port;
port_init( &port, PORT_A, 0xFFFF, GPIO_DIGITAL_OUTPUT );
Parameter | Description |
---|---|
port |
Context variable |
PORT_A |
Actual MCU port |
0xFFFF |
Determines which pins will be configured; in this case all |
GPIO_DIGITAL_OUTPUT |
Digital output |
Default state
Default state of the configured port is logical low, if pins are configured as digital output.
Writing to port¶
After configuring the port as digital output, you can use port_write()
function for writing desired value to the port, as shown below:
uint16_t value = 0xAAAA;
port_write( &port, value );
Reading from port¶
After configuring the port as digital input, you can use port_read()
function
for reading from the port, as shown below:
uint16_t read_value;
read_value = port_read( &port );