1 | //*****************************************************************************
|
2 | // +--+
|
3 | // | ++----+
|
4 | // +-++ |
|
5 | // | |
|
6 | // +-+--+ |
|
7 | // | +--+--+
|
8 | // +----+ Copyright (c) 2010-11 Code Red Technologies Ltd.
|
9 | //
|
10 | // LED flashing Timer16 application for LPCXPresso1114 board
|
11 | //
|
12 | // Software License Agreement
|
13 | //
|
14 | // The software is owned by Code Red Technologies and/or its suppliers, and is
|
15 | // protected under applicable copyright laws. All rights are reserved. Any
|
16 | // use in violation of the foregoing restrictions may subject the user to criminal
|
17 | // sanctions under applicable laws, as well as to civil liability for the breach
|
18 | // of the terms and conditions of this license.
|
19 | //
|
20 | // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
|
21 | // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
|
22 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
|
23 | // USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT
|
24 | // TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH
|
25 | // CODE RED TECHNOLOGIES LTD.
|
26 | //
|
27 | //*****************************************************************************
|
28 |
|
29 |
|
30 | #include "LPC11xx.h" /* LPC11xx definitions */
|
31 | #include "timer16.h"
|
32 | #include "clkconfig.h"
|
33 | #include "gpio.h"
|
34 |
|
35 | #include <cr_section_macros.h>
|
36 | #include <NXP/crp.h>
|
37 |
|
38 | // Variable to store CRP value in. Will be placed automatically
|
39 | // by the linker when "Enable Code Read Protect" selected.
|
40 | // See crp.h header for more information
|
41 | __CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
|
42 |
|
43 | // LPCXpresso processor card LED
|
44 | #define LED_PORT 0 // Port for led
|
45 | #define LED_BIT 7 // Bit on port for led
|
46 | #define LED_ON 1 // Level to set port to turn on led
|
47 | #define LED_OFF 0 // Level to set port to turn off led
|
48 |
|
49 | extern volatile uint32_t timer16_0_counter;
|
50 |
|
51 | int main (void)
|
52 | {
|
53 | GPIOInit();
|
54 |
|
55 | // Initialise Timer16_0 to tick at rate of 1/2000th of second.
|
56 | // Note that as this is a 16 bit timer, the maximum count we can
|
57 | // load into timer is 0xFFFF, or 65535. Default clock speed
|
58 | // set up by CMSIS SystemInit function - SystemCoreClock - is
|
59 | // 48MHz or 48000000 Hz. Dividing this by 2000 is 24000 which is
|
60 | // within appropriate timer16 maximum. This could be extended
|
61 | // if timer routine extended to make use of Prescale Counter register
|
62 | // Note by default LPC_SYSCON->SYSAHBCLKDIV is 1.
|
63 | init_timer16(0, (SystemCoreClock/LPC_SYSCON->SYSAHBCLKDIV)/2000 );
|
64 |
|
65 | // Initialise counter that counts Timer16_0 ticks
|
66 | timer16_0_counter = 0;
|
67 |
|
68 | //Enable Timer16_0
|
69 | enable_timer16(0);
|
70 |
|
71 | // Set port for LED to output
|
72 | GPIOSetDir( LED_PORT, LED_BIT, 1 );
|
73 | GPIOSetDir( 0, 10, 1 ); // Set PORT0 direction Bit10 to output
|
74 |
|
75 | while (1) /* Loop forever */
|
76 | {
|
77 |
|
78 | // LED is on for 1st half-second
|
79 | if ( (timer16_0_counter > 0) && (timer16_0_counter <= 1000) )
|
80 | {
|
81 | GPIOSetValue( LED_PORT, LED_BIT, LED_OFF );
|
82 | GPIOSetValue(0,10,1); // PORT0 Bit10 High
|
83 | }
|
84 |
|
85 | // LED is off for 2nd half-second
|
86 | if ( (timer16_0_counter > 1000) && (timer16_0_counter <= 2000) )
|
87 | {
|
88 | GPIOSetValue( LED_PORT, LED_BIT, LED_ON );
|
89 | GPIOSetValue(0,10,0); // PORT0 Bit10 Low
|
90 | }
|
91 |
|
92 | // Reset counter
|
93 | else if ( timer16_0_counter > 2000 )
|
94 | {
|
95 | timer16_0_counter = 0;
|
96 | }
|
97 | }
|
98 | }
|