PIC24 Support Libraries
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
chap9
int0_bounce.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 int0 interrupt
34
* to detect switch bounce.
35
*
36
*
37
*/
38
39
//Interrupt Service Routine for INT0
40
volatile
uint8_t
u8_bcnt;
41
void
_ISRFAST
_INT0Interrupt
(
void
) {
42
_INT0IF = 0;
//clear the interrupt bit
43
u8_bcnt++;
//increment the bounce count
44
}
45
46
#define SW1 _RB7 //switch state
47
#define SW1_PRESSED() (SW1==0) //switch test
48
#define SW1_RELEASED() (SW1==1) //switch test
49
/// Switch1 configuration, RB7 shares INT0 pin on PIC24HGP202
50
inline
void
CONFIG_SW1
() {
51
CONFIG_RB7_AS_DIG_INPUT();
//use RB7 for switch input
52
ENABLE_RB7_PULLUP();
//enable the pullup
53
}
54
55
56
int
main
(
void
) {
57
uint8_t
u8_cnt;
58
configBasic
(HELLO_MSG);
59
/** Configure the switch ***********/
60
CONFIG_SW1
();
//enables individual CN interrupt also
61
DELAY_US
(1);
62
/** Configure INT0 interrupt */
63
_INT0IF = 0;
//Clear the interrupt flag
64
_INT0IP = 2;
//Choose a priority
65
_INT0EP = 1;
//negative edge triggerred
66
_INT0IE = 1;
//enable INT0 interrupt
67
while
(1) {
68
u8_bcnt = 0;
69
outString
(
"Press & release switch... "
);
70
while
(SW1_RELEASED());
71
DELAY_MS
(
DEBOUNCE_DLY
);
72
while
(SW1_PRESSED());
73
DELAY_MS
(
DEBOUNCE_DLY
);
74
u8_cnt = u8_bcnt;
//copy variable so will not change
75
if
(u8_cnt != 1)
outString
(
"..bounced: "
);
76
else
outString
(
"..no bounce: "
);
77
outUint8
(u8_cnt);
78
outString
(
"\n"
);
79
}
80
}
Generated by
1.8.4