/*****************************************************
*********        Game Initialization       ***********
*********  ME 218A - Aut 2007 - Project    ***********
******************************************************/

#include <stdio.h>
#include <ME218_C32.h>
#include <timers12.h>
#include "PWMS12.h"
#include "IO_Definitions.h"
#include "Constants.h"
#include "ConfigureInitialize.h"
#include "ADS12.h" 


void GameConfigure(void) 
{
    char state;
/* I/O configuration */

  /* Port M */
     DDRM = 0xFF & COINSENSOR_INPUT & PLYR_GOAL_INPUT & OPP_GOAL_INPUT;
     

  /* Port T */
     DDRT = ALL_OUTPUTS;        // All outputs
     PTT = ALL_ZERO | PLAYER_SCORE | COMPUTER_SCORE | GOALIE_ON; // Initialize to 0

  /* Port AD */
     if (ADS12_Init(AD_IO) != ADS12_OK) 
          printf("Error configuring AD");
  
  /* Initialize Scoreboard */
     InitializeScoreboard();		// sets the IO for the scoreboard, as well as the initial display
      
/* Initialize timer and pulse width modules */ 
     TMRS12_Init(TMR_SPEED);
     PWMS12_Init();
     
     PWMS12_SetPeriod(PWMS12_2000US, PWMS12_GRP0);     
     state = PWMS12_SetDuty(0, PWMS12_CHAN0);
     
     TMRS12_InitTimer(GOALIE_TIMER, GOALIE_CHANGE_TIME);
     TMRS12_StartTimer(GOALIE_TIMER);
}
     
