📄 ex412.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzhou ZHIYUAN electronics Co.,LTD.
**
** http://www.embedtools.com
**
**--------------File Info-------------------------------------------------------------------------------
** File Name: ex412.c
** Last modified Date: 2006-11-15
** Last Version: v1.0
** Description: 扫描按键是否按下,如果按键按下则点亮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 "gpio.h"
#include "sysctl.h"
#include "systick.h"
#define KEY1 GPIO_PIN_1 //定义KEY1
#define LED1 GPIO_PIN_4 //定义LED1
void delay(unsigned long d)
{
for(;d;d--);
}
//-----------------------------------------------------------------------------
// 函数原形: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);
while (1)
{
// 读KEY1引脚的值,并判断,如果为高,则熄灭LED1
if(GPIOPinRead(GPIO_PORTB_BASE, KEY1))
{
GPIOPinWrite(GPIO_PORTB_BASE, LED1, LED1);
}
// 否则点亮LED1
else
{
GPIOPinWrite(GPIO_PORTB_BASE, LED1, ~LED1);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -