Interrupts Microprocessor and Interfacing 261313.
-
Upload
donald-hensley -
Category
Documents
-
view
229 -
download
2
Transcript of Interrupts Microprocessor and Interfacing 261313.
Interrupts
Microprocessor and Interfacing261313
Example: Writing a Game
Need to Check Keyboard Input
Method 1: Using a LoopProgram keeps checking for keyboard input
While (1) [ If Key = Right Then
moveRight ElseIf Key = Left Then moveLeft End If]
Mothod II: Use KeyPress EventRuns only when there is a keyboard interrupt
KeyPressEvent(Key) If Key = Left Then MoveLeft ElseIf Key = Right Then MoveRight End If End Subroutine
WHAT’S THE DIFFERENCE BETWEEN
METHOD I - METHOD
II ?
Method I : Software Polling
Method II : Event or Interrupt Driven
I/O Handling Techniques
Software Polling
Interrupts
Direct Memory Access (DMA)
Benefits of Using Interrupts
Consumes much less CPU Especially when interrupt generated by hardware
Cleaner & Simpler Code
Allows Basic Parallel Processing
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
Solution Software PollingInt currentTime;
Char data;
startTime = time();
While (1) {
if (time() – startTime > 500) {
output_toggle(LED);
startTime = time();
}
if (kbhit()) {
data = getchar();
}
}
Same Program with Timer InterrupttimerISR() {
output_toggle(LED);
}
Main() {
setupTimer();
while (1) {
data = getchar();
}
}
Interrupt Handling
Multi-Interrupt Handling
Interrupt on the PIC16
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
Interrupts on the PIC
Interrupts on the PIC
#INT_RBvoid rb_isr(void) { /// interrupt code}
Void main() {enable_interrupts(INT_RB); enable_interrupts(GLOBAL);
/// main code
}
Calling the correct ISR
INTBoot Vector
ISRCheck which INT occurred
Int TimerInt SerialInt I/Oetc
Context Switching: How do switch to and from an interrupt
PC Saved Automatically
Other registers may need to be saved, but must bedone in software.
Benefits of Programming in C
Everything is done for you automatically!
DMA (Direct Memory Access)
CPU
I/O(e.g. Disk)
RAMDMA
Can send data directly to and from memory
Watching a Movie:How Does the Data Flow?
CPU
RAM
Display
Summary
Analogy I: Hanging a Picture Frame
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.
5 11 9 3 13
17 1 152319
14 6 211610
4 22 2 2524
7 2012 8 18