00001 /* 00002 * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")" 00003 * All rights reserved. 00004 * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University) 00005 * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University) 00006 * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University) 00007 * 00008 * Permission to use, copy, modify, and distribute this software and its 00009 * documentation for any purpose, without fee, and without written agreement is 00010 * hereby granted, provided that the above copyright notice, the following 00011 * two paragraphs and the authors appear in all copies of this software. 00012 * 00013 * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR 00014 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 00015 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS" 00016 * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00017 * 00018 * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES, 00019 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00020 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 00021 * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO 00022 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 00023 * 00024 * Please maintain this header in its entirety when copying/modifying 00025 * these files. 00026 * 00027 * 00028 */ 00029 00030 #include "pic24_all.h" 00031 00037 volatile uint8 bcnt; 00038 //Interrupt Service Routine for Change Notification 00039 void _ISRFAST _CNInterrupt (void) { 00040 _CNIF = 0; //clear the change notification interrupt bit 00041 bcnt++; //increment the bounce count 00042 } 00043 00044 00045 #define SW1 _RB13 //switch state 00046 #define SW1_PRESSED() SW1==0 //switch test 00047 #define SW1_RELEASED() SW1==1 //switch test 00049 inline void CONFIG_SW1() { 00050 CONFIG_RB13_AS_DIG_INPUT(); //use RB13 for switch input 00051 ENABLE_RB13_PULLUP(); //enable the pullup 00052 ENABLE_RB13_CN_INTERRUPT(); //CN13IE = 1 00053 } 00054 00055 int main (void) { 00056 configBasic(HELLO_MSG); 00058 CONFIG_SW1(); //enables individual CN interrupt also 00060 _CNIF = 0; //Clear the interrupt flag 00061 _CNIP = 2; //Choose a priority 00062 _CNIE = 1; //enable the Change Notification general interrupt 00063 while (1) { 00064 bcnt = 0; 00065 outString("Press & release switch... "); 00066 while (SW1_RELEASED()); 00067 DELAY_MS(DEBOUNCE_DLY ); 00068 while (SW1_PRESSED()); 00069 DELAY_MS(DEBOUNCE_DLY ); 00070 if (bcnt != 2) outString("..bounced: "); 00071 else outString("..no bounce: "); 00072 outUint8(bcnt); 00073 outString("\n"); 00074 } 00075 }