demo_7_1.c~

来自「AVR单片机嵌入式系统原理与应用实践例码」· C~ 代码 · 共 46 行

C~
46
字号
/*********************************************
File name			: Demo_7_1.c
Chip type           : ATmega16
Program type        : Application
Clock frequency     : 4.000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*********************************************/
#include <mega16.h>

flash char led_7[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
                      0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
char counter;

// INT0中断服务程序
interrupt [EXT_INT0] void ext_int0_isr(void)
{
	if (++counter>=16) counter = 0;
}

// INT1中断服务程序
interrupt [EXT_INT1] void ext_int1_isr(void)
{
	if (counter) --counter;
	else counter = 15;
}

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];		// 显示计数单元
    }
}

⌨️ 快捷键说明

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