直接访问寄存器和端口
定义
sfr P0 0x80
sfr P1 0x81
sfr ADCON; 0xDE
sbit EA 0x9F
操作
ADCON = 0x08;
P1 = 0xFF;
io_status = P0 ;
EA = 1;
在使用了interrupt 1 关键字之后,会自动生成中断向量
在 ISR中不能 与其他 “后台循环代码”(the background loop code) 共享局部变量,因为连接器会复用 在RAM中这些变量的位置 ,所以它们会有不同的意义,这取决于当前使用的不同的函数复用变量对RAM有限的51来讲很重要。所以,这些函数希望按照一定的顺序执行 而不被中断。
void timer0_int(void) interrupt 1 using 2
{
unsigned char temp1;
unsigned char temp2;
executable C statements;
}
“interrupt”声明表向量生成在(8*n+3),这里,n就是interrupt参数后的那个数字这里,在08H的代码区域 生成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-criticalroutines. Note that interrupts of the same priority can share a register bank, since there is no risk that they will interrupt each other.
“using” 告诉编译器 在进入51danpi中断处理器 去切换寄存器的bank。这个”contet”切换是为中断处理程序的局部变量提供一个新鲜的寄存器bank最快的方式。对时序要求严格的程序,是首选的stack寄存器(保存寄存器到stack)方式。
注意:同样优先级别的中断可以共享寄存器bank,因为他们每次将中断没有危险。