1、简介
以下介绍美信系列MCU的GPIO操作,主要是实现通用推挽输出高电平、低电平,也可以设为开漏输出
2、操作步骤
Eclipse导入Hello World示例工程,将main.c文件内容全部删去
随后复制以下代码至main.c,以此作为空白模板工程
#include
<stdio.h>
#include
"mxc_device.h"
#include
"board.h"
 int
main(void)
{
 
}
如果需要对GPIO操作则需要引入gpio头文件,同时也引入delay头文件,用于调用延时函数
#include "mxc_delay.h"
3、gpio初始化
void GPIO_PIN_Init(mxc_gpio_regs_t * gpio_port,uint32_t gpio_pin,mxc_gpio_func_t gpio_pin_mode){
    mxc_gpio_cfg_t gpio_cfg;
    gpio_cfg.port=gpio_port;//port assigned 输出端口
    gpio_cfg.mask=gpio_pin; //pin assigned,or pins assigned 引脚
    gpio_cfg.pad=MXC_GPIO_PAD_PULL_DOWN;//pin pull up/down,pull up default 下拉
    gpio_cfg.func=gpio_pin_mode;      //pin mode 引脚工作模式
    gpio_cfg.vssel=MXC_GPIO_VSSEL_VDDIO;/**< Voltage select */
    gpio_cfg.drvstr=MXC_GPIO_DRVSTR_0;
    MXC_GPIO_Config(&gpio_cfg);
}板载LED在P0_14引脚

于是初始化端口MXC_GPIO0、引脚MXC_GPIO_PIN_14
GPIO_PIN_Init(MXC_GPIO0,MXC_GPIO_PIN_14,MXC_GPIO_FUNC_OUT);
main.c添加LED亮灭的GPIO操作
int main(void)
{
GPIO_PIN_Init(MXC_GPIO0,MXC_GPIO_PIN_14,MXC_GPIO_FUNC_OUT);
while(1){
MXC_GPIO_OutSet(MXC_GPIO0,MXC_GPIO_PIN_14);
MXC_Delay(500000);
MXC_GPIO_OutClr(MXC_GPIO0,MXC_GPIO_PIN_14);
MXC_Delay(500000);
}
}4、运行结果
右上角的LED不断间隔闪烁,表明GPIOP0_14引脚电平输出正常


 
					
				
 
			
			
			
						
			 
					
				 我要赚赏金
 我要赚赏金 STM32
STM32 MCU
MCU 通讯及无线技术
通讯及无线技术 物联网技术
物联网技术 电子DIY
电子DIY 板卡试用
板卡试用 基础知识
基础知识 软件与操作系统
软件与操作系统 我爱生活
我爱生活 小e食堂
小e食堂

