Download presentation
Presentation is loading. Please wait.
1
Interrupts Microprocessor and Interfacing 261313
2
Example: Writing a Game Need to Check Keyboard Input
3
Method 1: Using a Loop Do If GetKeyState(vbKeyRight) Then moveRight ElseIf GetKeyState(vbKeyLeft) Then moveLeft End If Loop
4
Mothod II: Use KeyPress Event KeyPressEvent(KeyAscii As Integer) If KeyAscii = LeftKey Then MoveLeft ElseIf KeyAscii = RightKey Then MoveRight End If End Sub
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_high(LED), Output_low(LED) Time() – returns current time (in ms) Kbhit() – returns true if serial data is available
10
Solution Int currentTime; Char data; startTime = time(); While (1) { if (time() – startTime > 500) { blink_LED(); startTime = time(); } if (kbhit()) { data = getchar(); }
11
Same Program with Timer Interrupt timerISR() { blinkLED(); } Main() { setTimer(); data = getchar(); }
12
Interrupt Handling
13
Multi-Interrupt Handling
14
Interrupt on the PIC
15
Available Interrupts Include 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
DMA (Direct Memory Access) CPU I/O (e.g. Disk) RAM DMA Can send data directly to and from memory
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.