BASIC4MCU | 질문게시판 | atmega128 fnd 인터럽트
페이지 정보
작성자 rhdefdl 작성일2023-04-07 00:40 조회886회 댓글1건본문
메인 프로그램이 시작되면 fnd 가장 오른쪽이 0이 표시된 상태로 있다가 int4번이 실행되면 숫자가 1씩 증가하고 int5는 10씩 증가, int6은 100씩 증가 마지막 int7은 표시된 숫자에서 1씩 0.01초 속도로 감소하여 0이 되면 멈추는 프로그램을 짜봤는데 실행이 안됩니다. 어느부분을 수정해야 할까요? isr의 4줄은 바운싱을 잡기위해 설정해두었습니다.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 16000000UL
#include <util/delay.h>
#define IDLE 0
volatile int count = 0;
volatile int state = IDLE;
unsigned char digit[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67};
unsigned char fnd_sel[4] = {0x01,0x02,0x04};
ISR(INT4_vect)
{
_delay_ms(100);
if((PINE&0x10)==0X10)
return;
EIFR |= 1<<4;
count++;
}
ISR(INT5_vect)
{
_delay_ms(100);
if((PINE&0x20)==0X20)
return;
EIFR |= 1<<5;
count = count+10;
}
ISR(INT6_vect)
{
_delay_ms(100);
if((PINE&0x40)==0X40)
return;
EIFR |= 2<<6;
count = count+100;
}
ISR(INT7_vect)
{
_delay_ms(100);
if((PINE&0x80)==0X80)
return;
EIFR |= 1<<7;
count--;
_delay_ms(10);
}
void init_stopwatch(void);
void display_fnd(int);
int main(void)
{
init_stopwatch();
while (1)
{
if(state == IDLE)
{
PORTC = 0X3F; PORTG = 0X01;
}
else
{
display_fnd(count);
}
if (count == 1000)
count = 0;
}
}
void init_stopwatch(void)
{
DDRC = 0XFF;
DDRG = 0X0F;
DDRE = 0X00;
sei();
EICRB = 0XAA;
EIMSK = 0XF0;
}
void display_fnd(int count)
{
int i,fnd[3];
fnd[2] = (count/100)%10;
fnd[1] = (count/10)%10;
fnd[0] = count%10;
for(i=0;i<3;i++)
{
PORTC=digit[fnd[i]];
PORTG=fnd_sel[i];
_delay_ms(100);
}
}
댓글 1
조회수 886master님의 댓글
master 작성일
https://cafe.naver.com/circuitsmanual/221584
이 답글을 실행 해보세요