For the PIC microcontroller, the whole process of interrupt activity can be roughly summarized into 9 stages:
1. Interrupt Request: Interrupt Events Once the interrupt condition is constituted, the interrupt source submits the "Application Report" (the interrupt flag position 1), and the CPU is requested to temporarily put down the current work and turn to the interrupt source as a special service;
2, interrupt mask: Although the interrupt source submits the "Application Report", whether it is obtained by the CPU response, but also depends on whether the "application report" can be delivered to the CPU through 2 or 3 "level" (interrupt shield). The corresponding interrupt shield is equal to 1, which is released for the level; the corresponding interrupt shield is equal to 0, which is prohibited by the level);
3, interrupt response: If all the way is released, the CPU responds to the interrupt, record the interrupted work breakpoint (protect the breakpoint address to the stack), hang "no longer accepting other application reports" (clear global interrupt " Sign bit GIE = 0), jump to the interrupt service subroutine;
4. Protection site: It is possible to destroy the original work on the site when dealing with new tasks, so it is necessary to properly protect the work site and working environment;
5. Survey is the source: Check "Application Report" is submitted by the interrupt source in order to make targeted services;
6, interrupt processing: Start a targeted interrupt service to identify the interrupt source;
7. Clear flag: After the corresponding task is processed, you need to cancel the registration (clear interrupt flag) to avoid repeated response;
8. Restore the site: Restore the work site that has been protected in front to continue to perform the work being interrupted;
9. Interrupt return: Retrieve the broken work breakpoint (restore the breakpoint address from the stack), and pick up the "no additional application report" (GIE = 1), continue to execute the original interrupted work.
In the 9 stages described above, the first, 2, 3 and 9 stages are automatically implemented by hardware, while the tip of the 4, 5, 6, and 7, and the user software is done.
The interrupt source of the PIC16F877 single-chip microcomputer is more than 14, but the interrupt vector has only one (0004H), and there is no priority between the respective interrupt sources, and does not have a non-mask interrupt (i.e., all interrupts can be shielded). The PIC-series microcontroller with interrupt function is a multi-source interrupt design (ie, an interrupt vector corresponds to a plurality of interrupt sources), only one interrupt vector, or only one interrupt service subroutine entry address.
references:
Li Xuehai "PIC single-chip practical tutorial - basics" Beijing Aerospace University Air Publishing House