// int1.c
// INT7(interrupt 7)을 이용한 외부 인터럽트 테스트
// INT7 스위치를 누를 때마다 LED를 차례로 켜고
// FND를 차례로 증가시킨다.
#include <avr/io.h>
#include <avr/interrupt.h>
#define FND_ON 0xe3 // PE4=0
unsigned char fnd[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, // 0~4
0x92, 0x82, 0xf8, 0x80, 0x98, // 5~9
0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e}; // AbCdEF
volatile unsigned char int_cnt = 0;
void int_init();
// ISR - Interrupt Service Routine
ISR(INT7_vect) { // SIGNAL(SIG_INTERRUPT7)
int_cnt++;
}
int main(void) {
unsigned char led = 0xfe;
unsigned char bin = 0;
DDRD = 0x0f;
PORTD = 0xff;
DDRA = 0xff;
PORTA = 0xff;
DDRE = 0x3f; // 0011 1111, PE7=0(INT7용 값 입력), PE4=1(FND_ON)
PORTE = FND_ON; // PE4에 0 출력
int_init(); // interrupt 초기화 루틴
sei(); // SREG bit 7을 1로 세팅(Set Enable Interrupt)
while(1) {
if(int_cnt) {
int_cnt = 0;
PORTD = led; // LED 이동
led <<= 1;
led |= 0xf1;
if(led == 0xff)
led = 0xfe;
PORTA = fnd[bin]; // FND 표시
bin++;
if(bin >= 16)
bin = 0;
} // if
} // while
return(0);
} // main
// interrupt 초기화 루틴
void int_init() {
EIMSK = 0x80; // 1000 0000 (Int7을 사용하겠다.)
EICRB = 0Xc0; // 10 00 00 00(falling edge에서 동작하게 해준다.)
// 0x40 : falling/rising edge
// 0x80 : falling edge
// 0xc0 : rising edge
}
// INT7(interrupt 7)을 이용한 외부 인터럽트 테스트
// INT7 스위치를 누를 때마다 LED를 차례로 켜고
// FND를 차례로 증가시킨다.
#include <avr/io.h>
#include <avr/interrupt.h>
#define FND_ON 0xe3 // PE4=0
unsigned char fnd[] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, // 0~4
0x92, 0x82, 0xf8, 0x80, 0x98, // 5~9
0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e}; // AbCdEF
volatile unsigned char int_cnt = 0;
void int_init();
// ISR - Interrupt Service Routine
ISR(INT7_vect) { // SIGNAL(SIG_INTERRUPT7)
int_cnt++;
}
int main(void) {
unsigned char led = 0xfe;
unsigned char bin = 0;
DDRD = 0x0f;
PORTD = 0xff;
DDRA = 0xff;
PORTA = 0xff;
DDRE = 0x3f; // 0011 1111, PE7=0(INT7용 값 입력), PE4=1(FND_ON)
PORTE = FND_ON; // PE4에 0 출력
int_init(); // interrupt 초기화 루틴
sei(); // SREG bit 7을 1로 세팅(Set Enable Interrupt)
while(1) {
if(int_cnt) {
int_cnt = 0;
PORTD = led; // LED 이동
led <<= 1;
led |= 0xf1;
if(led == 0xff)
led = 0xfe;
PORTA = fnd[bin]; // FND 표시
bin++;
if(bin >= 16)
bin = 0;
} // if
} // while
return(0);
} // main
// interrupt 초기화 루틴
void int_init() {
EIMSK = 0x80; // 1000 0000 (Int7을 사용하겠다.)
EICRB = 0Xc0; // 10 00 00 00(falling edge에서 동작하게 해준다.)
// 0x40 : falling/rising edge
// 0x80 : falling edge
// 0xc0 : rising edge
}
댓글 없음:
댓글 쓰기