These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!
GPIO/GPIO_Interrupt/gpio_int.c@0:bf7b9fba3924, 2011-03-20 (annotated)
- Committer:
- frank26080115
- Date:
- Sun Mar 20 05:38:56 2011 +0000
- Revision:
- 0:bf7b9fba3924
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frank26080115 | 0:bf7b9fba3924 | 1 | /***********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 2 | * @file gpio_int.c |
frank26080115 | 0:bf7b9fba3924 | 3 | * @purpose This example used to test GPIO interrupt function |
frank26080115 | 0:bf7b9fba3924 | 4 | * @version 2.0 |
frank26080115 | 0:bf7b9fba3924 | 5 | * @date 21. May. 2010 |
frank26080115 | 0:bf7b9fba3924 | 6 | * @author NXP MCU SW Application Team |
frank26080115 | 0:bf7b9fba3924 | 7 | *--------------------------------------------------------------------- |
frank26080115 | 0:bf7b9fba3924 | 8 | * Software that is described herein is for illustrative purposes only |
frank26080115 | 0:bf7b9fba3924 | 9 | * which provides customers with programming information regarding the |
frank26080115 | 0:bf7b9fba3924 | 10 | * products. This software is supplied "AS IS" without any warranties. |
frank26080115 | 0:bf7b9fba3924 | 11 | * NXP Semiconductors assumes no responsibility or liability for the |
frank26080115 | 0:bf7b9fba3924 | 12 | * use of the software, conveys no license or title under any patent, |
frank26080115 | 0:bf7b9fba3924 | 13 | * copyright, or mask work right to the product. NXP Semiconductors |
frank26080115 | 0:bf7b9fba3924 | 14 | * reserves the right to make changes in the software without |
frank26080115 | 0:bf7b9fba3924 | 15 | * notification. NXP Semiconductors also make no representation or |
frank26080115 | 0:bf7b9fba3924 | 16 | * warranty that such application will be suitable for the specified |
frank26080115 | 0:bf7b9fba3924 | 17 | * use without further testing or modification. |
frank26080115 | 0:bf7b9fba3924 | 18 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 19 | #include "LPC17xx.h" |
frank26080115 | 0:bf7b9fba3924 | 20 | #include "lpc17xx_gpio.h" |
frank26080115 | 0:bf7b9fba3924 | 21 | #include "lpc17xx_pinsel.h" |
frank26080115 | 0:bf7b9fba3924 | 22 | #include "lpc17xx_libcfg.h" |
frank26080115 | 0:bf7b9fba3924 | 23 | |
frank26080115 | 0:bf7b9fba3924 | 24 | /* Example group ----------------------------------------------------------- */ |
frank26080115 | 0:bf7b9fba3924 | 25 | /** @defgroup GPIO_Interrupt GPIO_Interrupt |
frank26080115 | 0:bf7b9fba3924 | 26 | * @ingroup GPIO_Examples |
frank26080115 | 0:bf7b9fba3924 | 27 | * @{ |
frank26080115 | 0:bf7b9fba3924 | 28 | */ |
frank26080115 | 0:bf7b9fba3924 | 29 | |
frank26080115 | 0:bf7b9fba3924 | 30 | /************************** PRIVATE DEFINITIONS *************************/ |
frank26080115 | 0:bf7b9fba3924 | 31 | #define MCB_LPC_1768 |
frank26080115 | 0:bf7b9fba3924 | 32 | //#define IAR_LPC_1768 |
frank26080115 | 0:bf7b9fba3924 | 33 | |
frank26080115 | 0:bf7b9fba3924 | 34 | #ifdef MCB_LPC_1768 |
frank26080115 | 0:bf7b9fba3924 | 35 | /* LED pin in byte style on P1 */ |
frank26080115 | 0:bf7b9fba3924 | 36 | #define POLL_LED (1<<4) // P1.28 |
frank26080115 | 0:bf7b9fba3924 | 37 | #define INT3_LED (1<<5) // P1.29 |
frank26080115 | 0:bf7b9fba3924 | 38 | #define GPIO_INT (1<<25) // test GPIO interrupt on P0.25 |
frank26080115 | 0:bf7b9fba3924 | 39 | #elif defined(IAR_LPC_1768) |
frank26080115 | 0:bf7b9fba3924 | 40 | #define POLL_LED (1<<1) //P1.25 (LED2) |
frank26080115 | 0:bf7b9fba3924 | 41 | #define INT3_LED (1<<4) //P0.4 (LED1) |
frank26080115 | 0:bf7b9fba3924 | 42 | #define GPIO_INT (1<<23) // test GPIO interrupt on P0.23 |
frank26080115 | 0:bf7b9fba3924 | 43 | #endif |
frank26080115 | 0:bf7b9fba3924 | 44 | |
frank26080115 | 0:bf7b9fba3924 | 45 | |
frank26080115 | 0:bf7b9fba3924 | 46 | /************************** PRIVATE FUNCTIONS *************************/ |
frank26080115 | 0:bf7b9fba3924 | 47 | void EINT3_IRQHandler(void); |
frank26080115 | 0:bf7b9fba3924 | 48 | |
frank26080115 | 0:bf7b9fba3924 | 49 | void delay (void); |
frank26080115 | 0:bf7b9fba3924 | 50 | |
frank26080115 | 0:bf7b9fba3924 | 51 | /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 52 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 53 | * @brief External interrupt 3 handler sub-routine |
frank26080115 | 0:bf7b9fba3924 | 54 | * @param[in] None |
frank26080115 | 0:bf7b9fba3924 | 55 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 56 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 57 | void EINT3_IRQHandler(void) |
frank26080115 | 0:bf7b9fba3924 | 58 | { |
frank26080115 | 0:bf7b9fba3924 | 59 | int j; |
frank26080115 | 0:bf7b9fba3924 | 60 | if(GPIO_GetIntStatus(0, 25, 1)) |
frank26080115 | 0:bf7b9fba3924 | 61 | { |
frank26080115 | 0:bf7b9fba3924 | 62 | GPIO_ClearInt(0,(1<<25)); |
frank26080115 | 0:bf7b9fba3924 | 63 | for (j= 0; j<8; j++) |
frank26080115 | 0:bf7b9fba3924 | 64 | { |
frank26080115 | 0:bf7b9fba3924 | 65 | #ifdef MCB_LPC_1768 |
frank26080115 | 0:bf7b9fba3924 | 66 | /* Use MCB1700 board: |
frank26080115 | 0:bf7b9fba3924 | 67 | * blink LED P1.29 when EINT3 occur |
frank26080115 | 0:bf7b9fba3924 | 68 | */ |
frank26080115 | 0:bf7b9fba3924 | 69 | FIO_ByteSetValue(1, 3, INT3_LED); |
frank26080115 | 0:bf7b9fba3924 | 70 | delay(); |
frank26080115 | 0:bf7b9fba3924 | 71 | FIO_ByteClearValue(1, 3, INT3_LED); |
frank26080115 | 0:bf7b9fba3924 | 72 | delay(); |
frank26080115 | 0:bf7b9fba3924 | 73 | #elif defined(IAR_LPC_1768) |
frank26080115 | 0:bf7b9fba3924 | 74 | /* Use IAR LPC1768 KS board: |
frank26080115 | 0:bf7b9fba3924 | 75 | * blink LED2 P0.4 when EINT3 occur |
frank26080115 | 0:bf7b9fba3924 | 76 | */ |
frank26080115 | 0:bf7b9fba3924 | 77 | FIO_ByteSetValue(0, 0, INT3_LED); |
frank26080115 | 0:bf7b9fba3924 | 78 | delay(); |
frank26080115 | 0:bf7b9fba3924 | 79 | FIO_ByteClearValue(0, 0, INT3_LED); |
frank26080115 | 0:bf7b9fba3924 | 80 | delay(); |
frank26080115 | 0:bf7b9fba3924 | 81 | #endif |
frank26080115 | 0:bf7b9fba3924 | 82 | } |
frank26080115 | 0:bf7b9fba3924 | 83 | } |
frank26080115 | 0:bf7b9fba3924 | 84 | } |
frank26080115 | 0:bf7b9fba3924 | 85 | |
frank26080115 | 0:bf7b9fba3924 | 86 | /*-------------------------PRIVATE FUNCTIONS------------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 87 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 88 | * @brief Delay function |
frank26080115 | 0:bf7b9fba3924 | 89 | * @param[in] None |
frank26080115 | 0:bf7b9fba3924 | 90 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 91 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 92 | void delay (void) { |
frank26080115 | 0:bf7b9fba3924 | 93 | unsigned int i; |
frank26080115 | 0:bf7b9fba3924 | 94 | |
frank26080115 | 0:bf7b9fba3924 | 95 | for (i = 0; i < 0x100000; i++) { |
frank26080115 | 0:bf7b9fba3924 | 96 | } |
frank26080115 | 0:bf7b9fba3924 | 97 | } |
frank26080115 | 0:bf7b9fba3924 | 98 | |
frank26080115 | 0:bf7b9fba3924 | 99 | |
frank26080115 | 0:bf7b9fba3924 | 100 | /*-------------------------MAIN FUNCTION------------------------------*/ |
frank26080115 | 0:bf7b9fba3924 | 101 | /*********************************************************************//** |
frank26080115 | 0:bf7b9fba3924 | 102 | * @brief c_entry: Main program body |
frank26080115 | 0:bf7b9fba3924 | 103 | * @param[in] None |
frank26080115 | 0:bf7b9fba3924 | 104 | * @return int |
frank26080115 | 0:bf7b9fba3924 | 105 | **********************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 106 | int c_entry (void) |
frank26080115 | 0:bf7b9fba3924 | 107 | { |
frank26080115 | 0:bf7b9fba3924 | 108 | /** Use: LEDs for polling when idle and when GPIO interrupt occurs |
frank26080115 | 0:bf7b9fba3924 | 109 | * If using MCB1700 board: Polling led: P1.28; Interrupt led: P1.29 |
frank26080115 | 0:bf7b9fba3924 | 110 | * If using IAR KS board: Polling led: P1.25 (LED1); Interrupt led: P0.4 (LED2) |
frank26080115 | 0:bf7b9fba3924 | 111 | */ |
frank26080115 | 0:bf7b9fba3924 | 112 | #ifdef MCB_LPC_1768 |
frank26080115 | 0:bf7b9fba3924 | 113 | FIO_ByteSetDir(1, 3, POLL_LED, 1); |
frank26080115 | 0:bf7b9fba3924 | 114 | FIO_ByteSetDir(1, 3, INT3_LED, 1); |
frank26080115 | 0:bf7b9fba3924 | 115 | // Turn off all LEDs |
frank26080115 | 0:bf7b9fba3924 | 116 | FIO_ByteClearValue(1, 3, POLL_LED); |
frank26080115 | 0:bf7b9fba3924 | 117 | FIO_ByteClearValue(1, 3, INT3_LED); |
frank26080115 | 0:bf7b9fba3924 | 118 | #elif defined(IAR_LPC_1768) |
frank26080115 | 0:bf7b9fba3924 | 119 | FIO_ByteSetDir(1, 3, POLL_LED, 1); |
frank26080115 | 0:bf7b9fba3924 | 120 | FIO_ByteSetDir(0, 0, INT3_LED, 1); |
frank26080115 | 0:bf7b9fba3924 | 121 | // Turn off all LEDs |
frank26080115 | 0:bf7b9fba3924 | 122 | FIO_ByteSetValue(1, 3, POLL_LED); |
frank26080115 | 0:bf7b9fba3924 | 123 | FIO_ByteSetValue(0, 0, INT3_LED); |
frank26080115 | 0:bf7b9fba3924 | 124 | #endif |
frank26080115 | 0:bf7b9fba3924 | 125 | |
frank26080115 | 0:bf7b9fba3924 | 126 | // Enable GPIO interrupt |
frank26080115 | 0:bf7b9fba3924 | 127 | /* Use MCB1700: test GPIO interrupt on P0.25->connects with ADC potentiometer |
frank26080115 | 0:bf7b9fba3924 | 128 | * Use IAR KS : test GPIO interrupt on P0.23->connects with BUT1 button |
frank26080115 | 0:bf7b9fba3924 | 129 | */ |
frank26080115 | 0:bf7b9fba3924 | 130 | GPIO_IntCmd(0,(1<<25),1); |
frank26080115 | 0:bf7b9fba3924 | 131 | NVIC_EnableIRQ(EINT3_IRQn); |
frank26080115 | 0:bf7b9fba3924 | 132 | |
frank26080115 | 0:bf7b9fba3924 | 133 | while (1) |
frank26080115 | 0:bf7b9fba3924 | 134 | { |
frank26080115 | 0:bf7b9fba3924 | 135 | //polling led while idle |
frank26080115 | 0:bf7b9fba3924 | 136 | FIO_ByteSetValue(1, 3, POLL_LED); |
frank26080115 | 0:bf7b9fba3924 | 137 | delay(); |
frank26080115 | 0:bf7b9fba3924 | 138 | FIO_ByteClearValue(1, 3, POLL_LED); |
frank26080115 | 0:bf7b9fba3924 | 139 | delay(); |
frank26080115 | 0:bf7b9fba3924 | 140 | } |
frank26080115 | 0:bf7b9fba3924 | 141 | } |
frank26080115 | 0:bf7b9fba3924 | 142 | |
frank26080115 | 0:bf7b9fba3924 | 143 | |
frank26080115 | 0:bf7b9fba3924 | 144 | /* With ARM and GHS toolsets, the entry point is main() - this will |
frank26080115 | 0:bf7b9fba3924 | 145 | allow the linker to generate wrapper code to setup stacks, allocate |
frank26080115 | 0:bf7b9fba3924 | 146 | heap area, and initialize and copy code and data segments. For GNU |
frank26080115 | 0:bf7b9fba3924 | 147 | toolsets, the entry point is through __start() in the crt0_gnu.asm |
frank26080115 | 0:bf7b9fba3924 | 148 | file, and that startup code will setup stacks and data */ |
frank26080115 | 0:bf7b9fba3924 | 149 | int main(void) |
frank26080115 | 0:bf7b9fba3924 | 150 | { |
frank26080115 | 0:bf7b9fba3924 | 151 | return c_entry(); |
frank26080115 | 0:bf7b9fba3924 | 152 | } |
frank26080115 | 0:bf7b9fba3924 | 153 | |
frank26080115 | 0:bf7b9fba3924 | 154 | #ifdef DEBUG |
frank26080115 | 0:bf7b9fba3924 | 155 | /******************************************************************************* |
frank26080115 | 0:bf7b9fba3924 | 156 | * @brief Reports the name of the source file and the source line number |
frank26080115 | 0:bf7b9fba3924 | 157 | * where the CHECK_PARAM error has occurred. |
frank26080115 | 0:bf7b9fba3924 | 158 | * @param[in] file Pointer to the source file name |
frank26080115 | 0:bf7b9fba3924 | 159 | * @param[in] line assert_param error line source number |
frank26080115 | 0:bf7b9fba3924 | 160 | * @return None |
frank26080115 | 0:bf7b9fba3924 | 161 | *******************************************************************************/ |
frank26080115 | 0:bf7b9fba3924 | 162 | void check_failed(uint8_t *file, uint32_t line) |
frank26080115 | 0:bf7b9fba3924 | 163 | { |
frank26080115 | 0:bf7b9fba3924 | 164 | /* User can add his own implementation to report the file name and line number, |
frank26080115 | 0:bf7b9fba3924 | 165 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
frank26080115 | 0:bf7b9fba3924 | 166 | |
frank26080115 | 0:bf7b9fba3924 | 167 | /* Infinite loop */ |
frank26080115 | 0:bf7b9fba3924 | 168 | while(1); |
frank26080115 | 0:bf7b9fba3924 | 169 | } |
frank26080115 | 0:bf7b9fba3924 | 170 | #endif |
frank26080115 | 0:bf7b9fba3924 | 171 | |
frank26080115 | 0:bf7b9fba3924 | 172 | /* |
frank26080115 | 0:bf7b9fba3924 | 173 | * @} |
frank26080115 | 0:bf7b9fba3924 | 174 | */ |