You are on page 1of 3

#include <mega8.

h>
#include <delay.h>
//-------------------7seg------------------------------#define set PORTD
//-------------------enable----------------------------#define enable1 PORTC.2
#define enable2 PORTC.3
#define enable3 PORTC.4
#define enable4 PORTC.5
//-------------------tombol---------------------------#define tombol1 PINB.1
#define tombol2 PINB.3
//-------------------kondisi--------------------------#define mati 1
#define nyala 0
unsigned char x=5,a ,y,detik,sat_mnt,pul_mnt,sat_jam,pul_jam,hit[10]={0b01111111
, 0b00011100, 0b10111011, 0b10111110, 0b11011100, 0b11101110, 0b11100111, 0b0011
1100, 0b11111111, 0b11111110}; //common katoda
void rolling()
{
enable4=1;enable1=0;
set=hit[sat_mnt];
delay_ms(x);
if(sat_mnt>9){sat_mnt=0;pul_mnt++;}
enable1=1;enable2=0;
set=hit[pul_mnt];
delay_ms(x);
if(pul_mnt>5){pul_mnt=0;sat_jam++;}
enable2=1;enable3=0;
set=hit[sat_jam];
delay_ms(x);
if(sat_jam>9){sat_jam=0;pul_jam++;}
enable3=1; enable4=0;
set=hit[pul_jam];
delay_ms(x);
if(pul_jam>=4&&sat_jam==2){sat_jam=0;pul_jam=0;}
}
void setting()
{
while(1)
{
if (tombol1==0)
{
delay_ms(200);
while(tombol1==0);
a++;
if(a==1)
{ for(;;)
{
enable4=1;enable1=0;;set=hit[sat_mnt];
if(tombol2==0){ delay_ms(200); while(tombol2==0);sa
t_mnt++;if(sat_mnt>9)sat_mnt=0;}
else if(tombol1==0){break;};
};
}
else if(a==2)
{ for(;;)
{

enable1=1;enable2=0;;set=hit[pul_mnt];
if(tombol2==0){ delay_ms(200); while(tombol2==0);pu
l_mnt++;if(pul_mnt>5)pul_mnt=0;}
else if(tombol1==0){break;};
};
}
else if(a==3)
{ for(;;)
{
enable2=1;enable3=0;;set=hit[sat_jam];
if(tombol2==0){ delay_ms(200); while(tombol2==0);sa
t_jam++;if(sat_jam>9)sat_jam=0;}
else if(tombol1==0){break;};
};
}
else if(a==4)
{ for(;;)
{
enable3=1; enable4=0;;set=hit[pul_jam];
if(tombol2==0){delay_ms(200); while(tombol2==0);pul_
jam++;if(pul_jam>2)pul_jam=0;}
else if(tombol1==0){break;};
};
}
else if(a>4){a=0;goto lanjut;};
}
else if(a==0)break;
}
lanjut:
}
void jalan()
{
for (detik=1;detik<60;detik++)
{
DDRB.4=DDRB.5=1;
PORTB.5=1;
PORTB.4=1;
for (y=0;y<=24;y++)
{
rolling();
setting();
};
PORTB.4=0;
PORTB.5=0;
for (y=0;y<=24;y++)
{
rolling();
setting();
};
};
sat_mnt++;
}

void main(void)
{
PORTB=0xFF;
DDRB=0x00;
PORTC=0xFF;
DDRC=0xFF;
PORTD=0x00;
DDRD=0xFF;
set=hit[0];
delay_ms(10);
while(1)
{ jalan(); }
}