BASIC4MCU | 질문게시판 | 답변 : atmega 128 질문
페이지 정보
작성자 master 작성일2022-05-31 12:42 조회6,376회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=20258
본문
외부 인터럽트는 누를 때만 1회 실행합니다.
다이나믹 방식의 세그먼트는 계속해서 실행 해야하므로
메인 무한루프에서 세그먼트를 켜세요
난수는 타이머0을 이용해서 만들었습니다.
#include <mega128.h>
#include <delay.h>
//
char seg[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
//
unsigned char num,num1=0,num2=0;
//
interrupt [EXT_INT0] void external_int0(void) {
num=TCNT0;
num1=num/10;
num2=num%10;
}
//
void main(void){
DDRC=0xFF;
DDRA=0x03;
PORTD=0x03;
TCCR0=0x09; OCR0=99; // 0~99 난수 발생용
EICRA=0xAA; EIMSK=0x01; SREG=0x80;
while(1){
PORTC=seg[num1]; PORTA=2; delay_ms(1); PORTA=0;
PORTC=seg[num2]; PORTA=1; delay_ms(1); PORTA=0;
}
}
댓글 0
조회수 6,376등록된 댓글이 없습니다.