BASIC4MCU | 질문게시판 | atmega 128 질문
페이지 정보
작성자 샬라랍빵 작성일2022-05-30 14:13 조회1,755회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=20245
본문
인터럽트 스위치를 이용해서 난수를 표현하고자 합니다.
다음과 같이 코드를 짰는데 num1은 잠깐 출력되었다가 사라지고 num2만 출력됩니다.
혹시 어디에 문제가 있는지 알 수 있을까요.
#include <mega128.h>
#include <delay.h>
#include <stdlib.h>
char seg_pat[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
unsigned int num1=0, num2=0;
void main(void)
{
DDRC=0b11111111;
DDRA=0b00000011;
DDRD=0b00000000;
PORTA=0b0000011;
EIMSK=0b00000001;
EICRA=0b00000010;
SREG=0b10000000;
while (1);
}
interrupt [EXT_INT0] void external_int0(void) {
num1=(char)(rand()%10);
num2=(char)(rand()%10);
PORTA=0b0000010;
PORTC=seg_pat[num1];
delay_ms(10);
PORTA=0b0000001;
PORTC=seg_pat[num2];
delay_ms(10);
}
댓글 0
조회수 1,755등록된 댓글이 없습니다.