📄 main.c
字号:
#include "system.h"
#include "led.h"
#include "rtc.h"
#include "interrupts.h"
#include <inarm.h>
// IRQ 中断句柄
#pragma vector=0x18
__irq __arm void IRQ_ISR_Handler (void) {
void (*interrupt_function)();
unsigned int vector;
vector = VICVectAddr; // 获取中断向量
interrupt_function = (void(*)())vector;
(*interrupt_function)(); // 调用向量中断函数
VICVectAddr = 0; // 清除VIC中断
}
// FIQ 中断句柄
#pragma vector=0x1c
__fiq __arm void FIQ_ISR_Handler (void) {
void (*interrupt_function)();
unsigned int vector;
vector = VICVectAddr; // 获取中断向量
interrupt_function = (void(*)())vector;
(*interrupt_function)(); // 调用向量中断函数
VICVectAddr = 0; // 清除VIC中断
}
void EINT0Interrupt() { // 外部中断EINT0服务,分配给按键2
while((EXTINT & 0x01) != 0) {
LedBlink(); // LED闪动
EXTINT = 0x01; // 清除外部中断EINT0标志
}
}
void EINT2Interrupt() { // 外部中断EINT2服务,分配给按键1
LedOn(); // 电亮LED
EXTINT = 0x04; // 清除外部中断EINT2标志
}
void RTCInterrupt() {
LedOn(); // 电亮LED
Delay(300000); // 延时
LedOff(); // 熄灭LED
ILR=0x3; // 清除所有RTC中断
}
int main() {
/* 检测连接器命令文件是否将中断向量安装在0地址,若是则将MEMMAP设为1,使程序从FLASH运行 */
#pragma segment = "INTVEC"
if (( void * )0x00000000UL == __segment_begin( "INTVEC" )) {
MEMMAP = 1; // 正常FLASH模式
}
else {
MEMMAP = 2 ; // 用户RAM模式-将最低64字节地址空间映射到内部RAM底部,并将异常向量映射到此处
}
PINSEL0_bit.P0_15=0x2; // 引脚P0.15配置为外部中断EINT2,按键1
PINSEL1_bit.P0_16=0x1; // 引脚P0.15配置为外部中断EINT0,按键2
FrecInit(); // 频率初始化
LedInit(); // LED初始化
InitRTC(); // RTC初始化
/**** 中断设置 ****/
__disable_interrupt(); // 关中断
InitRTCInterrupt(); // 设置RTC中断
InitEINT2Interrupt(); // 设置外中断EINT2
InitEINT0Interrupt(); // 设置外中断EINT0
__enable_interrupt(); // 开中断
while(1){
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -