Presentation is loading. Please wait.

Presentation is loading. Please wait.

Interrupts Microprocessor and Interfacing 261313.

Similar presentations


Presentation on theme: "Interrupts Microprocessor and Interfacing 261313."— Presentation transcript:

1 Interrupts Microprocessor and Interfacing 261313

2 Example: Writing a Game Need to Check Keyboard Input

3 Method 1: Using a Loop Program keeps checking for keyboard input While (1) [ If Key = Right Then moveRight ElseIf Key = Left Then moveLeft End If ]

4 Mothod II: Use KeyPress Event Runs only when there is a keyboard interrupt KeyPressEvent(Key) If Key = Left Then MoveLeft ElseIf Key = Right Then MoveRight End If End Subroutine

5 WHAT’S THE DIFFERENCE BETWEEN METHOD I - METHOD II ?

6 Method I : Software Polling Method II : Event or Interrupt Driven

7 I/O Handling Techniques Software Polling Interrupts Direct Memory Access (DMA)

8 Benefits of Using Interrupts Consumes much less CPU  Especially when interrupt generated by hardware Cleaner & Simpler Code Allows Basic Parallel Processing

9 Exercise: Program a PIC Microcontroller Blink an LED every 0.5 sec Also receives serial data from the computer Available Commands  Getchar() – wait and return serial data  Output_toggle(LED)  Time() – returns current time (in ms)  Kbhit() – returns true if serial data is available

10 Solution Software Polling Int currentTime; Char data; startTime = time(); While (1) { if (time() – startTime > 500) { output_toggle(LED); startTime = time(); } if (kbhit()) { data = getchar(); }

11 Same Program with Timer Interrupt timerISR() { output_toggle(LED); } Main() { setupTimer(); while (1) { data = getchar(); }

12 Interrupt Handling

13 Multi-Interrupt Handling

14 Interrupt on the PIC16

15 Available Interrupts INT Pin Interrupt (external interrupt) TMR0 Overflow Interrupt PORTB Change Interrupt (pins RB7:RB4) Comparator Change Interrupt Parallel Slave Port Interrupt USART Interrupts Receive Interrupt Transmit Interrupt A/D Conversion Complete Interrupt LCD Interrupt. Data EEPROM Write Complete Interrupt Timer1 Overflow Interrupt Timer2 Overflow Interrupt CCP Interrupt SSP Interrupt

16 Interrupts on the PIC

17

18 #INT_RBvoid rb_isr(void) { /// interrupt code } Void main() { enable_interrupts(INT_RB); enable_interrupts(GLOBAL); /// main code }

19 Calling the correct ISR INT Boot Vector ISR Check which INT occurred Int Timer Int Serial Int I/O etc

20 Context Switching: How do switch to and from an interrupt PC Saved Automatically Other registers may need to be saved, but must be done in software.

21 Benefits of Programming in C Everything is done for you automatically!

22 DMA (Direct Memory Access) CPU I/O (e.g. Disk) RAM DMA Can send data directly to and from memory

23 Watching a Movie: How Does the Data Flow? CPU RAM Display

24 Summary

25 Analogy I: Hanging a Picture Frame

26 Analogy II: A Simple Game We need one volunteer The instructor will show a number to the class but hide it from the player We will simulate Polling, Interrupt, and DMA by playing this game.

27 5119313 171152319 146211610 42222524 72012818


Download ppt "Interrupts Microprocessor and Interfacing 261313."

Similar presentations


Ads by Google