354 39 Solutions Instructor Manual 11 Hardware Features 8051 Chapter 11
Short Description
microcontroller ppt...
Description
Microprocessors and Microcontrollers
Kumar, Saravanan & Jeevananthan
Chapter 11 Hardware features of 8051 Solution to Numerical/DESIGN‐BASED EXERCISE: 1. Show the circuit connections for interfacing 16K of EPROM IC 27128 and 8 K of RAM IC 6264 with the 8051.
The first step in interfacing is to select or fix the address range for the chips to be used. As the 27128 has 16 KB of memory registers, it requires 14 address lines to select one memory location in it. The address map of the 27128 is fixed as 0000H–3FFFH. The address range for the 8KB RAM chip 6264 is selected as C000H–DFFFH. The most significant bits A14 and A15 are used to decode and select the chip. For decoding purposes, a 2‐to‐4 decoder chip, the 74139, is used. The 74319 has a dual 2‐to‐4 decoder and one of them is used for selecting the EPROM chip. Bits A14 and A15 are at logic 0 for the EPROM chip and the Y0 output is made active low for the corresponding A14 and A15 inputs. This Y0 signal is used as the active low chip select input of the IC 27128.
© Oxford University Press 2011
9‐1
Microprocessors and Microcontrollers
Kumar, Saravanan & Jeevananthan
Bits A14 and A15 are at logic 1 for the RAM chip and the Y3 output is made active low for the A14 and A15 inputs as logic high. This Y3 signal is used as the active low chip select input of the IC 6264. The connection diagram is shown in Figure. The 8‐bit latch or register IC 74373 is used to de‐multiplex the lower‐order address and data bus. OE is the data read enable line of the 27128 and is connected to the PEN signal output of the 8051. The data read enable line of the 6264 is OE, which is connected to the P3.7 port output of the 8051. Similarly, the write enable input 6264 is connected to the port line P3.6 of the 8051. Solutions to THINK AND ANSWER Exercises 1. What are the conditions for external memory access in the 8051?
Connecting the EA pin of the 8051 to logic 1 or +5 V will program the microcontroller to use the internal program memory for the addresses starting at 0000H. After the available internal memory is addressed, then the external memory is accessed. Connecting EA pin to logic 0 will make the microcontroller use only external memory for all the addresses starting from 0000H. 2. What is the purpose of multiplexing the lower‐order address bus with the data bus for external memory access?
The purpose of multiplexing is to reduce the pin count and reduce the number of pins required. 3. What are the advantages of separate data and program memory (Harvard architecture)?
The separate data and program memory increases the memory addressing capability of the microcontroller. Moreover, as the program and data are separate, the chance of erasing of program memory by mistake as data is removed. 4. Write a delay routine for 1 ms using Timer 0 of the 8051, for 12 MHz crystal frequency.
© Oxford University Press 2011
9‐2
Microprocessors and Microcontrollers
Kumar, Saravanan & Jeevananthan
The clock frequency to counter is 12MHz/12; the counter will get the clock pulses at the 1 MHz rate. So, the counter will be incremented every 1 µs. The program uses 16-bit counter mode. The timer should produce a delay of 1000 µs. So, the 16bit counter must be initialized to 64535 (i.e., 65535 - 1000). The hexadecimal equivalent of this decimal value is FC17. Therefore, the lower-order eight bits of the timer are initialized to 17H and the higher-order eight bits to FCH.
The following DELAY subroutine uses the polled method of waiting for 1msec and then returns to main program.
DELAY:
LOOP:
WAIT:
MOV TMOD, #00000001B CLR TF0 MOV TH0, #0FCH MOV TL0, #17H SETB TR0 JNB TF0, WAIT CLR TR0 CLR TF0 RET
; Set Timer 0 in mode 1 (16-bit operation). ; Clear the Timer 0 overflow flag. ; Initialize the 16 bits of Timer 0 with the appropriate value. ; Start or run Timer 0 by setting the TR0 bit. ; Read, check, and loop until the overflow bit TF0 in TCON register is set. ; Clear the overflow flag.
5. Write a routine using a timer of the 8051 to count the cars moving on a road and to give a signal when the count value reaches 100. To count the external pulses, Timer 1 is initialized as a counter by setting the D6 bit of TMOD. Mode 1 of Timer 1 is used in this example, as 100 objects are to be counted and this can be accomplished by the 8‐bit timer auto reload mode. Timer 1 is loaded with the value 155 (i.e., 255 ‐ 100), which in hexadecimal form is 9B. This gives an interrupt after 100 counts. The program is written in two parts. The main program initializes the timer and runs it. After that, the main program does nothing. Detecting the count value of 100 is
© Oxford University Press 2011
9‐3
Microprocessors and Microcontrollers
Kumar, Saravanan & Jeevananthan
done automatically, by generating an interrupt and then giving logic 1 output on port pin is done in the Interrupt service routine. Main program: MAIN: MOV TMOD, #01110000B ; Set Timer 1 in mode 1 (counter operation). MOV TH1, #09BH
; Load the Timer 1 count.
MOV IE, #10001000B
; Enable Timer/Counter 1 interrupt
SETB TR1
; Start Timer/Counter 1.
LOOP: LJMP LOOP ; Loop and do nothing. Interrupt service routine: ISR_TIMER1:
; Stop Timer 1 to be safe.
SETB P1.0
; Set high LSB of P1.
RETI
; Return from interrupt.
CLR TR1
6. Write the Interrupt Priority word for making serial port and external interrupt 1 as high priority and other interrupts as low priority ones. Interrupt Priority word format Bit
D7
D6
D5
D4
D3
© Oxford University Press 2011
D2
D1
D0
9‐4
Microprocessors and Microcontrollers
Kumar, Saravanan & Jeevananthan
position Name
EA
‐
‐
PS
PT1
PX1
PT0
PX0
1
0
0
1
0
1
0
0
Explanatio n
Enable Interrupt s— Made 1 to enable all interrupt s
Undefine d
Set Serial interrup t as high priority
Timer 1 interrup t priority
Set Extern al 1 interrup t as high priority
Timer 0 interrup t priority
Extern al 0 interrup t priority
Undefine d
Corresponding Interrupt priority word is 94H. 7. Write the control word for masking external interrupts in an 8051‐based system. Interrupt Enable Register format Bit
D7
D6
D5
D4
D3
D2
D1
D0
Name
EA
‐
‐
ES
ET1
EX1
ET0
EX0
1
0
0
1
1
0
1
0
position
Explanatio
Disable Global
Enable
Enable
n
Disable Enable
externa interrupt
Undef
Undefine
serial
Timer 1
enable/
ined
d
interru
interru
externa Timer 0
l 1
l 0 interru
interru disable
pt
pt
interru pt
pt
pt
8. Write the control word format for setting the serial port in mode 1.
© Oxford University Press 2011
9‐5
Microprocessors and Microcontrollers
Kumar, Saravanan & Jeevananthan
Bit patterns for SCON register Bit Name Value
D7 SM0
Explanation of function
0 Serial port mode select bits
D6 SM1
1
D5 SM2
0
Multiprocessor communications enable bit
D4 REN
1
Receiver enable — This bit must be set, to receive characters.
D3
TB8
0
Transmit bit 8 — The 9th bit to transmit in modes 2 and 3
D2 RB8
0
Receive bit 8 — The 9th bit received in modes 2 and 3
D1
TI
0
Transmit Interrupt flag — Set when a byte has been completely transmitted
D0
RI
0
Receive Interrupt flag — Set when a byte has been completely received
Corresponding SCON value is 01010000B i.e. 50H. 9. Calculate the reload value of Timer 1 for achieving a baud rate of 4800 in the 8051, for a crystal frequency of 11.0592 MHz. The relation between the baud rate and the TH1 timer reload value is given below. TH1 = 256 ‐ ((Clock frequency/384)/Baud) if SMOD in PCON SFR is 0. TH1 = 256 ‐ ((Clock frequency/192)/Baud) if SMOD in PCON SFR is 1 Accordingly, for 4800 baud rate, the reload value is F9H if SMOD bit is 0 and F3H if SMOD bit is 1.
© Oxford University Press 2011
9‐6
Microprocessors and Microcontrollers
Kumar, Saravanan & Jeevananthan
10. Write an 8051 ALP to transmit ‘Hello World’ serially at 9600 baud for a crystal frequency of 11.0592 MHz. Following program assumes that the ASCII code for the characters ‘Hello World’ are stored consecutively in the internal memory 40H onwards. MAIN:
; Set up Timer 1 to drive baud rate of 9600.
MOV TMOD, #00100000B; Set Timer 1 in mode 2 (8‐bit timer). MOV TH1, #0FDH SETB TR1
; Time Timer 1 for 9600 baud. ; Enable Timer 1 for free run.
MOV SCON, #01000000B; Initialize serial port for mode 1 operation.
MOV R0, #40H
; Initialize memory pointer.
MOV R1, #0BH
; Intialize a counter for the number of
characters in the words ‘Hello World’. SEND: MOV SBUF,@R0
; Get the data from memory and send it to SBUF for
transmission. LOOP: JNB TI, LOOP
; Test TI flag to check whether data has been sent.
CLR TI
; Clear TI.
INC R0
; Point to the next data.
DJNZ R1, SEND
; Loop again to send data, if not completed.
END
© Oxford University Press 2011
9‐7
Microprocessors and Microcontrollers
Kumar, Saravanan & Jeevananthan
© Oxford University Press 2011
9‐8
View more...
Comments