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 00039 //Interrupt Service Routine for INT0 00040 volatile uint8 u8_bcnt; 00041 void _ISRFAST _INT0Interrupt (void) { 00042 _INT0IF = 0; //clear the interrupt bit 00043 u8_bcnt++; //increment the bounce count 00044 } 00045 00046 #define SW1 _RB7 //switch state 00047 #define SW1_PRESSED() SW1==0 //switch test 00048 #define SW1_RELEASED() SW1==1 //switch test 00050 inline void CONFIG_SW1() { 00051 CONFIG_RB7_AS_DIG_INPUT(); //use RB7 for switch input 00052 ENABLE_RB7_PULLUP(); //enable the pullup 00053 } 00054 00055 00056 int main (void) { 00057 uint8 u8_cnt; 00058 configBasic(HELLO_MSG); 00060 CONFIG_SW1(); //enables individual CN interrupt also 00061 DELAY_US(1); 00063 _INT0IF = 0; //Clear the interrupt flag 00064 _INT0IP = 2; //Choose a priority 00065 _INT0EP = 1; //negative edge triggerred 00066 _INT0IE = 1; //enable INT0 interrupt 00067 while (1) { 00068 u8_bcnt = 0; 00069 outString("Press & release switch... "); 00070 while (SW1_RELEASED()); 00071 DELAY_MS(DEBOUNCE_DLY); 00072 while (SW1_PRESSED()); 00073 DELAY_MS(DEBOUNCE_DLY); 00074 u8_cnt = u8_bcnt; //copy variable so will not change 00075 if (u8_cnt != 1) outString("..bounced: "); 00076 else outString("..no bounce: "); 00077 outUint8(u8_cnt); 00078 outString("\n"); 00079 } 00080 }