#include "LPC122x.h"                           // LPC122x definitions

volatile long SysTickCnt;                      // System Tick Counter (each 10 msec)

void SysTick_Handler (void)
{
    SysTickCnt++;
}

void delay (long tick)                         // delay function
{
  long cnt;

    cnt = SysTickCnt;
    while ((SysTickCnt - cnt) < tick) ;
}

int main (void)
{
	  SysTick_Config(SystemCoreClock/100);       // generate IRQ each 10 ms

    LPC_SYSCON->SYSAHBCLKCTRL |= (1UL << 31) | // enable clock for GPIO0
                                 (1UL << 16);  // enable clock for IOCON

    LPC_GPIO0->DIR |= (1 << 23);               // configure P0.23 (LED1) as output

    while (1) {                                // loop forever
        LPC_GPIO0->CLR = 1 << 23;              // turn on LED1
        delay(20);
        LPC_GPIO0->SET = 1 << 23;              // turn off LED1
        delay(20);
    }
}
