1 / 15

Lab 4 Interrupt

Lab 4 Interrupt. Experiment 4. Goal: 1.How do interrupts work? 2.How does the interrupt service (ISR) take over the MCU(micro control unit)? 3.How to write ISR, modify Startup.s? 4.How to let GPIO,TIMER,SYSTICK work as interrupt producer? Outputs: JP3 PF2 LED1 JP2 PF3 LED0

sora
Download Presentation

Lab 4 Interrupt

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab 4 Interrupt

  2. Experiment 4 Goal: 1.How do interrupts work? 2.How does the interrupt service (ISR) take over the MCU(micro control unit)? 3.How to write ISR, modify Startup.s? 4.How to let GPIO,TIMER,SYSTICK work as interrupt producer? Outputs: JP3 PF2 LED1 JP2 PF3 LED0 Inputs: JP43 PB6 SW1-RIGHT JP41 PE5 SW2-PRESS JP42 PE4 SW3-UP JP44 PF1 SW4-DOWN JP45 PB4 SW5-LEFT Push down one key of SW1-RIGHT ,SW3-UP,SW4-DOWN,SW5-LEFT Yellow(LED0)turns on for 1s,then turns off for 2s Green(LED1)turns on for 0.33s,then turns off for 0.67s Push down SW2-PRESS, both LEDs are turned off.

  3. Main.c with interrupt #include "HardwareLibrary.h" #include "LuminaryDriverLibrary.h" #include "GPIODriverConfigure.h" #include "SysCtlConfigure.h" #include "SysTickConfigure.h" #include "TimerConfigure.h" unsigned char ShiningEnable=true; //hw_types中定义,必须小写 int main(void) { ClockInitial(); GPIOInitial(); SysTickInitial(); TimerInitial(); IntMasterEnable(); //外围中断开启(除了SysTick外的所有中断都要开启) SysTickEnable(); //SysTick开始计数 TimerEnable(TIMER0_BASE,TIMER_A); //TIMER0开始计数 while(1); }

  4. Experiment 3-2 unsigned char KeyPress(unsigned char KeyNum) { switch (KeyNum) { case KEY_PRESS: { if (HWREG(KEY_PRESS_BASE+GPIO_O_DATA+(KEY_PRESS_PIN<<2))) return 0; else return 1; int main(void) { ClockInitial(); GPIOInitial(); SysTickInitial(); TimerInitial(); while(1) { if (KeyPress(KEY_PRESS)) { if (SysTickValueGet() > (TheSysClock*2)) LEDOn(LED_0); else LEDOff(LED_0); if (TimerValueGet(TIMER0_BASE,TIMER_A) > (TheSysClock*10/3)) LEDOn(LED_1); else LEDOff(LED_1); } else LEDOff(LED_ALL); } }

  5. IN GTIOinitial() GPIOIntTypeSet(KEY_PRESS_BASE,KEY_PRESS_PIN, GPIO_FALLING_EDGE); //Press中断 GPIOPinIntEnable(KEY_PRESS_BASE,KEY_PRESS_PIN); GPIOIntTypeSet(KEY_LEFT_BASE,KEY_LEFT_PIN, GPIO_FALLING_EDGE); //Left中断 GPIOPinIntEnable(KEY_LEFT_BASE,KEY_LEFT_PIN); GPIOIntTypeSet(KEY_RIGHT_BASE,KEY_RIGHT_PIN, GPIO_FALLING_EDGE); //Right中断 GPIOPinIntEnable(KEY_RIGHT_BASE,KEY_RIGHT_PIN); GPIOIntTypeSet(KEY_UP_BASE,KEY_UP_PIN, GPIO_FALLING_EDGE); //Up中断 GPIOPinIntEnable(KEY_UP_BASE,KEY_UP_PIN); GPIOIntTypeSet(KEY_DOWN_BASE,KEY_DOWN_PIN, GPIO_FALLING_EDGE); //Down中断 GPIOPinIntEnable(KEY_DOWN_BASE,KEY_DOWN_PIN); IntEnable(INT_GPIOE); //开启GPIOE中断源 IntEnable(INT_GPIOB); //开启GPIOB中断源 IntEnable(INT_GPIOF); //开启GPIOF中断源

  6. Modify Startup.s ****************************************************************************** ; ; Place code into the reset code section. ; ;****************************************************************************** AREA RESET, CODE, READONLY THUMB EXTERN SysTick_ISR EXTERN Timer0A_ISR EXTERN GPIO_Port_B_ISR EXTERN GPIO_Port_E_ISR EXTERN GPIO_Port_F_ISR ;****************************************************************************** ;

  7. ;******************************************************************************;****************************************************************************** ; ; The vector table. ; ;************************************************************************* EXPORT __Vectors __Vectors DCD StackMem + Stack ; Top of Stack DCD Reset_Handler ; Reset Handler DCD NmiSR ; NMI Handler DCD FaultISR ; Hard Fault Handler DCD IntDefaultHandler ; MPU Fault Handler DCD IntDefaultHandler ; Bus Fault Handler DCD IntDefaultHandler ; Usage Fault Handler DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD IntDefaultHandler ; SVCall Handler DCD IntDefaultHandler ; Debug Monitor Handler DCD 0 ; Reserved DCD IntDefaultHandler ; PendSV Handler DCD SysTick_ISR ; SysTick Handler DCD IntDefaultHandler ; GPIO Port A DCD GPIO_Port_B_ISR ; GPIO Port B DCD IntDefaultHandler ; GPIO Port C DCD IntDefaultHandler ; GPIO Port D DCD GPIO_Port_E_ISR ; GPIO Port E DCD IntDefaultHandler ; UART0 DCD IntDefaultHandler ; UART1 DCD IntDefaultHandler ; SSI DCD IntDefaultHandler ; I2C DCD IntDefaultHandler ; PWM Fault DCD IntDefaultHandler ; PWM Generator 0 DCD IntDefaultHandler ; PWM Generator 1 DCD IntDefaultHandler ; PWM Generator 2 DCD IntDefaultHandler ; Quadrature Encoder DCD IntDefaultHandler ; ADC Sequence 0 DCD IntDefaultHandler ; ADC Sequence 1 DCD IntDefaultHandler ; ADC Sequence 2 DCD IntDefaultHandler ; ADC Sequence 3 DCD IntDefaultHandler ; Watchdog DCD Timer0A_ISR ; Timer 0A

  8. Interrupt in ARM

  9. Interrupt/Exception Sequences ● Exception Exits ● Nested Interrupts ● Tail-Chaining Interrupts ● Late Arrivals ● More on the Exception Return Value ● Interrupt Latency ● Faults Related to Interrupts

More Related