专注电子技术学习与研究
当前位置:单片机教程网 >> MCU设计实例 >> 浏览文章

各种单片机中断程序的写法

作者:刘大允   来源:本站原创   点击数:  更新时间:2014年03月25日   【字体:

 

////////////////////    下面是PIC单片机中断的写法!///////////////////////////////////////////////////////////

#include<pic.h>
__CONFIG(0x1832); //写配置位
volatile char i; //中断用到的变量须要用volatile修饰一下

void main()
{

}

void interrupt tt() //中断服务程序,不用申明
{

}

//////////////////////////////////////////   下面AVR单片机GCC中断程序的写法     /////////////////////////////////////////////

#include<avr/io.h>
#include<avr/interrupt.h>
volatile char i; //中断用到的变量须要用volatile修饰一下

int main(void) //GCC编写的主函数是要用int型的函数
{
    sei(); //开总中断
}

SIGNAL(SIG_INTERRUPT0) //外部中断0
{

}
SIGNAL(SIG__INTERRUPT1) //外部中断1
{

}
SIGNAL(SIG_OVERFLOW1) //定时器1溢出中断
{

}

SIGNAL(SIG_ADC)//ADC中断的

{

}

///////////////////////////////////      下面是AVR单片机的ICC中断程序写法!///////////////////////////////////////////////////

#include<iom16v.h>
volatile char i; //中断用到的变量须要用volatile修饰一下
#pragma interrupt_handler miao:9
#pragma data:code
const  table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,
             0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

void main()
{
   SREG|=(1<<7); //开总中断
}

void miao() //中断服务程序
{

}
 

关闭窗口

相关文章