首页资源分类嵌入式系统 > LPC4357学习笔记-GPIO

LPC4357学习笔记-GPIO

已有 445005个资源

下载专区

文档信息举报收藏

标    签:LPC4357GPIO

分    享:

文档简介

LPC4357学习笔记-GPIO

文档预览

LPC4357学习笔记-GPIO 作者:BLUEFLAME 20140403 见手册UM10503-Rev. 1.8 — 28 January 2014 GPIO 以下n=0~7 CTRL----------GPIO 分组中断控制寄存器 PORT_POLn-----GPIO 分组中断端口n极性寄存器 PORT_ENAn-----GPIO 分组中断端口n使能寄存器 DIRn-----------方向寄存器端口n MASKn----------掩码寄存器端口n PINn-----------端口引脚寄存器端口n MPINn----------掩码后端口寄存器端口n SETn-----------写入:端口n的设置寄存器 读:端口n的输出位 CLRn-----------清除端口n NOTn-----------切换端口n 初始化GPIO步骤如下 1.使能GPIO时钟,并等待为使能 UM10503 P197有解释 /* Clock Control Unit register bits */ #define CCU_CLK_CFG_RUN (1 << 0)//运行使能 #define CCU_CLK_CFG_AUTO (1 << 1)//自动(AHB禁用机制)使能 #define CCU_CLK_STAT_RUN (1 << 0)//运行使能状态 LPC_CCU1->CLK_M4_GPIO_CFG = CCU_CLK_CFG_AUTO | CCU_CLK_CFG_RUN;//设置GPIO时钟 while (!(LPC_CCU1->CLK_M4_GPIO_STAT & CCU_CLK_STAT_RUN));//读取GPIO运行时钟状态,并等待 /* Clock Control Unit register bits */ 2.设置GPIO功能模式,有两种方法可以设置,分别如下 A直接设置GPIO管脚地址: LPC_SCU->SFSPD_10 = 4; /* GPIO6[24] */ LPC_SCU->SFSPD_11 = 4; /* GPIO6[25] */ LPC_SCU->SFSPD_12 = 4; /* GPIO6[26] */ LPC_SCU->SFSPD_13 = 4; /* GPIO6[27] */ LPC_SCU->SFSPD_14 = 4; /* GPIO6[28] */ B使用库的方法设置: /* *函数原型:void scu_pinmux(uint8_t port, uint8_t pin, uint8_t mode, uint8_t func) *函数在库:"lpc43xx_scu.c"和"lpc43xx_scu.h" */ scu_pinmux(0xD,10, MD_PUP, FUNC4);//GPIO6[24] scu_pinmux(0xD,11, MD_PUP, FUNC4);//GPIO6[25] scu_pinmux(0xD,12, MD_PUP, FUNC4);//GPIO6[26] scu_pinmux(0xD,13, MD_PUP, FUNC4);//GPIO6[27] scu_pinmux(0xD,14, MD_PUP, FUNC4);//GPIO6[28] 3.设置GPIO输入输出模式: A输出模式: LPC_GPIO_PORT->DIR[6] |=( 1UL << 24 //GPIO6[24] |1UL << 25 //GPIO6[25] |1UL << 26 //GPIO6[26] |1UL << 27 //GPIO6[27] |1UL << 28);//GPIO6[28] B输入模式: LPC_GPIO_PORT->DIR[6] ~=( 1UL << 24 //GPIO6[24] &1UL << 25 //GPIO6[25] &1UL << 26 //GPIO6[26] &1UL << 27 //GPIO6[27] &1UL << 28);//GPIO6[28] C操作库函数: void GPIO_SetDir(uint8_t portNum, uint32_t bitValue, uint8_t dir) portNum:管脚号 到此GPIO作为出入输出的设置完毕,下面是操作GPIO 1.输出模式输出高电平 A直接操作寄存器: LPC_GPIO_PORT->SET[6] = 1UL << 24; //GPIO6[24] LPC_GPIO_PORT->SET[6] = 1UL << 25; //GPIO6[25] LPC_GPIO_PORT->SET[6] = 1UL << 26; //GPIO6[26] LPC_GPIO_PORT->SET[6] = 1UL << 27; //GPIO6[27] LPC_GPIO_PORT->SET[6] = 1UL << 28; //GPIO6[28] B操作库函数: GPIO_SetValue(6, 1UL << 24); //GPIO6[24] GPIO_SetValue(6, 1UL << 25); //GPIO6[25] GPIO_SetValue(6, 1UL << 26); //GPIO6[26] GPIO_SetValue(6, 1UL << 27); //GPIO6[27] GPIO_SetValue(6, 1UL << 28); //GPIO6[28] C操作PIN寄存器 LPC_GPIO_PORT->PIN[6] &= ~(1UL << 24); //GPIO6[24] LPC_GPIO_PORT->PIN[6] &= ~(1UL << 25); //GPIO6[25] LPC_GPIO_PORT->PIN[6] &= ~(1UL << 26); //GPIO6[26] LPC_GPIO_PORT->PIN[6] &= ~(1UL << 27); //GPIO6[27] LPC_GPIO_PORT->PIN[6] &= ~(1UL << 28); //GPIO6[28] 2.输出模式输出低电平 A直接操作寄存器: LPC_GPIO_PORT->CLR[6] = 1UL << 24; //GPIO6[24] LPC_GPIO_PORT->CLR[6] = 1UL << 25; //GPIO6[25] LPC_GPIO_PORT->CLR[6] = 1UL << 26; //GPIO6[26] LPC_GPIO_PORT->CLR[6] = 1UL << 27; //GPIO6[27] LPC_GPIO_PORT->CLR[6] = 1UL << 28; //GPIO6[28] B操作库函数: GPIO_ClearValue(6, 1UL << 24); //GPIO6[24] GPIO_ClearValue(6, 1UL << 25); //GPIO6[25] GPIO_ClearValue(6, 1UL << 26); //GPIO6[26] GPIO_ClearValue(6, 1UL << 27); //GPIO6[27] GPIO_ClearValue(6, 1UL << 28); //GPIO6[28] C操作PIN寄存器 LPC_GPIO_PORT->PIN[6] |= 1UL << 24; //GPIO6[24] LPC_GPIO_PORT->PIN[6] |= 1UL << 25; //GPIO6[25] LPC_GPIO_PORT->PIN[6] |= 1UL << 26; //GPIO6[26] LPC_GPIO_PORT->PIN[6] |= 1UL << 27; //GPIO6[27] LPC_GPIO_PORT->PIN[6] |= 1UL << 28; //GPIO6[28] PGIO输入模式 1.初始化 /* Enable clock and init GPIO outputs */ LPC_CCU1->CLK_M4_GPIO_CFG = CCU_CLK_CFG_AUTO | CCU_CLK_CFG_RUN;////使能GPIO时钟UM10503 P197有解释 while (!(LPC_CCU1->CLK_M4_GPIO_STAT & CCU_CLK_STAT_RUN));//等待GPIO时钟状态为使能 LPC_SCU->SFSPC_9 = (1 << 6) | 4; LPC_SCU->SFSPC_11 = (1 << 6) | 4; LPC_SCU->SFSPC_12 = (1 << 6) | 4; LPC_SCU->SFSPC_13 = (1 << 6) | 4; LPC_SCU->SFSPC_14 = (1 << 6) | 4; LPC_GPIO_PORT->DIR[6] &= ~(1 << 8 );//P6.8 LPC_GPIO_PORT->DIR[6] &= ~(1 << 10);//P6.10 LPC_GPIO_PORT->DIR[6] &= ~(1 << 11);//P6.11 LPC_GPIO_PORT->DIR[6] &= ~(1 << 12);//P6.12 LPC_GPIO_PORT->DIR[6] &= ~(1 << 13);//P6.13 2.读取按键状态 if (!(LPC_GPIO_PORT->PIN[6] & (1 << 8 ))) {}//读取P6.8 if (!(LPC_GPIO_PORT->PIN[6] & (1 << 10))) {}//读取P6.10 if (!(LPC_GPIO_PORT->PIN[6] & (1 << 11))) {}//读取P6.11 if (!(LPC_GPIO_PORT->PIN[6] & (1 << 12))) {}//读取P6.12 if (!(LPC_GPIO_PORT->PIN[6] & (1 << 13))) {}//读取P6.13 //----------------------------------------------------------------------------//

Top_arrow
回到顶部
EEWORLD下载中心所有资源均来自网友分享,如有侵权,请发送举报邮件到客服邮箱bbs_service@eeworld.com.cn 或通过站内短信息或QQ:273568022联系管理员 高员外,我们会尽快处理。