1.IO口输出高/低电平
(1)初始化
mxc_gpio_cfg_t gpio_out1 = {MXC_GPIO1, MXC_GPIO_PIN_6, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO};
MXC_GPIO_Config(&gpio_out1);
注:MXC_GPIO_VSSEL_VDDIO:1.8V, MXC_GPIO_VSSEL_VDDIOH:3.3V
(2)设置高低电平
MXC_GPIO_OutSet(MXC_GPIO_PORT_OUT2, MXC_GPIO_PIN_OUT2); // 高电平
MXC_GPIO_OutClr(MXC_GPIO_PORT_OUT2, MXC_GPIO_PIN_OUT2); // 低电平
(3)完整例子
#include "mxc_device.h"
#include "mxc_sys.h"
#include "board.h"
#include "gpio.h"
#include "led.h"
#include "mxc_delay.h"
/* GPIO output definitions */
#define MXC_GPIO_PORT_OUT1 MXC_GPIO2
#define MXC_GPIO_PIN_OUT1 MXC_GPIO_PIN_3 //P2_3
#define MXC_GPIO_PORT_OUT2 MXC_GPIO2
#define MXC_GPIO_PIN_OUT2 MXC_GPIO_PIN_4 //P2_4
#define MXC_GPIO_PORT_OUT3 MXC_GPIO2
#define MXC_GPIO_PIN_OUT3 MXC_GPIO_PIN_6 //P2_6
#define MXC_GPIO_PORT_OUT4 MXC_GPIO2
#define MXC_GPIO_PIN_OUT4 MXC_GPIO_PIN_7 //_2_7
int main()
{
/* Initialize system and clocks - Assuming this function exists and it's necessary for your hardware. */
/* Configure GPIO pins as output */
mxc_gpio_cfg_t gpio_out1 = {MXC_GPIO_PORT_OUT1, MXC_GPIO_PIN_OUT1, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH};
MXC_GPIO_Config(&gpio_out1);
mxc_gpio_cfg_t gpio_out2 = {MXC_GPIO_PORT_OUT2, MXC_GPIO_PIN_OUT2, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH};
MXC_GPIO_Config(&gpio_out2);
mxc_gpio_cfg_t gpio_out3 = {MXC_GPIO_PORT_OUT3, MXC_GPIO_PIN_OUT3, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH};
MXC_GPIO_Config(&gpio_out3);
mxc_gpio_cfg_t gpio_out4 = {MXC_GPIO_PORT_OUT4, MXC_GPIO_PIN_OUT4, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH};
MXC_GPIO_Config(&gpio_out4);//MXC_GPIO_VSSEL_VDDIO:1.8V, MXC_GPIO_VSSEL_VDDIOH:3.3V
MXC_GPIO_OutSet(MXC_GPIO_PORT_OUT1, MXC_GPIO_PIN_OUT1);//高电平
MXC_GPIO_OutSet(MXC_GPIO_PORT_OUT2, MXC_GPIO_PIN_OUT2);
//MXC_GPIO_OutClr(MXC_GPIO_PORT_OUT2, MXC_GPIO_PIN_OUT2);//低电平
MXC_GPIO_OutSet(MXC_GPIO_PORT_OUT3, MXC_GPIO_PIN_OUT3);
MXC_GPIO_OutSet(MXC_GPIO_PORT_OUT4, MXC_GPIO_PIN_OUT4);
while (1)
{
/* Set GPIO outputs to high level */
/* Delay for a second to observe the LED states,
remove if not necessary or adjust the delay as per your requirement. */
}
/* Normally this won't be executed */
return 0;
}
/* Define System_Init if necessary for your setup, or remove it if not needed */