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

📄 main.c

📁 这是一个关于LPC2468芯片的IAR环境下的按键测试例程源代码
💻 C
字号:

#include <iolpc2468.h>
#include "type.h"
#include "irq.h"
#include "target.h"

volatile DWORD eint0_counter;
int InitialBoard()
{
  DWORD MValue, NValue;
  // pll
  if ( PLLSTAT & (1 << 25) )
  {
    PLLCON = 1;     /* Enable PLL, disconnected */
    PLLFEED = 0xaa;
    PLLFEED = 0x55;
  }
  PLLCON = 0;       /* Disable PLL, disconnected */
  PLLFEED = 0xaa;
  PLLFEED = 0x55;

  SCS |= 0x20;      /* Enable main OSC */
  while( !(SCS & 0x40) ); /* Wait until main OSC is usable */

  CLKSRCSEL = 0x1;    /* select main OSC, 12MHz, as the PLL clock source */
  PLLCFG = PLL_MValue | (PLL_NValue << 16);
  PLLFEED = 0xaa;
  PLLFEED = 0x55;

  PLLCON = 1;       /* Enable PLL, disconnected */
  PLLFEED = 0xaa;
  PLLFEED = 0x55;

  CCLKCFG = 4; /* Set clock divider */

  while ( ((PLLSTAT & (1 << 26)) == 0) ); /* Check lock bit status */

  MValue = PLLSTAT & 0x00007FFF;
  NValue = (PLLSTAT & 0x00FF0000) >> 16;
  while ((MValue != PLL_MValue) && ( NValue != PLL_NValue) );

  PLLCON = 3;       /* enable and connect */
  PLLFEED = 0xaa;
  PLLFEED = 0x55;
  while ( ((PLLSTAT & (1 << 25)) == 0) ); /* Check connect bit status */

  /* Set system timers for each component */
#if (Fpclk / (Fcclk / 4)) == 1
  PCLKSEL0 = 0x00000000;  /* PCLK is 1/4 CCLK */
  PCLKSEL1 = 0x00000000;
#endif
#if (Fpclk / (Fcclk / 4)) == 2
  PCLKSEL0 = 0xAAAAAAAA;  /* PCLK is 1/2 CCLK */
  PCLKSEL1 = 0xAAAAAAAA;
#endif
#if (Fpclk / (Fcclk / 4)) == 4
  PCLKSEL0 = 0x55555555;  /* PCLK is the same as CCLK */
  PCLKSEL1 = 0x55555555;
#endif

  /* Set memory accelerater module*/
  MAMCR = 0;
#if Fcclk < 20000000
  MAMTIM = 1;
#else
#if Fcclk < 40000000
  MAMTIM = 2;
#else
  MAMTIM = 3;
#endif
#endif
  MAMCR = 2;
  // initial IO
  PINSEL4 = 0x05500000;  // set extint0-3
  // 设置P0.15为GPIO
  PINSEL0 &= 0x4fffffff;
  // 设置P0.16-18为GPIO
  PINSEL1 &= 0xffffffc0;
  // 设置P0.15-18为输出
  IO0DIR |= 0x00078000;
  
  return 0;
}

__irq __nested __arm void EINT_Handler (void)
{
  EXTINT = 0x0f;        /* clear interrupt */
  EXTMODE = 0x0f;
  eint0_counter++;
  if (eint0_counter& 0x1)
    IO0PIN = 0x00078000;
  else
    IO0PIN &= ~0x00078000;
  VICAddress = 0;   /* Acknowledge Interrupt */
}

DWORD EINTInit( void )
{
  if ( install_irq( EINT0_INT, (void *)EINT_Handler, HIGHEST_PRIORITY ) == FALSE )
  {
    return (FALSE);
  }
  if ( install_irq( EINT1_INT, (void *)EINT_Handler, HIGHEST_PRIORITY ) == FALSE )
  {
    return (FALSE);
  }
  if ( install_irq( EINT2_INT, (void *)EINT_Handler, HIGHEST_PRIORITY ) == FALSE )
  {
    return (FALSE);
  }
  if ( install_irq( EINT3_INT, (void *)EINT_Handler, HIGHEST_PRIORITY ) == FALSE )
  {
    return (FALSE);
  }
  return( TRUE );
}

int main()
{
  InitialBoard();
  init_VIC();
  EINTInit();
  while( 1 );
  return 0;
}

⌨️ 快捷键说明

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