BASIC4MCU | 질문게시판 | ATmega128 FND 도움 부탁드립니다
페이지 정보
작성자 아트메가128 작성일2020-12-11 18:22 조회4,349회 댓글1건본문
. Sw0누르면 FND에 “0”이 SW1을 누르면 “1” 표시되고 해서 Sw7=>”7”이 표 시되는 프로그램을 작성할려고 하는데 도움 부탁드립니다
#define SW0 PINC.0
#define SW1 PINC.1
#define SW2 PINC.2
// FND Data '0' '1' ‘2' '3' '4' '5' '6' '7'
'8' '9'
unsigned char fnd[10]={0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xd8, 0x80, 0x98};
int count = 0;
void UpCnt(void)-
{
count++;
if(count > 9)
count = 0;
}
void DownCnt(void)
{
count--;
if(count < 0)
count = 9;
}
void main(void)
{
PORTA=0xFF; DDRA=0xFF;
PORTC=0xFF; DDRC=0x00;
PORTA= fnd[0];
while(1)
{
if(SW0 == 0) // 스위치 SW0 ON?
{
delay_ms(1);
while(SW0 != 1)
{
delay_ms(1);
}
UpCnt();
PORTA = fnd[count];
}
if(SW1 == 0)
{
delay_ms(1);
while(SW1 != 1)
{
delay_ms(1);
}
DownCnt();
PORTA = fnd[count];
}
if(SW2 == 0)
{
delay_ms(1);
while(SW2 != 1)
{
delay_ms(1);
}
count = 0;
PORTA = fnd[count];
}
} // while
}
댓글 1
조회수 4,349master님의 댓글
master 작성일
//
char count=0,fnd[10]={0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xd8, 0x80, 0x98};
//
void main(void){
DDRA=0xFF;
PORTC=0xFF;
while(1){
PORTA=fnd[count];
if(!PINC.0)count=1;
if(!PINC.1)count=2;
if(!PINC.2)count=3;
if(!PINC.3)count=4;
if(!PINC.4)count=5;
if(!PINC.5)count=6;
if(!PINC.6)count=7;
if(!PINC.7)count=8;
}
}