www.pudn.com > LPC2148_IAR_LPC2148.zip > demo.c


/************************************************************************* 
 * 
 *    Used with ICCARM and AARM. 
 * 
 *    (c) Copyright IAR Systems 2003 
 * 
 *    File name   : main.c 
 *    Description : Define main module 
 * 
 *    History : 
 *    1. Data        : Feb 10, 2005 
 *       Author      : Stanimir Bonev 
 *       Description : Create 
 * 
 * Buttons function 
 * Butt1 - Next 
 * Butt2 - Select 
 * 
 * Terminal settings: 
 * UART1 
 * ------------------ 
 * Communication speed: 9600 bps 
 * Number of data bits:    8 
 * Number of stop bits:    1 
 * Parity:              none 
 * 
 * UART2 
 * ------------------ 
 * Communication speed: 9600 bps 
 * Number of data bits:    8 
 * Number of stop bits:    1 
 * Parity:              none 
 * 
 * Jumper settings: 
 * ---------------- 
 * 
 * 
 * Set PWM/DAC to DAC. 
 * Set Ext/J-Linck to Ext. 
 * 
 * 
 * 
 *    $Revision: 1.3.2.1 $ 
**************************************************************************/ 
#include "includes.h" 
#include  
 
#define LIGHT_ALWAYS_OFF  0 
#define LIGHT_AUTO        1 
#define LIGHT_ALWAYS_ON   2 
#define LIGHT_AUTO_OFF_TO TICK_PER_SECOND*10 /* 10sec */ 
 
#define GET_TIME          '1' 
#define GET_DATE          '2' 
 
const char UART_Menu[] = "\r\nUart commands\r\n'1' Get Time\r\n'2' Get Date\r\n'?' Help\n\r"; 
 
volatile int TickSysFlag = 0; 
int SysTimeUpdateFlag = 0; 
int SysAlarmFlag = 0; 
 
int B1_Short = 0; 
int B2_Short = 0; 
 
int TimeFormat = 2; 
int DataFormat = 1; 
 
int LightMode = LIGHT_AUTO; 
 
/************************************************************************* 
 * Function Name: irq_handler 
 * Parameters: void 
 * Return: void 
 * 
 * Description: IRQ subroutine 
 *		 
 *************************************************************************/ 
__irq __arm void irq_handler (void) 
{ 
void (*interrupt_function)(); 
unsigned int vector; 
 
  vector = VICVectAddr;     // Get interrupt vector. 
  interrupt_function = (void(*)())vector; 
  (*interrupt_function)();  // Call vectored interrupt function. 
} 
 
/************************************************************************* 
 * Function Name: fiq_handler 
 * Parameters: void 
 * Return: void 
 * 
 * Description: FIQ subroutine 
 *		 
 *************************************************************************/ 
__fiq __arm void fiq_handler (void) 
{ 
void (*interrupt_function)(); 
unsigned int vector; 
 
  vector = VICVectAddr;     // Get interrupt vector. 
  interrupt_function = (void(*)())vector; 
  (*interrupt_function)();  // Call vectored interrupt function. 
} 
 
/************************************************************************* 
 * Function Name: NonVectISR 
 * Parameters: void 
 * Return: void 
 * 
 * Description: non vectored callback subroutine 
 *		 
 *************************************************************************/ 
void NonVectISR(void) 
{ 
} 
 
/************************************************************************* 
 * Function Name: ClearFlag 
 * Parameters: void 
 * Return: void 
 * 
 * Description: clear arg 
 *		 
 *************************************************************************/ 
void ClearFlag (void* arg) 
{ 
int* pFlag = arg; 
  *pFlag = 0; 
} 
 
/************************************************************************* 
 * Function Name: Dly100us 
 * Parameters: void *arg 
 * Return: void 
 * 
 * Description: Timer1 CH0 subroutine - delay [100us] 
 *		 
 *************************************************************************/ 
void Dly100us(void *arg) 
{ 
volatile int Flag = 1; 
int Delay = (int)arg; 
  // Stop Timer 1 
  TIMER_Stop(TIMER1); 
  // Stop Reset Timer 1 counter 
  TIMER_Reset(TIMER1); 
  // Set action of match module CH0 
  TIMER_SetMatchAction(TIMER1, CH0, TimerAction_Interrupt | TimerAction_StopTimer, 
  Delay usec_T1*100, ClearFlag, (void *)&Flag, DONOTHING); 
  // Start Timer 1 
  TIMER_Start(TIMER1); 
  // Wait expire of delay 
  while(Flag); 
} 
 
/************************************************************************* 
 * Function Name: SysInit 
 * Parameters: void 
 * Return: int 
 * 
 * Description: Hardware initialize 
 *		 
 *************************************************************************/ 
int SysInit(void) 
{ 
  // Initialize the system 
#ifdef FLASH 
  if (SYS_Init(FOSC, FCCLK, VPBDIV1, USER_FLASH, 0x0001FF0F,0x87FE01F1,0,0xFFFFFFFF)) 
    return 1; 
#else 
  if (SYS_Init(FOSC, FCCLK, VPBDIV1, USER_RAM,   0x0001FF0F,0x87FE01F1,0,0xFFFFFFFF)) 
    return 1; 
#endif 
  // Initialize Serial Interface 
  if (UART_Init(UART0)) 
    return 1; 
  if (UART_Init(UART1)) 
    return 1; 
 
  // Initialize Timers 
  if (TIMER_Init(TIMER0, TIMER_PRECISION)) 
    return 1; 
  if (TIMER_Init(TIMER1, TIMER_PRECISION)) 
    return 1; 
 
  // Initialize RTC 
  if (RTC_Init(0))	 
    return 1; 
 
  // initialize VIC 
  VIC_Init(); 
  VIC_SetProtectionMode(UserandPrivilegedMode); 
  // Enable interrupts non vectored interrupts 
  VIC_EnableNonVectoredIRQ(NonVectISR); 
 
  // UART0 interrupt 
  VIC_SetVectoredIRQ(UART0_ISR,VIC_Slot0,VIC_UART0); 
  VIC_EnableInt(1<