📄 ex413.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info-------------------------------------------------------------------------------
** File Name: ex413.c
** Last modified Date: 2006-11-15
** Last Version: v1.0
** Description: 程序正常运行时,熄灭LED指示灯。当按键按下时,触发中断,点亮LED指示
** 灯。按键放开后,又熄灭LED指示灯。
**
**------------------------------------------------------------------------------------------------------
** Created By: Yang Li
** Created date: 2006-11-15
** Version: v1.0
** Descriptions:
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Description:
**
********************************************************************************************************/
#include "hw_memmap.h"
#include "hw_types.h"
#include "hw_ints.h"
#include "gpio.h"
#include "interrupt.h"
#include "sysctl.h"
#include "systick.h"
#define KEY1 GPIO_PIN_1 //定义KEY1
#define LED1 GPIO_PIN_4 //定义LED1
//-----------------------------------------------------------------------------
// 函数原形:void GPIO_Port_B_ISR(void)
// 功能描述:首先清除中断标志,再点亮LED1。
// 参数说明:无
// 返回值:无
//-----------------------------------------------------------------------------
void GPIO_Port_B_ISR(void)
{
GPIOPinIntClear(GPIO_PORTB_BASE, KEY1); //清除中断标志
GPIOPinWrite(GPIO_PORTB_BASE, LED1, ~LED1); //点亮LED1
}
//-----------------------------------------------------------------------------
// 函数原形:int main(void)
// 功能描述:主函数
// 参数说明:无
// 返回值:0
//-----------------------------------------------------------------------------
int main(void)
{
// 使能GPIO PB口
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
// 设置连接KEY1的PB1为输入
GPIODirModeSet(GPIO_PORTB_BASE, KEY1, GPIO_DIR_MODE_IN);
// 设置连接LED1的PB4为输出
GPIODirModeSet(GPIO_PORTB_BASE, LED1, GPIO_DIR_MODE_OUT);
// 设置KEY1中断的触发方式为低电平触发
GPIOIntTypeSet(GPIO_PORTB_BASE, KEY1, GPIO_LOW_LEVEL);
// 使能KEY1中断
GPIOPinIntEnable(GPIO_PORTB_BASE, KEY1);
// 使能GPIO B 口中断
IntEnable(INT_GPIOB);
while (1)
{
// 熄灭LED1
GPIOPinWrite(GPIO_PORTB_BASE, LED1, LED1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -