Page 141 - Programming Microcontrollers in C
P. 141
126 Chapter 3 What Are Microcontrollers?
The process of saving the status of the machine is to push the
contents of all machine registers onto the machine stack. Therefore,
the ISR can safely use any of the central machine resources without
disrupting the operation of the main line of code when control is
returned. When exiting an ISR, it is necessary to use a special
instruction called a return from interrupt or a return from exception.
This instruction restores the status of the machine from the stack and
picks up execution of the code from the instruction following the one
where the interrupt occurred.
The third means for exiting the main loop of the program is from
internal interrupts. The microcontroller peripherals can often cause
interrupts to occur. An internal interrupt causes exactly the same
sequence of operations to occur as an external interrupt. Different
interrupt vectors are used for each of the several internal peripheral
parts so the cause of the interrupt is generally known and control is
directed to the specific ISR for each of the several possible internal
interrupts.
Data are transferred, information is passed, or events are handled
either synchronously or asynchronously. The difference between these
two methods of data transfer has mainly to do with how the clocking
of the data is handled. The most common form of synchronous data
transfer is with a three-wire serial link. One of the wires is a clock,
and the other two are input data and output data, respectively. For a
synchronous transfer, the value of the input is usually sampled at one
edge of the clock signal (such as the fall of the clock) and the value
of the bit to be sent out is guaranteed to be correct at the fall of the
clock signal. Any synchronous system must set its output at such a
time that it will be stable while the clock is high, and hold it in that
condition until the clock signal falls. To receive a bit, the condition
of the input line must be latched into the system as the clock signal
falls from high to low.
Within the computer, there is another distinction for synchronous.
Often an input is allowed to set a bit when it occurs. If this happens,
the program will not expeditiously observe the fact that the bit is set.
In fact, the program will test the state of the bit according to the
program timing requirements. This type of operation is also called
synchronous because the test is synchronized with the program.
Asynchronous operation, on the other hand, usually depends on a
prearranged series of events to cause the data transfer. Serial data