// Copyright (c) 2001-2003 Rowley Associates Limited.
//
// This file may be distributed under the terms of the License Agreement
// provided with this software.
//
// THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
////////////////////////////////////////////////////////////////////////////////
//
//                 Philips LPC210X LED Example
//
// Description
// -----------
// This example demonstrates writing to the GPIO port.
//
// Building and Running
// --------------------
// To run from FLASH:
//   - Set the project configuration to "Flash Debug".
//   - Connect to the target.
//   - Click "Start Debugging" to download and run.
//
// To run from RAM:
//   - Set the project configuration to "RAM Debug".
//   - Connect to the target.
//   - Click "Start Debugging" to download and run.
//
////////////////////////////////////////////////////////////////////////////////

typedef volatile unsigned int *reg32_t;

#define MAMCR (*(reg32_t)0xE01FC000)

#define IOPIN (*(reg32_t)0xE0028000)
#define IOSET (*(reg32_t)0xE0028004)
#define IODIR (*(reg32_t)0xE0028008)
#define IOCLR (*(reg32_t)0xE002800C)
#define IOPINSEL0 (*(reg32_t)0xE002C000)

//GPIO 12
#define LEDMASK   0x1000



static void
ledInit()
{
  IOPINSEL0  = 0x00000000;
  IODIR |= LEDMASK;
  //IOSET |= 0x00001000; //ON LED
}

static void
ledOn(int led)
{
  IOCLR = led;
}

static void
ledOff(int led)
{
  IOSET = led;
}

void
delay(int d)
{
  for(; d; --d);
}

int
main(void)
{
  int i, j;
  MAMCR = 2;
  ledInit();
  while (1)
    {

          ledOn(LEDMASK);
          delay(20000);
          ledOff(LEDMASK);
          delay(20000);
    }
  return 0;
}


