1 ////////////////////////////////////////////////////////////////////////////////
3 // Philips LPC210X interrupt use example
7 // This example demonstrates
8 //version 1.0 15/08/2005
9 //Author : Guillaume LAGARRIGUE
10 ////////////////////////////////////////////////////////////////////////////////
19 static int leds[] = { 0x10000, 0x20000, 0x40000, 0x80000 };
23 /*////////////////////////////////////////////////////////INITIALISATION FUNCTIONS///////////////////////////////////*/
27 * Function Name: lowInit()
30 * This function starts up the PLL then sets up the GPIO pins before
31 * waiting for the PLL to lock. It finally engages the PLL and
41 static void lowInit(void)
43 // set PLL multiplier & divisor.
44 // values computed from config.h
45 PLLCFG = PLLCFG_MSEL | PLLCFG_PSEL;
49 PLLFEED = 0xAA; // Make it happen. These two updates
50 PLLFEED = 0x55; // MUST occur in sequence.
52 // setup the parallel port pin
53 IOCLR = PIO_ZERO_BITS; // clear the ZEROs output
54 IOSET = PIO_ONE_BITS; // set the ONEs output
55 IODIR = PIO_OUTPUT_BITS; // set the output bit direction
58 while (!(PLLSTAT & PLLSTAT_LOCK))
61 // enable & connect PLL
62 PLLCON = PLLCON_PLLE | PLLCON_PLLC;
63 PLLFEED = 0xAA; // Make it happen. These two updates
64 PLLFEED = 0x55; // MUST occur in sequence.
66 // setup & enable the MAM
67 MAMTIM = MAMTIM_CYCLES;
70 // set the peripheral bus speed
71 // value computed from config.h
72 VPBDIV = VPBDIV_VALUE; // set the peripheral bus clock speed
77 * Function Name: sysInit()
80 * This function is responsible for initializing the program
90 static void sysInit(void)
92 lowInit(); // setup clocks and processor port pins
94 MEMMAP = 1; // map interrupt vectors space into FLASH
96 //MEMMAP = 1; // map interrupt vectors space into FLASH
97 MEMMAP = 0x2; /** user RAM mode **/
101 /*////////////////////////////LEDS INITIALISATION///////////////////////*/
106 static void ledInit()
108 IODIR |= 0x000F0000; /*leds connected to P0.16 17 18 & 19 should blink*/
109 IOSET = 0x00000000; /* all leds are switched off */
113 * Switches the leds off.
114 * @param led switched off led number. (integer)
116 static void ledOff(int led) /* Ioclr.i =1 => IOset.i cleared */
122 * Switches the leds on.
123 * @param led switched on led number. (integer)
125 static void ledOn(int led) /* Ioset.i = 1 => P0.i = 1 */
133 * @param d duration (unit not defined yet)
140 for (i = 0; i < 10; i++)
148 * Switches on and off the 4 leds one after one:
150 * A led is switched on when an interrupt occurs
151 * then switched off when the next interrupt occurs
154 void timer0_isr(void) __attribute__ ((interrupt));
159 void timer0_isr(void)
164 ledOn(leds[led_num]);
171 ledOff(leds[led_num]);
177 if (led_num == NUM_LEDS)
182 T0IR |= 0x00000001; // Clear match0 interrupt
183 VICVectAddr = 0x00000000;
190 * initializes timer T0 to raise an interrupt and to reset T0counter when it matches T0MatchRegister0
193 static void Init_timer(void)
195 VICVectAddr0 = (unsigned)timer0_isr; /* Set the ISR vector address vector0 = highest priority */
196 VICVectCntl0 = 0x20|4; /* Enable this vector and assign Timer IRQ to it */
197 VICIntEnable = 0x00000010; /* Enable the interrupt of timer0*/
200 T0MR0 = 0x0010000; //Match 0 control register = 65536
201 T0MCR = 0x3; //resets timer0 and generates interrupt when timer0 counter match MR0 register
203 T0TCR = 0x3; //Reset timer 0
214 T0TCR = 0x01; //Run timer 0
216 while(1) //infinite loop