⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 led.c

📁 using GCC complier for ARM LPC2106
💻 C
字号:
// 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 NUM_LEDS 8

static int leds[] = { 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000};

static void
ledInit()
{
  IODIR |= 0x0000FF00;
  IOSET = 0x0000FF00;
}

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)
    {
      for (i = 0; i < NUM_LEDS; ++i)
        {
          ledOn(leds[i]);
          delay(20000);
        }
      for (i = 0; i < NUM_LEDS; ++i)
        {
          ledOff(leds[i]);
          delay(20000);
        }
      for (i = NUM_LEDS - 1; i >= 0; --i)
        {
          ledOn(leds[i]);
          delay(20000);
        }
      for (i = NUM_LEDS - 1; i >= 0; --i)
        {
          ledOff(leds[i]);
          delay(20000);
        }

    }
  return 0;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -