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.
   *******************************************************************/
  
  /*
  
  This license is compatible with above license, when using this code with any
  Microchip microcontoller/signal processor. This project is designed for using it
  with Microchip controller product. If you want to change microcontrollers in
  your project, you can use all files except controller source code (with
  "Generated" keyword) - please write your own code for your own platform, and
  don't use code generator code (by the way - will Microchip code run on
  STM? ;> ).
  
  The MIT License (MIT)
  
  Copyright (c) 2015 Sławomir Kozok
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
  
  */
  
  #include <xc.h>
  #include <stdbool.h>
  #include <buttons.h>
  
  /*** Button Definitions *********************************************/
  //      S1  is MCLR button
  #define S3_PORT  PORTDbits.RD6
  #define S6_PORT  PORTDbits.RD7
  #define S5_PORT  PORTAbits.RA7       //Overlaps with D10
  #define S4_PORT  PORTDbits.RD13
  
  #define S3_TRIS  TRISDbits.TRISD6
  #define S6_TRIS  TRISDbits.TRISD7
  #define S5_TRIS  TRISAbits.TRISA7
  #define S4_TRIS  TRISDbits.TRISD13
  
  #define S3_ANSEL ANSELDbits.ANSD6
  #define S6_ANSEL ANSELDbits.ANSD7
  #define S5_ANSEL ANSELAbits.ANSA7
  
  #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
  
  /*********************************************************************
   * 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_S3:
              return ( ( S3_PORT == BUTTON_PRESSED ) ? true : false ) ;
  
          case BUTTON_S6:
              return ( ( S6_PORT == BUTTON_PRESSED ) ? true : false ) ;
  
          case BUTTON_S5:
              return ( ( S5_PORT == BUTTON_PRESSED ) ? true : false ) ;
  
          case BUTTON_S4:
              return ( ( S4_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_S3:
              S3_TRIS = PIN_INPUT ;
              S3_ANSEL = PIN_DIGITAL ;
              break ;
  
          case BUTTON_S6:
              S6_TRIS = PIN_INPUT ;
              S6_ANSEL = PIN_DIGITAL ;
              break ;
  
          case BUTTON_S5:
              S5_TRIS = PIN_INPUT ;
              S5_ANSEL = PIN_DIGITAL ;
              break ;
  
          case BUTTON_S4:
              S4_TRIS = PIN_INPUT ;
              break ;
  
          case BUTTON_NONE:
              break ;
      }*/
  }
  