/* Team 2 Board Program This program is the "brains" of our self-scoring bean bag toss game. This program incorporates the sensor system with the team scores display as well as the games won display. It has wireless code that communicates with the Zigbee part. It also has code that accomodates the reset button. One goal of this program is to have the boards keep track of the score and games won without having to reset the game until two new teams want to start a game. EESDlib contains all of the functions and EESD.h is the header file. */ #include #include "EESD.h" #pragma DATA _CONFIG1H, _OSC_INTIO67_1H #pragma DATA _CONFIG2H, _WDT_OFF_2H #pragma DATA _CONFIG4L, _LVP_OFF_4L #pragma DATA _CONFIG3H, _MCLRE_ON_3H #pragma CLOCK_FREQ 8000000 bool gameisnotover = 1; bool sflag1 = 1; // Sensor 1 flag bool sflag2 = 1; // Sensor 2 flag bool sflag3 = 1; // Sensor 3 flag bool sflag4 = 1; // Sensor 4 flag bool sflag5 = 1; // Sensor 5 flag bool sflag6 = 1; // Sensor 6 flag bool reset = 1; void main(void) { osccon = 0x72; delay_s(1); // SPI Initialization trisc.5 = 0; //Make it an output (Enables SDO) trisc.3 = 0; //Make it an output (Enables SCK) trisd.3 = 0; //Make it an output (load CS for LED maxim) trisd.4 = 0; //Make it an output (load CS for SEVEN maxim) sspcon1 = 0x22; //Control Register (SPI MODE) //Master Synchronous Seial Port Enable, enables serial port and configures SCK, SDO, SDI, and invSS as serial port pins. //SPI Master Mode clock = Fosc/64 sspstat = 0x40; //Status Register (SPI MODE) CKE Trasmit occurs on transition from active to idle clock state. //Zigbee Initialization Serial_init(); // Initializes UART for Zigbee transmission interrupt_init(); // Initializes interrupt function // Phototransistor Initialization trisb |= 00000001b; // Photo1 input B1 trisb |= 00000010b; // Photo2 input B2 trisb |= 00000011b; // Photo3 input B3 trisb |= 00000100b; // Photo4 input B4 trisb |= 00000101b; // Photo5 input B5 trisa |= 00000001b; // Photo6 input A1 volatile bit data1; // Assigns variables to photo inputs volatile bit data2; volatile bit data3; volatile bit data4; volatile bit data5; volatile bit data6; data1 = portb.1; data2 = portb.2; data3 = portb.3; data4 = portb.4; data5 = portb.5; data6 = porta.1; // Sets Games Won flag to 0 for start of game int team1_gw = 0; int team2_gw = 0; reset = 1; LED_maxim_init(); SEVEN_maxim_init(); while(reset) // While game has not been reset { // LED Initialization //Initialize maxim with set registers. //bounce_blink(); // All holes blink at same time signaling new game delay_ms(100); blink1(); all_on1(); delay_ms(100); blink2(); all_on2(); delay_ms(100); blink3(); all_on3(); delay_ms(100); blink4(); all_on4(); delay_ms(100); blink5(); all_on5(); delay_ms(100); blink6(); all_on6(); // Seven Segment Display Initialization int score_val1 = 0; // Sets team 1 score value to 0 at beginning of each game int score_val2 = 0; // Sets team 1 score value to 0 at beginning of each game // Display Team Scores and Games Won on 7 segment scoreboards score1(score_val1); LCD_init(); LCD_printf("Score 1"); delay_s(1); LCD_clear(); score2(score_val2); LCD_init(); LCD_printf("Score 2"); delay_s(1); LCD_clear(); gameswon1(team1_gw); gameswon2(team2_gw); // Flag Initialization gameisnotover = 1; // Flag that game is not over sflag1 = 1; // Sensor 1 flag sflag2 = 1; // Sensor 2 flag sflag3 = 1; // Sensor 3 flag sflag4 = 1; // Sensor 4 flag sflag5 = 1; // Sensor 5 flag sflag6 = 1; // Sensor 6 flag while(gameisnotover) // While the particular game is not over... { LCD_init(); LCD_printf("Game is starting"); delay_s(1); LCD_clear(); data1 = portb.1; data2 = portb.2; data3 = portb.3; data4 = portb.4; data5 = portb.5; data6 = porta.1; if(sflag1==0 && sflag2==0 && sflag3==0 && sflag4==0 && sflag5 ==0 && sflag6==0) // If all holes have been hit... { Send_Zigbee(7); // Send that game is over to the other board through Zigbee //LCD_init(); //LCD_printf("Game is over"); delay_s(1); //LCD_clear(); team2_gw = team2_gw + 1; // Increase Team 2 games won value if(team2_gw == 10) // If Team 2 has won 10 games, will go back to 0 on games won scoreboard { team2_gw = 0; } gameswon2(team2_gw); // Display new Team 2 games won value on scoreboard Send_Zigbee(team2_gw+10); // Display new Team 2 games won value on other board gameisnotover = 0; // Game is over sflag1 = 0; sflag2 = 0; sflag3 = 0; sflag4 = 0; sflag5 = 0; sflag6 = 0; delay_ms(100); bounce_blink(); // Blink lights } if(sflag1 == 1) // If the hole 1 has not been hit.. { if(data1 == 0) // If hole 1 is not covered { //LCD_init(); //LCD_printf("Pin 1 Not Covered"); delay_ms(250); //LCD_clear(); data1 = portb.1; } else // Hole is covered { //LCD_printf("Pin 1 Covered"); delay_ms(250); //LCD_clear(); delay_ms(100); blink1(); // Blink lights delay_ms(100); //all_off1(); // Turn off lights score_val2 = score_val2 + 1; // Increse Team 2 score by 1 score2(score_val2); // Output new Team 2 score on 7 seg display //LCD_init(); //LCD_printf("Score 2"); delay_s(1); //LCD_clear(); Send_Zigbee(score_val2); // Send score on Zigbee to other board delay_s(1); //LCD_clear(); data1 = portb.1; sflag1 = 0; // Turn sensor 1 flag off } } if(sflag2 == 1) // If hole 2 has not been hit { if(data2 == 0) // If hole 2 is not covered { //LCD_printf("Pin 2 Not Covered"); delay_ms(250); //LCD_clear(); data2 = portb.2; } else // Hole 2 is covered { //LCD_printf("Pin 2 Covered"); delay_ms(250); //LCD_clear(); delay_ms(100); blink2(); // Blink LEDs delay_ms(100); //all_off2(); // Turn LEDs off score_val2 = score_val2 + 1; // Increase score value by 1 for Team 2 score2(score_val2); // Output new Team 2 score on 7 seg display //LCD_init(); //LCD_printf("Score 2"); delay_s(1); //LCD_clear(); Send_Zigbee(score_val2); // Send score on Zigbee to other board delay_s(1); //LCD_clear(); data2 = portb.2; sflag2 = 0; } } if(sflag3 == 1) // If hole 3 has not been hit { if(data3 == 0) // If hole 3 is not covered { //LCD_printf("Pin 3 Not Covered"); delay_ms(250); //LCD_clear(); data3 = portb.3; } else // Hole 3 is covered { //LCD_printf("Pin 3 Covered"); delay_ms(250); //LCD_clear(); delay_ms(100); blink3(); // Blink LEDs delay_ms(100); //all_off3(); // Turn LEDs off score_val2 = score_val2 + 1; // Increase score value by 1 for Team 2 score2(score_val2); // Output new Team 2 score on 7 seg display //LCD_init(); //LCD_printf("Score 2"); delay_s(1); //LCD_clear(); Send_Zigbee(score_val2); // Send score on Zigbee to other board delay_s(1); //LCD_clear(); data3 = portb.3; sflag3 = 0; } } if(sflag4 == 1) // If hole 4 has not been hit { if(data4 == 0) // If hole 4 is not covered { //LCD_printf("Pin 4 Not Covered"); delay_ms(250); //LCD_clear(); data4 = portb.4; } else // Hole 4 is covered { //LCD_printf("Pin 4 Covered"); delay_ms(250); //LCD_clear(); delay_ms(100); blink4(); // Blink LEDs delay_ms(100); //all_off4(); // Turn LEDs off score_val2 = score_val2 + 1; // Increase score value by 1 for Team 2 score2(score_val2); // Output new Team 2 score on 7 seg display //LCD_init(); //LCD_printf("Score 2"); delay_s(1); //LCD_clear(); Send_Zigbee(score_val2); // Send score on Zigbee to other board delay_s(1); LCD_clear(); data4 = portb.4; sflag4 = 0; } } if(sflag5 == 1) // If hole 5 has not been hit { if(data5 == 0) // If hole 5 is not covered { //LCD_printf("Pin 5 Not Covered"); delay_ms(250); //LCD_clear(); data5 = portb.5; } else // Hole 5 is covered { //LCD_printf("Pin 5 Covered"); delay_ms(250); // LCD_clear(); delay_ms(100); blink5(); // Blink LEDs delay_ms(100); //all_off5(); // Turn LEDs off score_val2 = score_val2 + 1; // Increase score value by 1 for Team 2 score2(score_val2); // Output new Team 2 score on 7 seg display //LCD_init(); //LCD_printf("Score 2"); delay_s(1); //LCD_clear(); Send_Zigbee(score_val2); // Send score on Zigbee to other board delay_s(1); //LCD_clear(); data5 = portb.5; sflag5 = 0; } } if(sflag6 == 1) // If hole 6 has not been hit { if(data6 == 0) // If hole 6 is not covered { //LCD_printf("Pin 5 Not Covered"); delay_ms(250); //LCD_clear(); data6 = porta.1; } else // Hole 6 is covered { //LCD_printf("Pin 6 Covered"); delay_ms(250); //LCD_clear(); delay_ms(100); blink6(); // Blink LEDs delay_ms(100); //all_off6(); // Turn LEDs off score_val2 = score_val2 + 1; // Increase score value by 1 for Team 2 score2(score_val2); // Output new Team 2 score on 7 seg display //LCD_init(); //LCD_printf("Score 2"); delay_s(1); //LCD_clear(); Send_Zigbee(score_val1); // Send score on Zigbee to other board delay_s(1); //LCD_clear(); data6 = porta.1; sflag6 = 0; } } } } //delay_s(2); }