PIC24 Support Libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
int1_wakeup.c
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
3  * All rights reserved.
4  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
5  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
6  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without written agreement is
10  * hereby granted, provided that the above copyright notice, the following
11  * two paragraphs and the authors appear in all copies of this software.
12  *
13  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
15  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
16  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
23  *
24  * Please maintain this header in its entirety when copying/modifying
25  * these files.
26  *
27  *
28  */
29 
30 #include "pic24_all.h"
31 
32 /** \file
33  * Demonstrates the use of int1 interrupt
34  * to wake from Sleep mode.
35  * Pushbutton on a int1 pin is used to wake from Sleep mode.
36  *
37  *
38  */
39 
40 //Interrupt Service Routine for INT1
41 void _ISRFAST _INT1Interrupt (void) {
42  _INT1IF = 0; //clear the interrupt bit
43 }
44 /// Switch1 configuration, use RB13
45 inline void CONFIG_SW1() {
46  CONFIG_RB13_AS_DIG_INPUT(); //use RB13 for switch input
47  ENABLE_RB13_PULLUP(); //enable the pullup
48  DELAY_US(1); // Wait for pull-up
49 }
50 int main (void) {
51  configBasic(HELLO_MSG);
52  /** Configure the switch ***********/
53  CONFIG_SW1();
54 #if (defined(__dsPIC33E__) || defined(__PIC24E__))
55  CONFIG_INT1_TO_RP(45); //RPI45 shares RB13 pin on these families
56 #else
57  CONFIG_INT1_TO_RP(13); //RP13 shares RB13 pin
58 #endif
59  /** Configure INT1 interrupt */
60  _INT1IF = 0; //Clear the interrupt flag
61  _INT1IP = 2; //Choose a priority
62  _INT1EP = 1; //negative edge triggerred
63  _INT1IE = 1; //enable INT1 interrupt
64  while (1) {
65  outString("Entering Sleep mode, press button to wake.\n");
66  //finish sending characters before sleeping
68  SLEEP(); //macro for asm("pwrsav #0")
69  }
70 }