将函数声明为interrupt并包含相应的头文件
示例代码:
在main.c文件中:
#include
#include "interrupts.h"
int main(void)
{
//使能中断
sei();
while(1)
{
//循环
}
return 0;
}
在interrupts.h文件中:
#ifndef INTERRUPTS_H
#define INTERRUPTS_H
//中断函数声明
ISR(TIMER1_OVF_vect);
#endif
在interrupts.c文件中:
#include
#include "interrupts.h"
//定时器1溢出中断
ISR(TIMER1_OVF_vect)
{
//中断函数的具体实现
}