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
blinky.c
Go to the documentation of this file.
1
/*
2
* @brief Blinky example using a timer and interrupt
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
#include <stdio.h>
34
60
/*****************************************************************************
61
* Private types/enumerations/variables
62
****************************************************************************/
63
64
#define TICKRATE1_HZ 10
65
#define TICKRATE2_HZ 7
66
67
/*****************************************************************************
68
* Public types/enumerations/variables
69
****************************************************************************/
70
71
/*****************************************************************************
72
* Private functions
73
****************************************************************************/
74
75
/*****************************************************************************
76
* Public functions
77
****************************************************************************/
78
83
void
TIMER1_IRQHandler
(
void
)
84
{
85
static
bool
On
=
false
;
86
87
if
(
Chip_TIMER_MatchPending
(
LPC_TIMER1
, 1)) {
88
Chip_TIMER_ClearMatch
(
LPC_TIMER1
, 1);
89
On = (bool) !On;
90
Board_LED_Set
(0, On);
91
}
92
}
93
98
void
TIMER2_IRQHandler
(
void
)
99
{
100
static
bool
On
=
false
;
101
102
if
(
Chip_TIMER_MatchPending
(
LPC_TIMER2
, 1)) {
103
Chip_TIMER_ClearMatch
(
LPC_TIMER2
, 1);
104
On = (bool) !On;
105
Board_LED_Set
(1, On);
106
}
107
}
108
113
int
main
(
void
)
114
{
115
uint32_t
timerFreq;
116
117
Board_Init
();
118
119
DEBUGSTR
(
"Blinky example using timers 1 and 2!\r\n"
);
120
121
/* Enable timer 1 clock and get clock rate */
122
Chip_TIMER_Init
(
LPC_TIMER1
);
123
#if defined(CHIP_LPC175X_6X)
124
timerFreq =
Chip_Clock_GetPeripheralClockRate
(SYSCTL_PCLK_TIMER1);
125
#else
126
timerFreq =
Chip_Clock_GetPeripheralClockRate
();
127
#endif
128
129
Chip_TIMER_Reset
(
LPC_TIMER1
);
130
Chip_TIMER_MatchEnableInt
(
LPC_TIMER1
, 1);
131
Chip_TIMER_SetMatch
(
LPC_TIMER1
, 1, (timerFreq /
TICKRATE1_HZ
));
132
Chip_TIMER_ResetOnMatchEnable
(
LPC_TIMER1
, 1);
133
Chip_TIMER_Enable
(
LPC_TIMER1
);
134
135
/* Enable timer interrupt */
136
NVIC_EnableIRQ(TIMER1_IRQn);
137
NVIC_ClearPendingIRQ(TIMER1_IRQn);
138
139
DEBUGOUT
(
"Timer 1 clock = %d Hz\r\n"
, timerFreq);
140
DEBUGOUT
(
"Timer 1 tick rate = %d Hz\r\n"
,
TICKRATE1_HZ
);
141
142
/* Enable timer 2 clock and get clock rate */
143
Chip_TIMER_Init
(
LPC_TIMER2
);
144
#if defined(CHIP_LPC175X_6X)
145
timerFreq =
Chip_Clock_GetPeripheralClockRate
(SYSCTL_PCLK_TIMER2);
146
#else
147
timerFreq =
Chip_Clock_GetPeripheralClockRate
();
148
#endif
149
150
Chip_TIMER_Reset
(
LPC_TIMER2
);
151
Chip_TIMER_MatchEnableInt
(
LPC_TIMER2
, 1);
152
Chip_TIMER_SetMatch
(
LPC_TIMER2
, 1, (timerFreq /
TICKRATE2_HZ
));
153
Chip_TIMER_ResetOnMatchEnable
(
LPC_TIMER2
, 1);
154
Chip_TIMER_Enable
(
LPC_TIMER2
);
155
156
/* Enable timer interrupt */
157
NVIC_EnableIRQ(TIMER2_IRQn);
158
NVIC_ClearPendingIRQ(TIMER2_IRQn);
159
160
DEBUGOUT
(
"Timer 2 clock = %d Hz\r\n"
, timerFreq);
161
DEBUGOUT
(
"Timer 2 tick rate = %d Hz\r\n"
,
TICKRATE2_HZ
);
162
163
while
(1) {
164
__WFI();
165
}
166
}
167
applications
lpc17xx_40xx
examples
periph
periph_blinky
blinky.c
Generated on Fri May 10 2013 10:42:07 for LPCOpen Platform by
1.8.2