📄 main.c
字号:
#include "systemInit.h"
#define LED_PERIPH SYSCTL_PERIPH_GPIOD
#define LED_PORT GPIO_PORTD_BASE
#define LED_PIN GPIO_PIN_0
#define Key_PERIPH SYSCTL_PERIPH_GPIOG
#define Key_PORT GPIO_PORTG_BASE
#define Key_PIN GPIO_PIN_5
// 主函数(程序入口)
int main(void)
{
jtagWait(); // 防止JTAG失效,重要!
clockInit(); // 时钟初始化:晶振,6MHz
SysCtlPeriEnable( LED_PERIPH ); //使能外设
GPIOPinTypeOut(LED_PORT, LED_PIN); // 设置LED所在管脚为输出
GPIOPinWrite(LED_PORT, LED_PIN, 0x01);
SysCtlPeriEnable( Key_PERIPH );
GPIOPinTypeIn( Key_PORT, Key_PIN ); // 设置KEY所在管脚为输入
GPIOIntTypeSet( Key_PORT, Key_PIN , GPIO_LOW_LEVEL); // 设置KEY管脚的中断类型
GPIOPinIntEnable(Key_PORT , Key_PIN ); // 使能KEY所在管脚的中断
IntEnable(INT_GPIOG); // 使能GPIOG端口中断
IntMasterEnable(); // 使能处理器中断
for (;;)
{
}
}
void GPIO_Port_G_ISR(void)
{
unsigned long ulStatus;
ulStatus = GPIOPinIntStatus(Key_PORT, true); // 读取中断状态
GPIOPinIntClear( Key_PORT, ulStatus); // 清除中断状态,重要
if (ulStatus & Key_PIN ) // 如果KEY2的中断状态有效
{
for (;;) //LED1以一秒的频率闪烁
{
GPIOPinWrite(LED_PORT, LED_PIN, 0x00); //点亮LED1
SysCtlDelay(1000 * (TheSysClock / 3000)); //延时1秒
GPIOPinWrite(LED_PORT, LED_PIN, 0x01); //熄灭LED1
SysCtlDelay(1000 * (TheSysClock / 3000)); //延时1秒
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -