blinking
[rapper.git] / bitbucket_lpc1768 / main.c
1 /* 
2  * LED blinking example for the mbed LPC1768-based board.
3  *
4  * See also: http://bitbucket.org/jpc/lpc1768/
5  *
6  * Copyright (c) 2010 LoEE - Jakub Piotr Cłapa
7  * This program is released under the new BSD license.
8  */
9 #include "CMSIS/LPC17xx.h"
10 #include "io-pin.h"
11
12 // For mbed-005.1
13 #define LED1 P1+18
14 #define LED2 P1+20
15 #define LED3 P1+21
16 #define LED4 P1+29
17
18 // Helper macros
19 #define LED_ON(i)  (pin_write (LED##i, 1))
20 #define LED_OFF(i) (pin_write (LED##i, 0))
21
22 volatile uint32_t current_time;
23
24 void SysTick_Handler (void)
25 {
26   current_time++;
27 }
28
29 void delay (uint32_t interval)
30 {
31   uint32_t start = current_time;
32   while (current_time - start < interval);
33 }
34
35 int main (void)
36 {
37   // Setup SysTick interrupts at 1kHz (1ms)
38   SysTick_Config (SystemCoreClock / 1000);
39
40   // Configure as output pins.
41   pin_dir (LED1, PIN_OUT);
42   pin_dir (LED2, PIN_OUT);
43   pin_dir (LED3, PIN_OUT);
44   pin_dir (LED4, PIN_OUT);
45
46   // Twinkle!
47   while(1) {
48     LED_OFF(1); delay (120); LED_ON(1);
49     LED_ON(2); delay (120); LED_OFF(2);
50     LED_ON(3); delay (120); LED_OFF(3);
51     LED_ON(4); delay (120); LED_OFF(4);
52     LED_ON(3); delay (120); LED_OFF(3);
53     LED_ON(2); delay (120); LED_OFF(2);
54   }
55 }