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
change_latency.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
Measure latency using change notification.
34
RB2 drives RB3 to generate an CN interrupt.
35
Need to run this with a slow clock to avoid
36
external loading effecting CN triggering point.
37
With FCY = 4 MHz, got 8 FYCs high period, 8 FYCs low period.
38
*/
39
40
//Interrupt Service Routine for Change Notification
41
void
_ISRFAST _CNInterrupt (
void
) {
42
_LATB2 = 0;
//set back low
43
NOP
();
//give the CN time to propagate so
44
NOP
();
//clearing the flag will actually clear it.
45
NOP
();
46
_CNIF = 0;
//clear the change notification interrupt bit
47
}
48
49
int
main
(
void
) {
50
configBasic
(HELLO_MSG);
51
/** PIO ***********/
52
CONFIG_RB2_AS_DIG_OUTPUT();
53
_LATB2 = 0;
54
CONFIG_RB3_AS_DIG_INPUT();
55
ENABLE_RB3_CN_INTERRUPT();
56
/** Configure Change Notification general interrupt */
57
_CNIF = 0;
//Clear the interrupt flag
58
_CNIP = 2;
//Choose a priority
59
_CNIE = 1;
//enable the Change Notification general interrupt
60
while
(1) {
61
_LATB2 = 1;
//trigger interrupt by bringing high
62
NOP
();
//give the CN time to propagate
63
NOP
();
64
}
65
}
Generated by
1.8.4