|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Technical Support On-Line Manuals Cx51 User's Guide |
Interrupt FunctionsThe 8051 and its derivatives provide a number of hardware interrupts that may be used for counting, timing, detecting external events, and sending and receiving data using the serial interface. The standard interrupts found on an 8051/8052 are listed in the following table:
As 8051 vendors create new parts, more interrupts are added. The Cx51 Compiler supports interrupt functions for 32 interrupts (0-31). Use the interrupt vector address in the following table to determine the interrupt number.
The interrupt function attribute specifies that the associated function is an interrupt service routine. For example:
unsigned int interruptcnt;
unsigned char second;
void timer0 (void) interrupt 1 using 2 {
if (++interruptcnt == 4000) { /* count to 4000 */
second++; /* second counter */
interruptcnt = 0; /* clear int counter */
}
}
The interrupt attribute takes as an argument an integer constant in the 0 to 31 value range. Expressions with operators and the interrupt attribute are not allowed in function prototypes. The interrupt attribute affects the object code of the function as follows:
In addition, the Cx51 Compiler generates the interrupt vector automatically. The following sample program demonstrates how to use the interrupt attribute. The program also shows you what the code generated to enter and exit the interrupt function looks like. The using function attribute is used to select a register bank different from that of the non-interrupt program code. However, because no working registers are needed in this function, the code generated to switch the register bank is eliminated by the optimizer.
stmt level source
1 extern bit alarm;
2 int alarm_count;
3
4
5 void falarm (void) interrupt 1 using 3 {
6 1 alarm_count *= 2;
7 1 alarm = 1;
8 1 }
ASSEMBLY LISTING OF GENERATED OBJECT CODE
; FUNCTION falarm (BEGIN)
0000 C0E0 PUSH ACC
0002 C0D0 PUSH PSW
; SOURCE LINE # 5
; SOURCE LINE # 6
0004 E500 R MOV A,alarm_count+01H
0006 25E0 ADD A,ACC
0008 F500 R MOV alarm_count+01H,A
000A E500 R MOV A,alarm_count
000C 33 RLC A
000D F500 R MOV alarm_count,A
; SOURCE LINE # 7
000F D200 E SETB alarm
; SOURCE LINE # 8
0011 D0D0 POP PSW
0013 D0E0 POP ACC
0015 32 RETI
; FUNCTION falarm (END)
In the example above, note that the ACC and PSW registers are saved at offset 0000h and restored at offset 0011h. Note also the RETI instruction generated to exit the interrupt. The following rules apply to interrupt functions.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.