cortex m0 lpc1114的NVIC中斷如何使用
LPC1114單片機的NVIC中斷函數(shù),有開中斷、關中斷、設置優(yōu)先級、掛起等操作函數(shù)。這些函數(shù)位于core_cm0.h文件里面。比如開中斷的函數(shù)如下:
/**briefEnableExternalInterruptThefunctionenablesadevice-specificinterruptintheNVICinterruptcontroller.param[in]IRQnExternalinterruptnumber.Valuecannotbenegative.*/__STATIC_INLINEvoidNVIC_EnableIRQ(IRQn_TypeIRQn){NVIC->ISER[0]=(1<<((uint32_t)(IRQn)&0x1F));}
/**/里面的注釋告訴我們,這是一個中斷函數(shù),函數(shù)的功能是允許一個中斷,也就是開中斷的意思。
比如我們要開P1口的中斷,可以這樣使用這個函數(shù):NVIC_EnableIRQ(EINT1_IRQn);
該函數(shù)里面,NVIC_EnableIRQ是函數(shù)名,EINT1_IRQn是參數(shù),表示P1口的中斷,這個參數(shù)可以在頭文件lpc11xx.h文件中找到。如下所示:
*==========================================================================*----------InterruptNumberDefinition-----------------------------------*==========================================================================*/typedefenumIRQn{/******Cortex-M0ProcessorExceptionsNumbers******************************/Reset_IRQn=-15,/*!<1ResetVector,invokedonPowerupandwarmreset*/NonMaskableInt_IRQn=-14,/*!<2NonmaskableInterrupt,cannotbestoppedorpreempted*/HardFault_IRQn=-13,/*!<3HardFault,allclassesofFault*/SVCall_IRQn=-5,/*!<11SystemServiceCallviaSVCinstruction*/PendSV_IRQn=-2,/*!<14Pendablerequestforsystemservice*/SysTick_IRQn=-1,/*!<15SystemTickTimer*//******LPC11CxxorLPC11xxSpecificInterruptNumbers*************************/WAKEUP0_IRQn=0,/*!可以看到,共有32種中斷,在使用的時候,你要開什么中斷,就用NVIC開中斷函數(shù)把對應的中斷打開。
開了中斷以后,中斷函數(shù)怎么寫呢?
例如P1口的中斷函數(shù)這樣寫:
voidPIOINT1_IRQHandler(){//進中斷以后執(zhí)行的代碼}為什么P1口的中斷函數(shù)名稱是PIOINT1_IRQHandler,這個其實在startup_lpc11xx.s文件中已經(jīng)定義好了:
;ExternalInterruptsDCDWAKEUP_IRQHandler;16+0:WakeupPIO0.0DCDWAKEUP_IRQHandler;16+1:WakeupPIO0.1DCDWAKEUP_IRQHandler;16+2:WakeupPIO0.2DCDWAKEUP_IRQHandler;16+3:WakeupPIO0.3DCDWAKEUP_IRQHandler;16+4:WakeupPIO0.4DCDWAKEUP_IRQHandler;16+5:WakeupPIO0.5DCDWAKEUP_IRQHandler;16+6:WakeupPIO0.6DCDWAKEUP_IRQHandler;16+7:WakeupPIO0.7DCDWAKEUP_IRQHandler;16+8:WakeupPIO0.8DCDWAKEUP_IRQHandler;16+9:WakeupPIO0.9DCDWAKEUP_IRQHandler;16+10:WakeupPIO0.10DCDWAKEUP_IRQHandler;16+11:WakeupPIO0.11DCDWAKEUP_IRQHandler;16+12:WakeupPIO1.0DCDCAN_IRQHandler;16+13:CANDCDSSP1_IRQHandler;16+14:SSP1DCDI2C_IRQHandler;16+15:I2CDCDTIMER16_0_IRQHandler;16+16:16-bitCounter-Timer0DCDTIMER16_1_IRQHandler;16+17:16-bitCounter-Timer1DCDTIMER32_0_IRQHandler;16+18:32-bitCounter-Timer0DCDTIMER32_1_IRQHandler;16+19:32-bitCounter-Timer1DCDSSP0_IRQHandler;16+20:SSP0DCDUART_IRQHandler;16+21:UARTDCDUSB_IRQHandler;16+22:USBIRQDCDUSB_FIQHandler;16+24:USBFIQDCDADC_IRQHandler;16+24:A/DConverterDCDWDT_IRQHandler;16+25:WatchdogTimerDCDBOD_IRQHandler;16+26:BrownOutDetectDCDFMC_IRQHandler;16+27:IP2111FlashMemoryControllerDCDPIOINT3_IRQHandler;16+28:PIOINT3DCDPIOINT2_IRQHandler;16+29:PIOINT2DCDPIOINT1_IRQHandler;16+30:PIOINT1DCDPIOINT0_IRQHandler;16+31:PIOINT0總結:NVIC的函數(shù)使用,就是這么簡單,KEIL已經(jīng)給我們寫好,我們直接使用即可!