//ICC-AVR application builder : 12/3/04 10:43:32 AM // Target : 2313 // Crystal: 4.0000Mhz #include #include #define FALSE 0 #define TRUE 1 #define RED 0 #define GREEN 1 #define PD_redActivate 1 #define PD_greenActivate 2 #define PD_IRin 0 #define PD_holdHP 3 #define DELAY_LONG 10000 #define DELAY_SHORT 100 #define DELAY_MICRO 1 void port_init(void) { PORTB = 0x00; DDRB = 0xFF; PORTD = 0x7E; DDRD = 0x00; } //call this routine to initialize all peripherals void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts port_init(); MCUCR = 0x00; GIMSK = 0x00; TIMSK = 0x00; SEI(); //re-enable interrupts //all peripherals are now initialized } int team = RED, hp = 2, refresh = FALSE; void play(int pitch, int length); void play_activate(); void play_hit(); void team_selection(); void delay(int delay_type, int length); void team_on(); void team_off(); void hit(); void delay(int delay_type, int length) { int i, j; for (i=0; i2500) hit(); f++; } if (refresh == TRUE) { if (hp == 2) PORTB |= 0b00000110; else { PORTB &= ~BIT(2); PORTB |= BIT(1); } } if (hp == 0) { //dead loop //turn on ONLY team indicator pin (active off) if (team==RED) PORTB = 0b01000000; else PORTB = 0b10000000; //play death music play(100, 3); play(1,1); play(100, 3); play(1,1); play(70, 6); //wait for respawn respawned = FALSE; while (respawned == FALSE) { if (team==RED) if (!(PIND & BIT(PD_redActivate))) //if redActivate is low respawned = TRUE; if (team==GREEN) if (!(PIND & BIT(PD_greenActivate))) respawned = TRUE; } hp = 2; refresh = TRUE; play_activate(); } } } void team_selection() { int exit = FALSE; while (exit==FALSE) { //red on, green off, twiddle speaker PORTB |= BIT(4); PORTB &= ~BIT(5); PORTB ^= BIT(3); delay(DELAY_LONG, 5); //twiddle red, green, speaker //leaves red off, green on PORTB ^= 0b00111000; delay(DELAY_LONG, 5); //yellow, turn red on, twiddle PORTB ^= 0b00011000; delay(DELAY_LONG, 5); //nothing on, so twiddle all PORTB ^= 0b00111000; delay(DELAY_LONG, 5); //check for red activate and admin if (!(PIND & BIT(PD_redActivate)) && !(PIND & BIT(PD_holdHP))) { team = RED; PORTB = 0b01010111; //red (LED and team), active, full HP play_activate(); exit = TRUE; } //check for green activate and admin if (!(PIND & BIT(PD_greenActivate)) && !(PIND & BIT(PD_holdHP))) { team = GREEN; PORTB = 0b10100111; //green (LED and team), active, full HP play_activate(); exit = TRUE; } } } void play_activate() { play(40, 1); play(1, 1); play(50, 1); play(79, 2); } void play(int pitch, int length) { //pitch of 1 = rest int l, p; for (l=0; l0) play_hit(); }