Professional Documents
Culture Documents
Maszidi Q and Ans
Maszidi Q and Ans
SUMMARY
The 8051 has two timers/counters. When used as timers they can generate time delays. When used as counters th
can serve as event counters. This chapter showed how to program the timers/counters for various modes. they
The two timers are accessed as two 8-bit registers: TL0 and THO for Timer 0, and TL1 and TH1 for Timer1 R
th
timers
use
the set timer operation modes. The lower 4 bits of TMOD are used for Timer 0
TMOD register to
upper 4 bits are used for Timer1.
andte
There are different modes that can be used for each timer. Mode 0 sets the timer as a 13-bit timer, mode 1
sets it as
a 16-bit timer, and mode 2 sets it as an 8-bit timer.
When the timer/counter is used as a timer, the 8051's crystal is used as the source of the frequency; when it is used
as a counter, however, it is a pulse outside the 8051 that increments the TH, TL registers.
PROBLEMS
SECTION 9.1: PROGRAMMING 8051 TIMERS
1. What is the difference between the operation of a timer and a counter?
2. The timers of the 8051 are -bit and are designated as. and
3. The registers of Timer 0 are accessed as and
4. The registers of Timer 1 are accessed as .
and
5. In Questions 3 and 4, are the registers bit-addressable?
6. The TMOD register is a(n) -bit register.
7. What is the function of the TMOD register?
8. True or false. TMOD is a bit-addressable register.
9. Find the TMOD value for both Timer 0 and Timer 1, mode 2, software start /
from the 8051's crystal.
stop (gate =
0), with the clock comirg
10. Find the frequency and period used by the timer if the crystal attached to the 8051 has the following values.
(a) XTAL = 11.0592 MHz (b) XTAL = 20 MHz
(c) XTAL = 24 MHz (d) XTAL = 30 MHz
is
11. What the difference in the timer lengths in modes 0, 1, and 22
12. Indicate the rollover value (in hex and decimal) of the timer for each of the following modes.
(a) mode 0 (b) mode 1 (c) mode 2
13. Indicate when the TF1 flag is raised for each of the following modes.
(a) mode 0 (b) mode 1 c) mode 2
14. In which register do we find the timer start bits and timer rollover flags?
15. True or false. Both Timer 0 and Timer 1 have their own timer start (TR).
16. Find the delay for XTAL = 22 MHz, if the program segment for timing is
MOV TMOD, #01
MOV THO, #0FFH
MOV TLO, #00
SETB TRO
17. Assuming that XTAL 16
=
MHz, indicate when the TF0 flag is raised for the following program.
MOV TMOD, #01
MOV TLO, #12H
mode 1.
TH1,TL1 value to generate a time delay of 5 ms. Timer 1 is programned n
wave frequency that we can generating a square wave on pin P1.2, find the highest square
generate using mode 1.
27. Assuming that XTAL 16 MHz, and we are =
40. Find the value (in hex) loaded into TH in each of the folowing.
TEMS
SUMMARY
This chapter began with an introduction to the fundamentals of serial communication. Serial communication
which data is sent one bit a time, is used when data is sent over significant distances since in parallel communication
where data is sent a byte or more a time, great distances can cause distortion of the data. Serial communication has tha
additional advantage of allowing transmission over phone lines. Serial communication uses two methods: synchrono
and asynchronous. In synchronous communication, data is sent in blocks of bytes; in asynchronous, data is sent in bytes
Data communication can be simplex (can send but cannot receive), half duplex (can send and receive, but not at the same
time), or full duplex (can send and receive at the same time). R$232 is a standard for serial communication connectors
The 8051's UART was discussed. We showed how to interface the 8051 with an RS232 connector and change the
baud rate of the 8051. In addition, we described the serial communication features of the 8051, and programmed the
8051 for serial data communication. We also showed how to program the second serial port of the DS89C4x0 chip in
Assembly and C.
PROBLEMS
SECTION 10.1: BASICS OF SERIAL COMMUNICATION
1 What is the advantage of serial communications over parallel communications?
2.
Distinguish between half duplex and full duplex mode of communications.
3. of the letter ASCII "Z" (0101 1010), no parity, 1 stop bit.
4.
Show the framing
If there is no data transfer and the line is high, it is
5.
called
True or false. The stop bit can be 1, 2, or none at all.
(mark, space).
6. Distinguish between synchronous and asynchronous data transfer.
Which are the voltage levels used in R$232C?
8. What is the function of the MAX 232 chip?
9 True or false. DB-25 and DB-9 are pin compatible for the first 9 pins.
10. How many pins of the R$232 are used by the IBM serial cable, and why?
11. Which are the minimum signals required in serial data transmission?
12. State the absolute minimum number of signals needed to transfer data between two PCs connected serially. What
are those signals?
13. If two PCs are connected through the R$232 without the modem, they are both configured as a (DTE,
DCE) -to (DTE, DCE) connection.
14. State the nine most important signals of the R$232.
15. Calculate the total number of bits trarnsferred if 200 pages of ASCII data are sent using asynchronous serial data
transfer. Assume a data size of 8 bits, 1 stop bit, and no parity. Assume each page has 80x25 of text characters.
16. In Problem 15, how long will the data transfer take if the baud rate is 9,600?
pins.
For the MAX233, indicate the
21.
Vcc and GND pins.
What is the advantage of
using the MAX233 from Maxim?
22. State the
advantages and disadvantages of the MAX232 and MAX233.
23. MAX232/233 has line driver(s) for the RxD wire.
266 1S
THE 8051 MICROCONTROLLER AND EMBEDDED SYSTEM>
24. MAX232/233 has line
25. Show the connection
driver(s)
of pins TxD for the TxD wire.
and RxD of the 8051 to a DB-9 RS232 connector via the second set of line drivers
of MAX232.
ak drivers
Show theof connection
MAX233, of the TxD and RxD pins of the 8051 to a DB-9 RS232 connector via the second set of line
26
a7 Show the connectionof the TxD and RxD pins of the 8051 to DB-25 RS232 via
connector via
Show the connection of the TxD and RxD pins of the 8051 to aa DB-25 RS232 connector MADD. MANLO
28.
instruction?
the rate of data transfer.
45. To which register does the SMOD bit belong? State its role in
46. Is the SMOD bit high or low when the 8051 is powered up?
compatible
not with the COM ports of the PC (x86 IBM/compatible).
following questions the baud rates
are
In the
16 MHz and SMOD 0.
Find the baud rate for the following if XTAL =
=
47.
(a) MOV TH1,#-10 (b) MOV TH1, #-25
() MOV TH1, #-200 (d) MOV TH1, #-180 loaded with -10?
TH1
the baud rate if is
8. For XTAL of frequency 22 MHz, what is
a
=1.
16 MHz and SMOD
Find the baud rate for the following if XTAL
=
49.
(b) MOV TH1,#-25
(a) MOV TH1, #-100
(d) MOV TH1,#-180
(c) MOV TH1, #-200
transfer be doubled?
. How can the baud rate of data
PORT
PROGRAMMING THE SECOND SERIAL
SECTION 10.4:
with a second serial port.
which comes
1. Timer 1
2 Pins P1.2 and P1.3
3. -1 of FFH
SBUF1
Serial Control 1, 8
5.
6. SCON1
SECTION 10.5: SERIAL PORT PROGRAMMING INC KT
D
O (D .
(D
P CO
Whatare the
contents of the IE
1 wthe instruction
to enable
register upon reset, and what do these values mean?
Show
the EX1 and Timer 1
Show the instruction to enable every interrupt of theinterrupts.
12
Write program
a using
of 3 kHz. P2 while Timer 1 is turning on and off the LED
data from Pl and send it to
48 Write a program using interrupts get
to
second.
Connected to P0.4 every
IN 295
TERRUPTs PROGRAMMING IN ASSEMBLY AND C
49. Write a program to generate a rising edge once, when a high-to-low transition is reveived on INTO
50. What is the method to disable all interrupts?
51. Which interrupts are latched, low-level or edge-triggered?
52. Which register keeps the latched interrupt for INT and INTI?
Make sure that the low pulse applied to pin INT1 is no wider than 4 machine cvcles. Or, make sure that the NTI
in is brought back to high by the time the
pin. 8051 executes the RETI instruction in the ISR.
False. There is no need tor the "CLR TCON. 0" since the RETI instruction does that for us.
S. TCON.0 is set to high to make INTO an edge-triggered interrupt. If INTO is edge-triggered (that is, TCON.O
whenevera high-to-low pulse is applied to the INTO pin it is captured (latched) and kept by the TCON.21sDitSet),
Dy
making TCON.2 high. While the ISR for INTO is being serviced, TCON.2 stays high no matter how many
H-to-L pulse is applied to pin INTO. Upon the execution of the last instruction times an
of the ISR, which is RETI, the TCON.2
bit is cleared, indicating that the INTO pin can respond
to another interrupt.
SECTION 11.4: PROGRAMMING THE SERIAL COMMUNICATION INTERRUPT
1 True. here is only one interrupt for both the transfer and receive.
2 23H
3 Bit D4 (E.4) and "MOV IE, #10010000B" will enable the serial interrupt.
4 The RI (received interrupt) flag is raised when the entire frame of data, including the stop bit, is received. As a result
the received byte is delivered to the SBUF register and the 8051 jumps to memory location 0023H to execute the ISR
belonging to this interrupt. In the serial cOM interrupt service routine, we must save the SBUF contents before it is
lost by the incoming data.
5. False
6. True. We must do it since the RETI instruction will not do it for the serial interrupt.
7 CLR TI
RETI
297
INTERRUPTS PROGRAMMINGIN ASSEMBLY ANDC
Review Questions
1. True or false. To see if any key is pressed, all rows are grounded.
2. IfD3 DO 0111 is the data read from the columns, which column does the pressed key belong to?
3. True or false. Key press detection and key identification require two different processes.
4. In Figure 12-6,if the rowsare D3 - D0 = 1110 and the columns are D3 DO = 1110, which key is pressed?
5. True or false. To identify the pressed key, one row at a time is grounded.
SUMMARRY
This chapter showed how to interface real-world devices such as LCDs and
the
keypads to the 8051. First, we de a
operation modes of LCDs, then described how to program the LCD by sending data or commands to it via ite
face to the 8051. inter.
Keyboards are one of the most widely used input devices for 8051 projects. This chapter also described tho .
ation of keyboards, including key press and detection mechanisms. Then the 8051 was shown
board. 8051 progranms were written to return the ASCII code for the interfacing with
pressed key. key.
PROBLEMS
SECTION 12.1: LCD INTERFACING
1. Which are the two
registers in the LCD module?
2. How can data be transferred to the LCD from a port using only 4 port lines?
3. To display letters and numbers, we send data
in_ code.
4. "Clear LCD" is a (command code, data item) and its value is
5. What is the hex value of the command code for
hex.
6.
"display on, cursor on"?
Which are the control pins of the LCD? What are their functions?
7.Give the state of RS, E, and R/W when
8.Which of the following is needed on the E
sending data character Z" to the LCD.
pin in order for a command code (or data) to be latched in by the LCD?
(a) H-to-L pulse (b) L-to-H pulse
9. How does the LCD
10. How does the
distinguish between data and command?
busy flag aid in making the LCD program more efficient?
11. For a 16x2 LCD, the location of the last character of
line 1 is 8FH (its command code). Show how this value was
calculated.
12. For a 16x2 LCD, the location of the first
character of line 2 is COH (its command code). Show how this value was
calculated.
13. For a 20x2 LCD, the location of the last character of line 2 is
93H (its command code). Show how this value was
calculated.
14. For a 20x2 LCD, the location of the third character of line 2 is C2H
(its command code). Show how this value was
calculated.
15. For a 40x2 LCD, the location of the last character of line 1 is A7H (its command code). Show how this value was
calculated.
16. For a 40x2 LCD, the location of the last character of line 2 is E7H (its command code). Show how this value was
calculated.
17. Show the value (in hex) for the command code for the 10th location, line 1 on a 20x2 LCD. Show how you got your
value.
18. Show the value (in hex) for the command code for the 20th location, ine 2 on a 40x2 LCD. Show how you got your
value.
19. Rewrite the COMNWRT subroutine. Assume connections P1.4 = RS, P1.5 = R/W, P1.6 = E.
20. Repeat Problem 19 for the data write subroutine. Send the string "Hello" to the LCD by checking the busy flag Use
the instruction MOVC.
MS
318 THE 8051 MICROCONTROLLER AND EMBEDDED SYSTEM
23. In Figure
(a) all rowws
l2-6,
t identify
the key presned, whieh of the following le groundecdr
(b) one row at timee (c) both (a) and (b)
4, For Figure 12-6, indicate the
(a) D3 - DO =0111 column and row for each of thhe following
(b) D3 D0 = 1110
a Indicate the steps to detect the key press.
26. Indicate the steps to identify the key pressed.
27. We need to operate a key in the interrupt mode. How should the key be
28. Ifa switch is connected to pin P3.2, what happens when the switch connected?
is pressed and a low Is recelved on the pin
1. Input
2. Input
3. H-to-L
4. High
5. 80H and COH
319
ROARRINTERFACING
for (y=0; y<1275;Y++)
++)
Review Questions
1. True or false.
2. The
The LM35 provides
3.
transducer must be
4.
The LM34 provides connected to signal
mV for
5.
Why do we set
the
each
mV for each degree of conditioning circuitry
ircuitry before it is sent to the
4, whatV,.of
In
Question is the ADCO848 to 2.56 V ifdegree
the
of .
to
(Fahrenheit, Celsius) temperature
te sADC.
temperature if the ADC analog (Fahrenheit, Celsius) temperature.
input is connected to the
output is 0011 1001? LM35?
SUMMARY
This
First, we chapter showed how to
discussed interface real-world
in both both parallel and devices such as DAC
we Assembly and C. serial ADC
studied sensors. We Next we explored the DAC chips, then described how tochips, ADC chips, and sensors to
also discussed chip, and showed how tointerface them to the 8051 and the 51.
conditioning, an essential feature of datathe relation between the interface it to the 8051. In program it
acquisition systems. analog world and digital device, and described
a the last section
signal
PROBLEMS
SECTION 13.1: PARALLEL
AND SERIAL ADC
1. Write a
program segment to
2. To access the chip, what generate the start conversion
3. The logic level should be pulse for ADC0804. Use
4.
ADC0804 is
What is
a evel
bit should
ADC.
given on
on tthe CS line of
ADC0804?
pin P1.0.
the function of the
5. Write a EOC pulse?
program segment to check if the ADC
6. Give a more
7. In the
efficient way of using the EOC has finished conversion.
ADC0804, what should be the output line of the ADC.
8. In the
ADC0804, what should be the V/2 value for a step size of 20
mV?
9. In the V,/2
ADC0804, what is the role of pins value for a step size of 5 mV?
step size of 19.53 mV, what is the V,+)
10. With a and V, (-?
11. With
V,/2= 0.64 V, find the Vn for the analog input voltage if all outputs are 1?
(a) D7 -DO 11111111= following outputs.
(b) D7 -D0 10011001
=
(c) D7 - DO = 1101100
12. Assume that the EOC
to the 8051?
pin of the ADC 0804 is connected to pin P3.2 of the
8051. How is the ADC
output transferred
352
THE 8051 MICROCONTROLLER AND EMBEDDED SYSTEMS
hich of the tollowin8 ADC sizes provide the best resolution?
(a)8-bit (b) 10-bit (c) 12-bit
(d) 16-bit (e) They are all the same.
4 estion 13, which provides the smallest step size?
In Ques.
Calculate the step size for the following ADCs, if Vis 5V.
(a)8-bit (b) 10-bit (c) 12-bit (d) 16-bit
rue or talse. ADCO8O08/0809 is an:8-bit ADC.
Indicate the out) for each of the following ADC0808/0809
direction (in, pins.
(a)SC (b) EOC (c) A, B, C
(d) ALE (e) OE () INO - IN7
(g) DO- D7
to select channel analoE pu
5
ENplain the role of the ALE pin in the ADCO808/0809 and show how value if we want the following sizes:
the ADCUSUB70809, assume V,-) Gnd. Give the V(+) voltage
=
In
(a) 20 mV b)5 mV (c) 10 mV
(d) 15 mV (e) 2 mV (f) 25 mV
following values of V,+)
In the ADCOSOS/0809, assume V-)= Gnd. Find the step size for the
(a) 1.28 V b) 1 V (c)0.64 V
different from ADCO804?
1 In what way is the ADCO808channel selected?
2. How is a particular analog
need of ALE on this chip? of the ADC0808. What
should
23 What is the
thatpins PO.0 to PO.2 of the 8051 is connected to pins A, B and C, respectively
4 Assume
be the values on the port pins to select.
(b)IN4 (c) IN7?
(a) INO
the importance of the OE pin? function in the ADC0848?
5 What isADCO848, INTR is an_ -(input, output) signal. Whatis its
26. In the size for each of the following Ver
ADCO848 chip, find the step
27. For an ()Ve1.9V
(a)V1.28 V (b) VPe1V 20 mV?
value if we want a step size of
ADCO848, what should be the V size of 5 mV?
28. In the if we want a step
ADC0848, what should be the Vvalue
29. In the channel selected?
how is the analog are 1?
30. In the ADC0848, what is the analog input voltage if all outputs
size of 19.53 mV,
31. With a step for the following outputs.
1.28V, find the V
1101100
(c) D7- D0
=
32. With V =
11111111 b) D7- D0
= 10011001
(a) D7- DO
=
ADC.
MAX1112 is a n 8-bit MAX1112 pins.
33. True or false.
direction (in, out) for each of the following
34. Indicate the (c) COM
b) DOUT
(a) CS CHANO - CHAN7
(d) DIN
(e) SCLK (
MAX1112 ADC?
(g) SSTRB has the
inputs digital outputs
and
5. How many analog does a serial
ADC offer?
36. What advantage inbuilt ADC. externally.
members with REFIN provided
Name two 8051 family each of the following
37. find the step size
for
(c) REFIN
=1.9 V
38. For MAX1112 chip, (b) REFIN =1V
V
(a) REFIN 1.28 =
channel selected? size of 5 mV?
MAX1112, how is the analog value if w e want
a step
In the the REFIN
9. what should be outputs. 1101100
In the MAX1112, for the following D7 D0
0.
=
V (c)
-
find the
W i t h REFIN
1.28 V, =
D7 D0
10011001
of the SCLK signal.
edge/negative edge)
=
(b)
-
REFOUT?
recognize c o n n e c t e d to
AGND with
How do we -CHAN7?
size if REFINis reference for CHANO
is the step is used for ground
What which pin
mode,
30. In single-ended
INTERFACING
SENSOR
ADC, DAC, AND
SECTION 13.2: DAC INTERFACING
SIGNAL CONDITIONING
SECTION 13.3: SENSOR INTERFACING AND
1. True
2. 10, Celsius.
3. 10, Fahrenheit. 10 mV. LM35 10 mV for eac
256 steps, and 2.56 V/256
=
produces
4 Since ADC0848 is an 8-bit ADC, it gives us
ADC's step size.
degree of temperature which matches the
5. 00111001 = 57, which indicates it is 57 degrees.
EMBEDDED SYSTEM
THE 8051 MICROcONTROLLER AND
354
With the
(e) DRAM A0 nll,1, D0
DO D7 --
(6)
UV-EPROM
EPROM Ao. A1 following
lowing pins.
A10, DO A0 A12, D0 -D7 pins.
-
(d) SRAM
(g)EEPROM
-
A0 A0 - A12, DO D7
A11, DO -D07 ()
)DRAM (h)SRAMA
-
-
A0 A12, DO
A8,
-
A10, DO--D7
D7
D7
following
-
(c) 64 Kx 16 ROM
7
17 Find the checksum (b) 32K x 8 ROMmemory chips.
(d) 256
For each of the byte for these bytes: 34H,4 RAM x
any member of the 8051 family, if EA Gnd the microcontroller fetches program code TOm
external ROM. r
=
385
8051 INTERFACING TO EXTERNAL MEMORY
be changed, if external program ROM is to be added ,
31. Which pin connection of the 8051 has to
liu
36.
between ALE 0 and ALE 1.
= =
DS89C4x0, = 0?
external
dat.
ACCESSING
from
S E C T I O N 14.5: of data The e x t e r n a l
transfer 20 bytes to
external
RAM.
in C to at 60H. data RAM
Write a program RAM starts internal
60. and internal
data from The exter
is 2000H, bytes of external
data RAM.
address t r a n s f e r 30 ROM to
m in S to arts at 40H. l data
ANSWERS TO REvIEW
QUESTIONS
SECTION 14.1: SEMIcONDUCTOR
C MEMORY
(a) 16Kx8, 128K bits
3. (a) 2Kx1, 21 bits (b) 64Kx8, 512K
(b) 8Kx4, 32K (c) 4Kx8, 32K
(d) 64Kx4, 256K (c) 128Kx8, 1M
(a) 64K bits, 14 address, (e) 256Kx1, 256K
and () 256Kx4, 1M
(c) 1M, 10 address, and 1 4 data (b) 256K, 15 address, and 8 data
(e) 512K, 16 address, and data
8 (d) 1M, 18 address, and 4 data
data
5. b, c () 4M, 10 address, and 4 data
4 PO
5 PO
b. P2
7. True
DATA MEMORY SPACE
SECTION 14.4: 8051
1. 128K
External
3. True external data memory
we
PROBLEMS
SECTION 17.1: RELAYS AND OPTOISOLATORS
1. Can a relay have normally open (NO) as well as normally closed (NC) contacts?
2. How does a reed switch work?
21. Which motor is best for moving a wheel exactly 90 degrees? motor?
and current of a DC
between the load, torque,
2. What is the relationship for no-load and loaded.
of a DC motor is the same
3 True or false. The
in
rpm
data sheets is for
(no-load, loaded).
The rpm given motors over AC
motors?
45.What is the advantage of DC
over DC motors? fixed.
of stepper motors to the motor are
b. What is the advantage
motor slows it down if
the current and voltage supplied
DC
7. True or false. Higher load
on a
control automatically the speed
of a DC motor?
microcontroller be used to
26. How can a
451
AND STEPPER MOTORS
MOTOR CONTROL: RELAY, PWM, DC,
29. Name two microcontrollers with in-built PWM circuitry.
30. What is the
advantage of placing an optoisolator between the motor and the microcontroller?