⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ff.c

📁 用Atmega16实现中断
💻 C
字号:
//ICC-AVR application builder : 2009-5-19 13:21:53
// Target : M16
// Crystal: 4.0000Mhz

#include <iom16v.h>
#include <macros.h>
flash unsigned char led_7[16]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,
                      0x80,0x90,0x88,0x83,0xC6,0xA1,0x80,0x8E};
unsigned char counter;
void port_init(void)
{
 PORTA = 0xFF;
 DDRA  = 0xFF;
 PORTB = 0xFF;
 DDRB  = 0x00;
 PORTC = 0xFF; //m103 output only
 DDRC  = 0x00;
 PORTD = 0xFF;
 DDRD  = 0x00;
}

#pragma interrupt_handler int0_isr:2
void int0_isr(void)
{
 //external interupt on INT0
 if (++counter>=16) counter = 0;
}

#pragma interrupt_handler int1_isr:3
void int1_isr(void)
{
 //external interupt on INT1
 if (counter) --counter;
	else counter = 15;
}

//call this routine to initialise all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 port_init();

 MCUCR = 0x0A;
 GICR  = 0xC0;
 TIMSK = 0x00; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialised
}
void main(void)
{
 	 PORTA=0xFF;
    DDRA=0xFF;

    GICR|=0xC0;		// 允许INT0、INT1中断
    MCUCR=0x0A;		// INT0、INT1下降沿触发 
    GIFR=0xC0;		// 清除INT0、INT1中断标志位

    counter = 0;	// 计数单元初始化为0	

    //#asm("sei")		// 全局中断允许

	
    while (1)
    {
	 	
      	 PORTA = led_7[counter];		// 显示计数单元
		int0_isr();
		int1_isr();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -