Unit-2-2 Mark
Unit-2-2 Mark
The first problem is that we wait for a „debounce‟ period in order to confirm that the switch has been
pressed:
DELAY_LOOP_Wait(DEBOUNCE_PERIOD);
31. Write program to create ‘hardware delays’ using Timer 0 and Timer 1. Write the syntax using
Timer 0 and Timer 1.
void DELAY_LOOP_Wait(const unsigned int DELAY)
{ unsigned int x, y;
for (x = 0; x <= DELAY; x++)
{
for (y = 0; y <= 120; y++);
}}
32. What are the timers used to create delay?
If you want to create more accurate delays, then we can do so using one of the 8051‟s on-chip
timers. These timers can be used to generate accurate delays.
o The TCON SFR
o The TMOD SFR
33. How to calculate hardware delays?
Building on the calculations of hardware delays generally takes the following form:
o We calculate the required starting value for the timer.
o We load this value into the timer.
o We start the timer.
o The timer will be incremented, without software intervention, at a rate determined by the
oscillator frequency; we wait for the timer to reach its maximum value and „roll over‟.
o The timer signals the end of the delay by changing the value of a flag variable.
34. What is SFR? (Or) Define SFR.
SFR stands for Special Function Register.
A Special Function Register or (Special Purpose Register or simply Special Register) is
a register within a microprocessor, which controls or monitors various aspects of the
microprocessor's function.
35. Draw the format of TCON SFR.
TCON SFR stands for TCON special function register (SFR). The various bits in the TCON SFR
have the following functions:
This loop will keep running until the variable Timeout_loop reaches its maximum value (assuming
16-bit integers) of 65535, and then overflows. When this happens, the program will continue.
44. What is Hardware Timeouts? (Nov/Dec 23)
Consider the ability to meet real-time requirements by code without timeouts and code with a loop
timeout; it is clear that the loop timeout solution is significantly better.
Loop timeouts are particularly well suited to applications involving long timeout delays (typically
measured in seconds).
Where we require shorter delays, with very precise timing, we can often gain a further improvement
in performance through the use of hardware-based timeouts.
45. What is Interrupt Service Routine (ISR)?
An interrupt service routine (ISR) is a software routine that hardware invokes in response to
an interrupt.
ISRs examine an interrupt and determine how to handle it. ISRs handle the interrupt, and then
return a logical interrupt value.
46. Write an example code for automatic timer reloads.
In the hardware delay code, we used a code structure like this:
// Preload values for 50 ms delay
TH0 = 0x3C; // Timer 0 initial value (High
Byte) TL0 = 0xB0; // Timer 0 initial value (Low
Byte) TF0 = 0; // Clear overflow flag
TR0 = 1; // Start timer 0
while (TF0 == 0); // Loop until Timer 0 overflows (TF0 ==
1) TR0 = 0; // Stop Timer 0