BASIC4MCU | 질문게시판 | 답변 : Atmega128a timer3 compare match 주기 오류
페이지 정보
작성자 master 작성일2022-12-06 10:35 조회304회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=22067
본문
1. main() 함수가 2개씩 있으면 컴파일이 안됩니다.
2. 타이머3 설정에 문제가 있습니다.
3. 외부인터럽트 설정이 안보입니다.//#include <mega128.h>#include <delay.h>//char seg[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};char run=0,led=0,d[4]={0,};int i;//interrupt [EXT_INT0] void ext_int0_isr(void){ run=1; }//interrupt [TIM0_COMP] void timer0_comp_isr(void){ // 1msstatic char c=0;PORTG=0;if(run){PORTD=(seg[d[c]]<<4 )|(PORTD&0x0F);PORTB=(seg[d[c]]&0x70)|(PORTB&0x0F); if(c==0)PORTB|=0x80;PORTG=1<<c;if(++c>3)c=0;}}//interrupt [TIM3_COMPA] void timer3_compa_isr(void){ // 15.84msif(++led>7)led=0; PORTC=~(1<<led);//i=ADCW; i=(int)((float)i*5000.0/1023.0); // mV 값으로 변환d[0]=i/1000; d[1]=i/100%10; d[2]=i/10%10; d[3]=i%10;}//void main(){PORTC=~(1<<led); DDRC=0xFF; DDRB=0xF0; DDRD=0xF0; DDRG=0x0F;ADMUX=0x07; ADCSRA=0xE7;TCCR0=0x0C; OCR0=249; TIMSK=0x02; // 16000000/64/(1+249),1msTCCR3B=0x0A; OCR3AH=31679>>8; OCR3AL=31679&0xFF; ETIMSK=0x10; // 16000000hz/8/31680=63.13131313131313Hz=15.84msEICRB=0xFF; EIMSK=0x20;SREG|=0x80;while(1){}}
댓글 0
조회수 304등록된 댓글이 없습니다.