| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Technical Support On-Line Manuals C251 User's Guide | Interrupt FunctionsThe 251 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 80C251SB are listed in the following table:
As 251 vendors create new parts, more interrupts are added. The C251 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 data 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 C251 Compiler generates the interrupt vector automatically. The following example program demonstrates how to use the interrupt attribute. The program 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 void falarm (void) interrupt 1 using 3 {
5 1 alarm_count *= 10;
6 1 alarm = 1;
7 1 }
ASSEMBLY LISTING OF GENERATED OBJECT CODE
; FUNCTION falarm (BEGIN)
; SOURCE LINE # 4
000000 75D118 MOV PSW1,#018H
; SOURCE LINE # 5
000003 7E24000A MOV WR4,#0AH
000007 7E3500 R MOV WR6,alarm_count
00000A AD32 MUL WR6,WR4
00000C 7A3500 R MOV alarm_count,WR6
; SOURCE LINE # 6
00000F D200 E SETB alarm
; SOURCE LINE # 7
000011 32 RETI
; FUNCTION falarm (END)
In the example above, note that the PSW1 register is already saved by the 251 hardware interrupt. Note also the RETI instruction generated to exit the interrupt. The following rules apply to interrupt functions.
Note
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||