Interrupts Microprocessor and Interfacing 261214 Example Writing a
- Slides: 15
Interrupts Microprocessor and Interfacing 261214
Example: Writing a Game Need to Check Keyboard Input
Method 1: Using a Loop Program keeps checking for keyboard input While (1) [ If Key = Right Then move. Right Else. If Key = Left Then move. Left End If ]
Mothod II: Use Key. Press Event Runs only when there is a keyboard interrupt Key. Press. Event(Key) If Key = Left Then Move. Left Else. If Key = Right Then Move. Right 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 What’s wrong with this program? While (1) { output_toggle(LED); delay_ms(500); data = getchar(); }
A better program, but not best While (1) { output_toggle(LED); delay_ms(500); if (kbhit()) { data = getchar(); } }
How do we fix the problem? 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 Polling Int current. Time; Char data; start. Time = time(); While (1) { if (time() – start. Time > 500) { output_toggle(LED); start. Time = time(); } if (kbhit()) { data = getchar(); } }
Same Program with Timer Interrupt timer. ISR() { output_toggle(LED); } Main() { setup. Timer(); while (1) { data = getchar(); } }
Interrupt Handling
Multi-Interrupt Handling
- 261214
- Microprocessor and interfacing darshan pdf
- Microprocessor programming tutorial
- Adc and dac interfacing
- What is intr in microprocessor
- Lcd and keyboard interfacing
- What is peripheral and interfacing
- Microcontroller interfacing to dac
- Adc and dac interfacing with 8051
- Impersonal writing style
- Difference between bios and dos interrupts
- Cara kerja polling adalah
- Bios interrupts
- Dos bios interrupts
- 8086 interrupts and interrupt responses
- He highest priority interrupt of 8051 is?