text: /********************************************************************
   Software License Agreement:
  
   The software supplied herewith by Microchip Technology Incorporated
   (the "Company") for its PIC(R) Microcontroller is intended and
   supplied to you, the Company's customer, for use solely and
   exclusively on Microchip PIC Microcontroller products. The
   software is owned by the Company and/or its supplier, and is
   protected under applicable copyright laws. All rights are reserved.
   Any use in violation of the foregoing restrictions may subject the
   user to criminal sanctions under applicable laws, as well as to
   civil liability for the breach of the terms and conditions of this
   license.
  
   THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
   WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
   TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
   PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
   IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
   CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
   *******************************************************************/
  
  #include <p33EP512MU810.h>
  #include <stdbool.h>
  #include <buttons.h>
  
  /*** Button Definitions *********************************************/
  #define S1_PORT  PORTDbits.RD6
  #define S2_PORT  PORTDbits.RD7
  #define S3_PORT  PORTDbits.RD13
  
  #define S1_TRIS  TRISDbits.TRISD6
  #define S2_TRIS  TRISDbits.TRISD7
  #define S3_TRIS  TRISDbits.TRISD13
  
  #define BUTTON_PRESSED      0
  #define BUTTON_NOT_PRESSED  1
  
  #define PIN_INPUT           1
  #define PIN_OUTPUT          0
  
  #define PIN_DIGITAL         0
  #define PIN_ANALOG          1
  
  #define BUTTON_PRESSED      0
  #define BUTTON_NOT_PRESSED  1
  
  /*********************************************************************
  * Function: bool BUTTON_IsPressed(BUTTON button);
  *
  * Overview: Returns the current state of the requested button
  *
  * PreCondition: button configured via BUTTON_SetConfiguration()
  *
  * Input: BUTTON button - enumeration of the buttons available in
  *        this demo.  They should be meaningful names and not the names 
  *        of the buttons on the silkscreen on the board (as the demo 
  *        code may be ported to other boards).
  *         i.e. - ButtonIsPressed(BUTTON_SEND_MESSAGE);
  *
  * Output: TRUE if pressed; FALSE if not pressed.
  *
  ********************************************************************/
  bool BUTTON_IsPressed(BUTTON button)
  {
      switch(button)
      {
          case BUTTON_S1:
              return ( (S1_PORT == BUTTON_PRESSED) ? true : false);
  
          case BUTTON_S2:
              return ( (S2_PORT == BUTTON_PRESSED) ? true : false);
  
          case BUTTON_S3:
              return ( (S3_PORT == BUTTON_PRESSED) ? true : false);
  
          case BUTTON_NONE:
              return false ;
      }
      
      return false;
  }
  
  /*********************************************************************
  * Function: void BUTTON_Enable(BUTTON button);
  *
  * Overview: Returns the current state of the requested button
  *
  * PreCondition: button configured via BUTTON_SetConfiguration()
  *
  * Input: BUTTON button - enumeration of the buttons available in
  *        this demo.  They should be meaningful names and not the names
  *        of the buttons on the silkscreen on the board (as the demo
  *        code may be ported to other boards).
  *         i.e. - ButtonIsPressed(BUTTON_SEND_MESSAGE);
  *
  * Output: None
  *
  ********************************************************************/
  void BUTTON_Enable(BUTTON button)
  {
      switch(button)
      {
          case BUTTON_S1:
              S1_TRIS = PIN_INPUT;
              break;
  
          case BUTTON_S2:
              S2_TRIS = PIN_INPUT;
              break;
  
          case BUTTON_S3:
              S3_TRIS = PIN_INPUT;
              break;
  
          case BUTTON_NONE:
              break ;
      }
  }
  