📄 iar-
字号:
/****************************************Copyright (c)****************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info---------------------------------------------------------------------------------
** File Name: GPIO_IN_OUT.c
** Last modified Date: 2007.12.24
** Last Version: V1.1
** Description: Stellaris系列单片机GPIO口操作
**
**--------------------------------------------------------------------------------------------------------
** Created By: Zhou Hai Xin
** Created date: 2007.09.20
** Version: V1.0
** Descriptions: 扫描按键是否按下,如果按键按下则点亮LED指示灯,否则熄灭LED指示灯。
**
**--------------------------------------------------------------------------------------------------------
** Modified by: Kang qinhua
** Modified date: 2008.01.12
** Version: V1.1
** Description:
**
*********************************************************************************************************/
#include "hw_memmap.h"
#include "hw_types.h"
#include "gpio.h"
#include "sysctl.h"
#include "systick.h"
#define KEY1 GPIO_PIN_2 /* 定义KEY1 */
#define LED3 GPIO_PIN_6 /* 定义LED3 */
/*********************************************************************************************************
** Function name: main
** Descriptions: 通过判断KEY1有没有按下,按下则点亮LED3,否则熄灭LED3。
** input parameters: NONE
** output parameters: NONE
** Returned value: NONE
** Created By: Zhou Hai Xin
** Created date: 2007.09.20
**--------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**--------------------------------------------------------------------------------------------------------
*********************************************************************************************************/
int main(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); /* 使能GPIO PB口 */
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); /* 使能GPIO PE口 */
GPIODirModeSet(GPIO_PORTE_BASE, KEY1, GPIO_DIR_MODE_IN); /* 设置连接KEY1的PD4为输入 */
GPIODirModeSet(GPIO_PORTB_BASE, LED3, GPIO_DIR_MODE_OUT); /* 设置连接LED3的PD7为输出 */
GPIOPadConfigSet(GPIO_PORTE_BASE, KEY1, /* 设置KEY1强度和类型 */
GPIO_STRENGTH_4MA, /* 4mA的输出驱动强度 */
GPIO_PIN_TYPE_STD); /* 设置为推挽管脚 */
GPIOPadConfigSet(GPIO_PORTB_BASE, LED3, /* 设置LED3的驱动强度和类型 */
GPIO_STRENGTH_4MA, /* 4mA的输出驱动强度 */
GPIO_PIN_TYPE_STD); /* 设置为推挽管脚 */
while (1) {
if (GPIOPinRead(GPIO_PORTE_BASE, KEY1)) { /*读KEY1引脚的值,并判断, */
/* 如果为高,则熄灭LED3 */
GPIOPinWrite(GPIO_PORTB_BASE, LED3, LED3);
} else { /* 否则点亮LED3 */
GPIOPinWrite(GPIO_PORTB_BASE, LED3, ~LED3);
}
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -