📄 ff._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]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
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 + -