BASIC4MCU | 질문게시판 | atmega128 버저 추가
페이지 정보
작성자 초보중에최고 작성일2022-11-24 00:46 조회1,039회 댓글0건본문
항상 바쁘신데 감사합니다. 처음에 만들었던 코드는 스위츠를 누르면 시간도 돌아가지 않아서 다시 짜고 있는데 도움이 필요합니다. 10초에 도달했을때 부저가 1초정도 울리는 것을 목적으로 만들고 있는 코드입니다. 7-SEG는 문제없이 돌아가나 부저가 울리지 않아서 도움을 요청합니다.
#include <avr/io.h>
#define F_CPU 16000000UL
#include <util/delay.h>
#include <avr/interrupt.h>
unsigned char fnd[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x27,0x7F,0x6F};
unsigned char fnd_sel[4] = {0x01, 0x02,0x04,0x08};
unsigned char fnd_set[4];
unsigned int time_count=0;
unsigned char int4_sw=0,fnd_sw=0;
volatile char play=0;
volatile int tone;
void fnd_digit(int count){
int i;
char f_table[1]={17};
int song[]={DDO,EOS};
fnd_set[0]=count%10;
fnd_set[1]=(count/10)%10;
fnd_set[2]=(count/100)%10;
fnd_set[3]=(count/1000)%10;
for(i=0;i<4;i++){
PORTG=fnd_sel[i];
PORTC=fnd[fnd_set[i]];
if(i==2) PORTC|=0x80;
_delay_ms(2.5);
}
}
ISR(SIG_INTERRUPT4){
switch(int4_sw){
case 0 :
fnd_sw=1;//count 카운트 시작
int4_sw=1;
break;
case 1 :
fnd_sw=0;//카운트 정지
int4_sw=0;
break;
}
}
ISR(SIG_INTERRUPT5){
time_count=0;
fnd_sw=0;
int4_sw=0;
}
int main(){
DDRB=0x01;
DDRG=0x0F;
DDRC=0xFF;
EIMSK=1<<INT4 | 1<<INT5;
EICRB=0x0A;
sei();
while(1){
fnd_digit(time_count);
(fnd_sw == 0)? : time_count++;
if(time_count==10000) time_count=0;
}
return 0;
}
while(fnd_set[]==10)
DDRB |=0x01;
_delay(50)
댓글 0
조회수 1,039등록된 댓글이 없습니다.