int main (void) { uint32_t interval; SystemCoreClockUpdate(); /* Config CLKOUT, mostly used for debugging. */ CLKOUT_Setup( CLKOUTCLK_SRC_MAIN_CLK ); LPC_IOCON->PIO0_1 &= ~0x07; LPC_IOCON->PIO0_1 |= 0x01; /* CLK OUT */ /* Enable AHB clock to the GPIO domain. */ LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6); /* TEST_TIMER_NUM is either 0 or 1 for 16-bit timer 0 or 1. */ interval = SystemCoreClock/1000 - 1; if ( interval > 0xFFFF ) { interval = 0xFFFF; } init_timer16(TEST_TIMER_NUM, interval); enable_timer16(TEST_TIMER_NUM); /* Set port 2_0 to output */ GPIOSetDir( 2, 0, 1 ); while (1) /* Loop forever */ { #if TEST_TIMER_NUM /* I/O configuration and LED setting pending. */ if ( (timer16_1_counter > 0) && (timer16_1_counter <= 200) ) { GPIOSetValue( 2, 0, 0 ); } if ( (timer16_1_counter > 200) && (timer16_1_counter <= 400) ) { GPIOSetValue( 2, 0, 1 ); } else if ( timer16_1_counter > 400 ) { timer16_1_counter = 0; } #else /* I/O configuration and LED setting pending. */ if ( (timer16_0_counter > 0) && (timer16_0_counter <= 200) ) { GPIOSetValue( 2, 0, 0 ); } if ( (timer16_0_counter > 200) && (timer16_0_counter <= 400) ) { GPIOSetValue( 2, 0, 1 ); } else if ( timer16_0_counter > 400 ) { timer16_0_counter = 0; } #endif } }
/***************************************************************************** ** Main Function main() ******************************************************************************/ int main (void) { /*** The main Function is an endless loop ****/ // Configure WDT to run from internal WD oscillator at about 8 kHz WDTInit(); init_timer16( 0, TIME_INTERVALmS * 10 ); enable_timer16( 0 ); /* Set LED pin to output and make sure it is off */ GPIOSetDir( LED_PORT, LED_BIT, 1 ); GPIOSetValue( LED_PORT, LED_BIT, LED_OFF ); // Check reset status for watchdog reset- if found, blink quickly if ((LPC_SYSCON->SYSRSTSTAT & 0x4) == 0x4) { LPC_SYSCON->SYSRSTSTAT |= 0x4; while( 1 ) { /* I/O configuration and LED setting pending. */ if ( (timer16_0_counter > 0) && (timer16_0_counter <= FAST_LED_TOGGLE_TICKS/2) ) { GPIOSetValue( LED_PORT, LED_BIT, LED_OFF ); } if ( (timer16_0_counter > FAST_LED_TOGGLE_TICKS/2) && (timer16_0_counter <= FAST_LED_TOGGLE_TICKS) ) { GPIOSetValue( LED_PORT, LED_BIT, LED_ON ); } else if ( timer16_0_counter > FAST_LED_TOGGLE_TICKS ) { timer16_0_counter = 0; } } } else { // No watchdog reset- lets blink slowly while( 1 ) { /* I/O configuration and LED setting pending. */ if ( (timer16_0_counter > 0) && (timer16_0_counter <= LED_TOGGLE_TICKS/2) ) { GPIOSetValue( LED_PORT, LED_BIT, LED_OFF ); } if ( (timer16_0_counter > LED_TOGGLE_TICKS/2) && (timer16_0_counter <= LED_TOGGLE_TICKS) ) { GPIOSetValue( LED_PORT, LED_BIT, LED_ON ); } else if ( timer16_0_counter > LED_TOGGLE_TICKS ) { timer16_0_counter = 0; } } } }
int main (void) { GPIOInit(); // Initialize Timer16_0 to tick at rate of 1/2000th of second. // Note that as this is a 16 bit timer, the maximum count we can // load into timer is 0xFFFF, or 65535. Default clock speed // set up by CMSIS SystemInit function - SystemCoreClock - is // 48MHz or 48000000 Hz. Dividing this by 2000 is 24000 which is // within appropriate timer16 maximum. This could be extended // if timer routine extended to make use of Prescale Counter register // Note by default LPC_SYSCON->SYSAHBCLKDIV is 1. init_timer16(0, (SystemCoreClock/LPC_SYSCON->SYSAHBCLKDIV)/2000 ); // Initialize counter that counts Timer16_0 ticks timer16_0_counter = 0; //Enable Timer16_0 enable_timer16(0); // Set port for LED to output GPIOSetDir( LED_PORT, LED_BIT, 1 ); while (1) /* Loop forever */ { // LED is on for 1st half-second if ( (timer16_0_counter > 0) && (timer16_0_counter <= 1000) ) { GPIOSetValue( LED_PORT, LED_BIT, LED_OFF ); } // LED is off for 2nd half-second if ( (timer16_0_counter > 1000) && (timer16_0_counter <= 2000) ) { GPIOSetValue( LED_PORT, LED_BIT, LED_ON ); } // Reset counter else if ( timer16_0_counter > 2000 ) { timer16_0_counter = 0; } } }
int main (void) { SystemInit(); USBIOClkConfig(); /* P0.1 is push-button input, P2.0~3 are LED output. */ LPC_GPIO2->DIR |= (0x1<<0)|(0x1<<1)|(0x1<<2)|(0x1<<3); LPC_GPIO0->DIR &= ~(0x1<<1); /* 16-bit timer 0. */ init_timer16(0, TIME_INTERVAL); enable_timer16(0); /* Set port 2_0 to output */ GPIOSetDir( 2, 0, 1 ); USB_Init(); /* USB Initialization */ USB_Connect(TRUE); /* USB Connect */ while (1) /* Loop forever */ { /* I/O configuration and LED setting pending. */ if ( (timer16_0_counter > 0) && (timer16_0_counter <= 200) ) { GPIOSetValue( 2, 0, 0 ); } if ( (timer16_0_counter > 200) && (timer16_0_counter <= 400) ) { GPIOSetValue( 2, 0, 1 ); } else if ( timer16_0_counter > 400 ) { timer16_0_counter = 0; } } }
int main (void) { /* Basic chip initialization is taken care of in SystemInit() called * from the startup code. SystemInit() and chip settings are defined * in the CMSIS system_<part family>.c file. */ /* SystemInit(); */ /* Config CLKOUT, mostly used for debugging. */ CLKOUT_Setup( CLKOUTCLK_SRC_MAIN_CLK ); LPC_IOCON->PIO0_1 &= ~0x07; LPC_IOCON->PIO0_1 |= 0x01; /* CLK OUT */ /* Enable AHB clock to the GPIO domain. */ LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6); /* TEST_TIMER_NUM is either 0 or 1 for 16-bit timer 0 or 1. */ init_timer16(TEST_TIMER_NUM, TIME_INTERVAL); enable_timer16(TEST_TIMER_NUM); /* Set port 2_0 to output */ /* GPIOSetDir( 2, 0, 1 ); */ /* Set LED port pin to output */ GPIOSetDir( LED_PORT, LED_BIT, 1 ); while (1) /* Loop forever */ { #if TEST_TIMER_NUM /* I/O configuration and LED setting pending. */ if ( (timer16_1_counter > 0) && (timer16_1_counter <= 200) ) { /* GPIOSetValue( 2, 0, 0 ); */ GPIOSetValue( LED_PORT, LED_BIT, LED_OFF ); } if ( (timer16_1_counter > 200) && (timer16_1_counter <= 400) ) { /* GPIOSetValue( 2, 0, 1 ); */ GPIOSetValue( LED_PORT, LED_BIT, LED_ON ); } else if ( timer16_1_counter > 400 ) { timer16_1_counter = 0; } #else /* I/O configuration and LED setting pending. */ if ( (timer16_0_counter > 0) && (timer16_0_counter <= 200) ) { /* GPIOSetValue( 2, 0, 0 ); */ GPIOSetValue( LED_PORT, LED_BIT, LED_OFF ); } if ( (timer16_0_counter > 200) && (timer16_0_counter <= 400) ) { /* GPIOSetValue( 2, 0, 1 ); */ GPIOSetValue( LED_PORT, LED_BIT, LED_ON ); } else if ( timer16_0_counter > 400 ) { timer16_0_counter = 0; } #endif } }