Setting Up Interrupts
By default at powerup, all interrupts are disabled. This means that even if, for example, the TF0 bit is set, the 8051 will not execute the interrupt. This program must specifically tell the 8051 that it wishes to enable interrupts and specifically which interrupts it wishes to enable.
Both of the above instructions set bit 3 of IE, thus enabling Timer 1 Interrupt. Once Timer 1 Interrupt is enabled, whenever the TF1 bit is set, the 8051 will automatically put "on hold" the main program and execute the Timer 1 Interrupt Handler at address 001Bh.
Thereafter, the Timer 1 Interrupt Handler at 01Bh will automatically be called whenever the TF1 bit is set (upon Timer 1 overflow).
Each of the 8051s interrupts has its own bit in the IE SFR. This will enable a given interrupt by setting the corresponding bit. For example, if it wish to enable Timer 1 Interrupt, this would execute either:
MOV IE, #08h
or
SETB ET1
However, before Timer 1 Interrupt (or any other interrupt) is truly enabled, it must also set bit 7 of IE. Bit 7, the Global Interupt Enable/Disable, enables or disables all interrupts simultaneously. That is to say, if bit 7 is cleared then no interrupts will occur, even if all the other bits of IE are set. Setting bit 7 will enable all the interrupts that have been selected by setting other bits in IE. This is useful in program execution if there is time-critical code that needs to execute. In this case, it may needed the code to execute from start to finish without any interrupt getting in the way. To accomplish this you can simply clear bit 7 of IE (CLR EA) and then set it after your time-criticial code is done.
So, to sum up what has been stated in this section, to enable the Timer 1 Interrupt the most common approach is to execute the following two instructions:
SETB ET1
SETB EA
Thereafter, the Timer 1 Interrupt Handler at 01Bh will automatically be called whenever the TF1 bit is set (upon Timer 1 overflow).
Your program may enable and disable interrupts by modifying the IE SFR (A8h):
Comments
Post a Comment