You are on page 1of 2

Electronic dice: #include <mega16.h> #include <delay.h> #define on 1 #define sw PINB.0 #define D1 PORTC.0 #define D2 PORTC.1 #define D3 PORTC.

2 #define D4 PORTC.3 #define D5 PORTC.4 #define D6 PORTC.5 #define D7 PORTC.6 void main(void) { int DICE=0; DDRB=0x00; DDRC=0Xff; PORTC=0x00; DDRD=0xff; PORTD=0x00; while(1) { if(sw==1) { switch(DICE) { case 1:D4=on; break; case 2:D3=on; D5=on;

break; case 3:D3=on; D4=on; D5=on; break; case 4:D1=on; D2=on; D6=on; D7=on; break; case 5:D4=on; D1=on; D6=on; D2=on; D7=on; break; case 6:D3=on; D1=on; D2=on; D6=on; D7=on; D5=on; break; } delay_ms(100); PORTC=0x00; } else { DICE++; PORTD=DICE; PORTC=0x00; if(DICE==7) DICE=1; }}}

You might also like