Microprocessors: From Assembly Language to C Using thePIC18Fxx2

This chapter discusses interrupts, which are of critical importance when implementing efficient input/output operations for microcontroller applications. Topics include interrupt fundamentals, PIC18 interrupt sources, and software techniques for implementing interrupt-driven IO. A first look at the powerful timer subsystem of the PIC18 uses a timer as a periodic interrupt source.
After reading this chapter, you will be able to:
Discuss the general function of interrupts within a microprocessor, and interrupt implementation on the PIC18.
Describe the difference between polled IO and interrupt-driven IO.
Implement an interrupt service routine in C for the PIC18.
Write C functions for performing interrupt-driven asynchronous serial IO.
Implement software FIFO buffering for interrupt-driven IO.
Implement an interrupt service routine using a state machine approach.
Discuss the structure of the PIC18 Timer2 subsystem and use it to generate periodic interrupts.
Implement an interrupt-driven interface for a rotary encoder.
Implement an interrupt-driven interface for a keypad.
An interrupt in a microprocessor is a forced deviation from normal program flow by an external or internal event. On the PIC18 are many possible internal and external events such as rising or falling edges on external pins, arrival of serial data, timer expiration, and so forth that can cause interrupts. Figure 10.1 illustrates what happens when an interrupt occurs on the PIC18. During normal program flow, assume some external or internal event triggers an interrupt. After the current instruction is finished, the BSR, W, and STATUS registers are saved in the...