LPCOpen Platform
v1.03
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Modules
Data Structures
Files
Related Pages
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
acmp.c
Go to the documentation of this file.
1
/*
2
* @brief Analog Comparator example.
3
*
4
* @note
5
* Copyright(C) NXP Semiconductors, 2012
6
* All rights reserved.
7
*
8
* @par
9
* Software that is described herein is for illustrative purposes only
10
* which provides customers with programming information regarding the
11
* LPC products. This software is supplied "AS IS" without any warranties of
12
* any kind, and NXP Semiconductors and its licensor disclaim any and
13
* all warranties, express or implied, including all implied warranties of
14
* merchantability, fitness for a particular purpose and non-infringement of
15
* intellectual property rights. NXP Semiconductors assumes no responsibility
16
* or liability for the use of the software, conveys no license or rights under any
17
* patent, copyright, mask work right, or any other intellectual property rights in
18
* or to any products. NXP Semiconductors reserves the right to make changes
19
* in the software without notification. NXP Semiconductors also makes no
20
* representation or warranty that such application will be suitable for the
21
* specified use without further testing or modification.
22
*
23
* @par
24
* Permission to use, copy, modify, and distribute this software and its
25
* documentation is hereby granted, under NXP Semiconductors' and its
26
* licensor's relevant copyrights in the software, without fee, provided that it
27
* is used in conjunction with NXP Semiconductors microcontrollers. This
28
* copyright, permission, and disclaimer notice must appear in all copies of
29
* this code.
30
*/
31
32
#include "board.h"
33
63
/*****************************************************************************
64
* Private types/enumerations/variables
65
****************************************************************************/
66
67
/*****************************************************************************
68
* Public types/enumerations/variables
69
****************************************************************************/
70
71
/*****************************************************************************
72
* Private functions
73
****************************************************************************/
74
75
/*****************************************************************************
76
* Public functions
77
****************************************************************************/
78
83
void
CMP_IRQHandler
(
void
)
84
{
85
/* Clear the interrupt */
86
Chip_ACMP_EdgeClear
(
LPC_CMP
);
87
88
__SEV();
89
}
90
95
void
HW_Setup
(
void
)
96
{
97
/* initialize the board */
98
Board_Init
();
99
100
/* initialize the ACMP */
101
Chip_ACMP_Init
(
LPC_CMP
);
102
103
/* Enable the clock to the Switch Matrix */
104
Chip_Clock_EnablePeriphClock
(
SYSCTL_CLOCK_SWM
);
105
106
/* Configure the SWM for ACMP_I1 as the input for the Analog Comparator. */
107
Chip_SWM_FixedPinEnable
(
ACMP_I1
,
ENABLE
);
108
109
/* Set the LPC8XX_ACMP_O_PINx (in sys_config.h) pin direction as an output. */
110
Chip_GPIO_SetDir
(
LPC_GPIO_PORT
, 0,
LPC8XX_ACMP_O_PINx
, 1);
111
112
/* Configure the SWM for PIO15 as the output for the comparator. */
113
Chip_SWM_MovablePinAssign
(
SWM_ACMP_O_O
,
PIO15
);
114
115
/* Positive and negative references, both edges, no hysteresis */
116
Chip_ACMP_SetupAMCPRefs
(
LPC_CMP
,
ACMP_EDGESEL_BOTH
,
ACMP_POSIN_ACMP_I1
,
ACMP_NEGIN_INT_REF
,
ACMP_HYS_NONE
);
117
118
/* Disable the clock to the Switch Matrix to save power */
119
Chip_Clock_DisablePeriphClock
(
SYSCTL_CLOCK_SWM
);
120
121
/* Enable the Interrupt for the compare output */
122
NVIC_EnableIRQ(CMP_IRQn);
123
}
124
129
int
main
(
void
)
130
{
131
/* Board and hardware setup */
132
HW_Setup
();
133
134
while
(1) {
135
/* Enter low power mode until interrupt */
136
__WFE();
137
138
if
(
Chip_ACMP_GetCompStatus
(
LPC_CMP
) &
ACMP_COMPSTAT_BIT
) {
139
Board_LED_Set
(0,
false
);
140
}
141
else
{
142
Board_LED_Set
(0,
true
);
143
}
144
}
145
146
return
0;
147
}
148
applications
lpc8xx
examples
periph
periph_acmp
acmp.c
Generated on Fri May 10 2013 10:42:08 for LPCOpen Platform by
1.8.2