中断号及interrupt和using(中断号及中断和使用)
A, interrupt
External interrupt 00
T0 timer 1
External interrupt 12
T1 timer 3
Serial port 4
Two, interrupt and using in the C51 interrupt
Including the basic structure of the MCU 8051 ries: 32 I/O port (4 group 8 bit port); two 16 bit timer counter; full duplex rial communication; 6 interrupt sources (2, 2 external interrupt timer / Counter interrupt, 1 rial input / output interrupt, interrupt priority level two); 128 the built-in RAM 64K byte byte; independently addressable data and code. Interrupt occurred, MCU turned to the 5 interrupt at th
e entrance of the interrupt rvice and then execute the corresponding processing program. Interrupt address program entrance by the compiler in the interrupt vector, the interrupt vector at the lowest address located in the program code, note the rial input / output interrupt sharing an interrupt vector. 8051 the interrupt vector table as follows:
Interrupt vector interrupt source
The power on ret 0000H
External interrupt 0 0003H
Timer 0 overflow 000BH
External interrupt 1 0013H
Timer 1 overflow 001BH
Serial port interrupt 0023H
Timer 2 overflow 002BH
Direct access to register and port Definition
SFR P0 0x80
SFR P1 0x81
SFR ADCON; 0xDE
Sbit EA 0x9F
operation
ADCON = 0x08;
P1 = 0xFF;
Io_status = P0;
EA = 1;
In the u of the interrupt keyword 1, will automatically generate the interrupt vector
Not in the ISR and other "background cycle code" (the background loop code) shared local variables
Becau the connector will reu the variables at the position of RAM, so they will have different meanings, depending on the current u of different function
Reu variables of RAM will be important to a limited 51. Therefore, the functions in order to perform a certain hope without interruption.
Timer0_int (interrupt) 1 using 2
{
Unsigned char temp1;
Unsigned char temp2;
Executable C statements;
}
The "interrupt" statement (8*n3), vector generation in here, the digital n is interrupt after parameters
Here, such an instruction in the 08H region of code generation LJMP timer0_int
"Using" tells the compiler to switch register banks on entry to an interrupt routine. This "context" switch is the fastest way of providing a fresh registerbank for an interrupt routine's local data and is to be preferred to stacking registers for very time-critical routines. Note that interrupts of the same priority can share a register bank, since there is no risk that they will interrupt each other.
'using'tells the compiler in the interrupt handler to switch register bank. This is the "contet" switch
Provide a fresh bank register the fastest way for the local variables of the interrupt handler. The timing requirements of strict procedures, is the first choice of the stack register (register stack) mode.
Note: the same priority interrupt can share register bank, becau they will interrupt each other without danger
If a USING is added to the Timer1 1 interrupt function prototype, the pushing of registers is replaced by a simple MOV to PSW to switch registerbanks. Unfortunately,
当一个中断入口被加速,直接寻址使用登记进入sys_interp失败。这是因为C51没有告诉寄存器bank已经改变。如果不使用工作寄存
器和没有其他的函数被调用时,优化器eliminiates德码开关登记银行。
如果在Timer1的中断函数原型中使用使用1,寄存器的推将被MOV PSW切换寄存器银行所替换。
不幸的是,当一个中断入口被加速时用在入口的直接寄存器寻址将失败。
这是因为C51没有告诉寄存器银行已经改变。如果不工作的寄存器将被使用,如果没有其他函数被调用,优化器.....
从逻辑上讲,一个中断服务程序,不能传递参数或返回。当中断发生时,编译器插入的代码被运行,它将累加器,B,DPTR和PSW(程序状态字)到堆栈。最后,在退出中断程序,预先存储在栈中被恢复,关闭“}”引起的视网膜被使用而不是一个正常的退役
逻辑上,一个中断服务程序,不能传递参数进去,也不可返回值。
当中断发生时,编译器插入的代码被运行,它将累加器,B,DPTR和PSW(程序状态字)入栈。最后,在退出中断程序时,预先存储在栈中被恢复。最后的“}”结束符号
将插入RETI到中断程序的最后,
为了用keil'c”语言创建一个中断服务程序(ISR),利用中断关键词和正确的中断号声明一个静态函数。keil'c”编译器自动生成中断向量,以及中断程序的进口、出口代码。中断函数属性标志着该函数为ISR。可用使用属性指定ISR使用哪一个寄存器区,这是可选的有效的寄存器区范围为到3 1。