#include <stdio.h>
#include <timers12.h>
#include <ME218_C32.h>

/*********Module Variables*******/
#define NO_EVENT      0
#define COIN_EVENT    1

/********Module Functions********/
void InitCoinSensor(char coin_line);
char CheckCoinEvent(void);

static char COIN_PORT;

/*************************************
Function:     InitCoinSensor(char coin_line)
Description:  Initializes coin-sensing port
Input:        char coin_line, which designates port for sensing coin
Output:       None
Revised:      PY        11/7/07
***************************************/
void InitCoinSensor(char coin_line)
{
  PTT = PTT & ~coin_line;  // Set coin_line to input
  DDRT &= (~coin_line);
  COIN_PORT = coin_line;
}

/**************************************
Function:     CheckCoinEvent(void)
Description:  Checks whether a coin has been inserted
Input:        None
Output:       char, which reports whether a coin event occurred
Revised:      PY        11/7/07
****************************************/
char CheckCoinEvent(void)
{
  char coin;
  coin = PTT & COIN_PORT;  
  //printf("Coin: %d\r\n",coin);
  if (coin != 0)
  {
    return COIN_EVENT;    
  } 
  else
  {
    return NO_EVENT;
  }
}