Figures 2.48 to 2.55 show the bit definitions of interrupt registers INTCON2, INTCON3, PIR1, PIR2, PIE1, PIE2, IPR1, and IPR2.
Figure 2.48: INTCON2 bit definitions
Figure 2.49: INTCON3 bit definitions
Figure 2.50: PIR1 bit definitions
Figure 2.51: PIR2 bit definitions
Figure 2.52: PIE1 bit definitions
Figure 2.53: PIE2 bit definitions
Figure 2.54: IPR1 bit definitions
Figure 2.55: IPR2 bit definitions
Examples are given in this section to illustrate how the CPU can be programmed for an interrupt.
Set up INT1 as a falling-edge triggered interrupt input having low priority.
The following bits should be set up before the INT1 falling-edge triggered interrupts can be accepted by the CPU in low-priority mode:
• Enable the priority structure. Set IPEN = 1
• Make INT1 an input pin. Set TRISB = 1
• Set INT1 interrupts for falling edge. SET INTEDG1 = 0
• Enable INT1 interrupts. Set INT1IE = 1
• Enable low priority. Set INT1IP = 0
• Clear INT1 flag. Set INT1IF = 0
• Enable low-priority interrupts. Set GIEL = 1
• Enable all interrupts. Set GIEH = 1
When an interrupt occurs, the CPU jumps to address 00008H in the program memory to execute the user program at the interrupt service routine.
Set up INT1 as a rising-edge triggered interrupt input having high priority.
The following bits should be set up before the INT1 rising-edge triggered interrupts can be accepted by the CPU in high-priority mode:
• Enable the priority structure. Set IPEN = 1
• Make INT1 an input pin. Set TRISB = 1
• Set INT1 interrupts for rising edge. SET INTEDG1 = 1
• Enable INT1 interrupts. Set INT1IE = 1
• Enable high priority. Set INT1IP = 1
• Clear INT1 flag. Set INT1IF = 0
• Enable all interrupts. Set GIEH = 1
When an interrupt occurs, the CPU jumps to address 000018H of the program memory to execute the user program at the interrupt service routine.
2.2 Summary
This chapter has described the architecture of the PIC18F family of microcontrollers. The PIC18F452 was used as a typical sample microcontroller in this family. Other members of the same family, such as the PIC18F242, have smaller pin counts and less functionality. And some, such as the PIC18F6680, have larger pin counts and more functionality.
Important parts and peripheral circuits of the PIC18F series have been described, including data memory, program memory, clock circuits, reset circuits, watchdog timer, general purpose timers, capture and compare module, PWM module, A/D converter, and the interrupt structure.
2.3 Exercises
1. Describe the data memory structure of the PIC18F452 microcontroller. What is a bank? How many banks are there?
2. Explain the differences between a general purpose register (GPR) and a special function register (SFR).