답변 : 외부인터럽트와 타이머/카운터 인터럽트를 이용 응용 프로그램 작성
페이지 정보
작성자 master 작성일18-06-29 23:26 조회3,932회 댓글0건본문
// MCU BASIC: https://www.basic4mcu.com
// DateTime : 2018-06-29 오후 11:29:30
// by Ok-Hyun Park
//
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
//
char seg[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x27,0x7f,0x6f,0x77,0x7c,0x58,0x5e,0x79,0x71,0};
int n=0;
//
ISR(INT4_vect){
PORTA<<=1; if(PORTA==0)PORTA=0x01;
}
//
ISR(INT5_vect){
PORTA>>=1; if(PORTA==0)PORTA=0x80;
}
//
ISR(INT6_vect){
if(++n>9999)n=0;
}
//
ISR(INT7_vect){
if(--n<0)n=9999;
}
//
ISR(TIMER0_COMP_vect){ // 1ms
static char cnt=0;
PORTG=0; // common off
switch(cnt){
case 0: PORTC=n/1000; break;
case 1: PORTC=n/100%10; break;
case 2: PORTC=n/10 %10; break;
case 3: PORTC=n %10; break;
}
PORTG=1<<cnt; // common on
if(++cnt>3)cnt=0;
}
//
int main(void){
DDRA=0xFF; DDRC=0xFF; DDRG=0x0F;
TCCR0=0x0C; OCR0=249; TIMSK=2; //16000000/ 64/(1+249)=1000Hz=1ms
EICRB=0xAA; EIMSK=0xF0;
sei();
while(1){}
}
댓글 : 0
조회수 : 3,932
등록된 댓글이 없습니다.