/********************************************************************** * $Id$ Gpio_LedBlinky.c 2011-06-02 *//** * @file Gpio_LedBlinky.c * @brief This example describes how to use GPIO interrupt to drive * LEDs * @version 1.0 * @date 02. June. 2011 * @author NXP MCU SW Application Team * * Copyright(C) 2011, NXP Semiconductor * All rights reserved. * *********************************************************************** * Software that is described herein is for illustrative purposes only * which provides customers with programming information regarding the * products. This software is supplied "AS IS" without any warranties. * NXP Semiconductors assumes no responsibility or liability for the * use of the software, conveys no license or title under any patent, * copyright, or mask work right to the product. NXP Semiconductors * reserves the right to make changes in the software without * notification. NXP Semiconductors also make no representation or * warranty that such application will be suitable for the specified * use without further testing or modification. **********************************************************************/ #include "lpc177x_8x_gpio.h" #include "lpc177x_8x_clkpwr.h" #include "bsp.h" /** @defgroup GPIO_LedBlinky GPIO Blinky * @ingroup GPIO_Examples * @{ */ /************************** PRIVATE DEFINITIONS *************************/ /************************** PRIVATE VARIABLES *************************/ /* SysTick Counter */ volatile unsigned long SysTickCnt; /************************** PRIVATE FUNCTIONS *************************/ void SysTick_Handler (void); void Delay (unsigned long tick); /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/ /*********************************************************************//** * @brief SysTick handler sub-routine (1ms) * @param[in] None * @return None **********************************************************************/ void SysTick_Handler (void) { SysTickCnt++; } /*-------------------------PRIVATE FUNCTIONS------------------------------*/ /*********************************************************************//** * @brief Delay function * @param[in] tick - number milisecond of delay time * @return None **********************************************************************/ void Delay (unsigned long tick) { unsigned long systickcnt; systickcnt = SysTickCnt; while ((SysTickCnt - systickcnt) < tick); } /*********************************************************************//** * @brief GPIO Configuration * @return None * * Note: * *LED1 (P1_14) LED2 (P4_28) LED3 (P1_13) LED4 (P4_27) *JOYSITCK A(P2_25) B(P2_26) C(P2_23) D(P2_19) PRESS(P0_14) *key1(P5_4) key2(P2_22) key3(P0_10) * **********************************************************************/ void GPIO_Configuration(void) { /*LED1 (P1_14) LED2 (P0_16) LED3 (P1_13) LED4 (P4_27)*/ GPIO_SetDir(1, (1<<14), GPIO_DIRECTION_OUTPUT); GPIO_SetDir(0, (1<<16), GPIO_DIRECTION_OUTPUT); GPIO_SetDir(1, (1<<13), GPIO_DIRECTION_OUTPUT); GPIO_SetDir(4, (1<<27), GPIO_DIRECTION_OUTPUT); /*JOYSITCK A(P2_25) B(P2_26) C(P2_23) D(P2_19) PRESS(P0_14)*/ GPIO_SetDir(2, (1<<25), GPIO_DIRECTION_INPUT); GPIO_SetDir(2, (1<<26), GPIO_DIRECTION_INPUT); GPIO_SetDir(2, (1<<23), GPIO_DIRECTION_INPUT); GPIO_SetDir(2, (1<<19), GPIO_DIRECTION_INPUT); GPIO_SetDir(0, (1<<14), GPIO_DIRECTION_INPUT); /*key1(P4_26) key2(P2_22) key3(P0_10) */ GPIO_SetDir(5, (1<<4), GPIO_DIRECTION_INPUT); GPIO_SetDir(2, (1<<22), GPIO_DIRECTION_INPUT); GPIO_SetDir(0, (1<<10), GPIO_DIRECTION_INPUT); } /*-------------------------MAIN FUNCTION------------------------------*/ /*********************************************************************//** * @brief c_entry: Main program body * @param[in] None * @return int **********************************************************************/ int c_entry (void) { uint32_t key; uint32_t cclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU); /* Generate interrupt each 1 ms */ SysTick_Config(cclk/1000 - 1); GPIO_Configuration(); key=5; while(1) { /*key1(P4_26) key2(P2_22) key3(P0_10) */ if(!(GPIO_ReadValue(4) & (1<<26))) key=1; if(!(GPIO_ReadValue(2) & (1<<22))) key=2; if(!(GPIO_ReadValue(0) & (1<<10))) key=3; /*JOYSITCK A(P2_25) B(P2_26) C(P2_23) D(P2_19) PRESS(P0_14)*/ if(!(GPIO_ReadValue(2) & (1<<25))) key=1; if(!(GPIO_ReadValue(2) & (1<<26))) key=2; if(!(GPIO_ReadValue(2) & (1<<23))) key=3; if(!(GPIO_ReadValue(2) & (1<<19))) key=4; if(!(GPIO_ReadValue(0) & (1<<14))) key=0; /*LED1 (P1_14) LED2 (P0_16) LED3 (P1_13) LED4 (P4_27)*/ switch(key) { case 0: GPIO_SetValue(0, (1<<16)); GPIO_SetValue(1, (1<<14)|(1<<13)); GPIO_SetValue(4, (1<<27)); Delay(100); Delay(100); GPIO_ClearValue(0, (1<<16)); GPIO_ClearValue(1, (1<<14)|(1<<13)); GPIO_ClearValue(4, (1<<27)); Delay(100); break; case 1: GPIO_OutputValue(1, (1<<14), 1); Delay(100); GPIO_OutputValue(1, (1<<14), 0); Delay(100); break; case 2: GPIO_OutputValue(0, (1<<16), 1); Delay(100); GPIO_OutputValue(0, (1<<16), 0); Delay(100); break; case 3: GPIO_OutputValue(1, (1<<13), 1); Delay(100); GPIO_OutputValue(1, (1<<13), 0); Delay(100); break; case 4: GPIO_OutputValue(4, (1<<27), 1); Delay(100); GPIO_OutputValue(4, (1<<27), 0); Delay(100); break; /*LED1 (P1_14) LED2 (P4_28) LED3 (P1_13) LED4 (P4_27)*/ case 5: GPIO_OutputValue(1, (1<<14), 1); Delay(100); GPIO_OutputValue(1, (1<<14), 0); GPIO_OutputValue(0, (1<<16), 1); Delay(100); GPIO_OutputValue(0, (1<<16), 0); GPIO_OutputValue(1, (1<<13), 1); Delay(100); GPIO_OutputValue(1, (1<<13), 0); GPIO_OutputValue(4, (1<<27), 1); Delay(100); GPIO_OutputValue(4, (1<<27), 0); break; } } } /* With ARM and GHS toolsets, the entry point is main() - this will allow the linker to generate wrapper code to setup stacks, allocate heap area, and initialize and copy code and data segments. For GNU toolsets, the entry point is through __start() in the crt0_gnu.asm file, and that startup code will setup stacks and data */ int main(void) { return c_entry(); } /* * @} */