0% found this document useful (0 votes)
107 views8 pages

8051 Assembly Brief

1. The document provides details for an exam on microcomputer systems including 6 questions ranging from writing 8051 programs to calculating baud rates from given code snippets. 2. Question 2 asks to generate a 440Hz tone using Timer 0 Mode 1 and calculates the exact output frequency and crystal value needed. Question 3 uses Timer 0 Mode 2 to continuously transmit ASCII codes from the serial port. 3. Question 6 calculates the baud rates for 3 code snippets using different Timer 1 modes and serial port configurations, obtaining rates of 625, 375k, and 110 baud respectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views8 pages

8051 Assembly Brief

1. The document provides details for an exam on microcomputer systems including 6 questions ranging from writing 8051 programs to calculating baud rates from given code snippets. 2. Question 2 asks to generate a 440Hz tone using Timer 0 Mode 1 and calculates the exact output frequency and crystal value needed. Question 3 uses Timer 0 Mode 2 to continuously transmit ASCII codes from the serial port. 3. Question 6 calculates the baud rates for 3 code snippets using different Timer 1 modes and serial port configurations, obtaining rates of 625, 375k, and 110 baud respectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

( A)

90,1,10

Assume the original crystal is fosc = 12 MHz


1. Write an 8051 program for the flowchart shown in Box. 1. (10%)
2. The international tuning standard for musical instruments is A above middle C at a frequency of 440
Hz. Write an 8051 program to generate this tuning frequency and sound a 440 Hz tone on a
loudspeaker connected to P0.4 using Timer 0 Mode 1. Due to rounding of the values placed in
TL0/TH0, there is a slight error in the output frequency. What is the exact output frequency? What
value of crystal would yield exactly 440 Hz with the program you have written? (20%)
3. Write an 8051 program to continually send the displayable ASCII (codes 20H to 7EH) to the device
attached to the 8051 serial port (using Serial Port Mode 0) as shown in Box. 3. Each code is display
about 0.5 sec, which is implemented by Timer 0 Mode 2. (15%)

page 2-1

Box. 3

Box. 1

page 2-2

page 2-3

4. Write an 8051 program to create 8-channel


waves as shown in Box. 4 based on the
given basic clock, which is a 500 Hz square
wave generated by Timer 1 Mode 0 and
using interrupt. Hint: you may use the
lookup table concept. (20%)

Box. 4

repeat
basic clock
(for reference)
output to P1.0
output to P1.1
output to P1.2
output to P1.3
output to P1.4
output to P1.5
output to P1.6
output to P1.7

5. Given 44 push-down on keypad (name key 0~9, A~F) connected respectively to the P1.0~P1.7, and
a 7-segment LEDs (common-cathode) connected to the P0.0~P0.7. Design the circuit and write the
8051 program such that the key number can be obtained from the 16 keys and display on the 7segment LEDs when any key is pressed and a falling-edge trigger occurs at the external interrupt 1. If
any 20-msec delay program is required, using Timer 0 Mode 1. Note that you should solve the
bouncing problem when any key is pressed. (30%)
6. Compute the baud rate for the given program shown in Box. 6(a), 6(b), and 6(c). (15%)

Box. 6(a)
MOV
TMOD, #20H
MOV
SCON, #40H
MOV
PCON, #80H
MOV
TH1, #9CH
SETB
TR1

Box. 6(b)
MOV
TMOD, #20H
MOV
SCON, #90H
MOV
PCON, #80H
MOV
TH1, #FEH
MOV
TL1, #0CH
SETB
TR1

page 2-4

Box. 6(c)
MOV
TMOD, #10H
MOV
SCON, #50H
MOV
PCON, #00H
MOV
TH1, #FEH
MOV
TL1, #E4H
SETB
TR1


1. (10%)
Find:
Next:

Other:
Exit:

MOV
R7, #8
DEC
R7
RRC
A
CJNE R7, #0, Other
JMP
Exit
JNC
Next
(Continued)

2. (a) (12%)
Because f = 440 Hz Time (high) = Time (low) = 1136.364 sec
And we use Timer 0 Mode 1,
Then we have TH0 = (65536 - 1136) / 256 = 251 and TL0 = (65536 - 1136) % 256 = 144.
The program is as follows:

Loop:

Here:

MOV
TMOD, #01H
MOV
TH0, #251
MOV
TL0, #144
SETB TR0
JNB
TF0, Here
CPLP0.4
CLR
TR0
CLR
TF0
SJMP Loop

; Timer 0, 16-bit timer mode


; 2 cycles, load values
; 2 cycles
; 1 cycle, start timer
; 2 cycles, wait for overflow
; 1 cycle, toggle output
; 1 cycle, stop timer
; 1 cycle, clear overflow flag
; 2 cycles, repeat
; total 12 cycles overhead

(b) (4%)
f(exact) = fosc / {12[2(1136 + 12)]}= 435.54 Hz
(c) (4%)
440Hz = fosc(crystal) / {12[2(1136 + 12)]} new fosc(crystal) = 12.122880 MHz

page 2-5

3. (15%)
Because of using Serial Port Mode 0 and Timer 0 Mode 2, we let TH0 = #200
The program is as follows:

Start:

Next:
Wait:

Delay:
Next1:
Wait1:

ORG
JMP
MOV
MOV
MOV
MOV
MOV
JNB
CALL

0000H
Start
SCON, #00H
TMOD, #02H
TH0, #200
A, #20H
SBUF, A
TI, Wait
Delay

; Serial Port Mode 0


; Timer 0 Mode 2, 8-bit auto-reload timer
; Reload value
; Begin ASCII code = 20H
; Transmit
; Check TI flag
; Delay 25100200 sec 0.5 sec

INC
A
CJNE A, #80H, Next
(Continued)

; Next
; Until ASCII code = 7FH

CLR
MOV
MOV
SETB
JNB
CLR
DJNZ
DJNZ
CLR
RET

; Clear TI flag

TI
R7, #25
R6, #100
TR0
TF0, Wait1
TF0
R6, Wait1
R7, Next1
TR0

; Start Timer 0

; Disable Timer 0

END

page 2-6

4. From the given waveforms, we may design 8 patterns to construct the waveform.
Because f = 500 Hz Time (high) = Time (low) = 1000 sec
And we use Timer 1 Mode 0,
Then we have TH0 = (8192 - 1000) / 32 = 224 and TL0 = (8192 - 1000) % 32 = 24.
The program is as follows:

Main:

Here:

ORG
JMP
ORG
JMP
ORG
MOV
MOV
MOV
SETB
SJMP

0000H
Main
001BH
T1ISR
0030H
TMOD, #00000000B
IE, #10001000B
R0, #0
TF1
Here

T1ISR: CJNE
MOV
Output: MOV
CALL
MOV
INC
MOV
MOV
CLR
SETB
RETI

R0, #8, Output


R0, #0
A, R0
Pattern
P1, A
R0
TH1, #224
TL1, #24
TF1
TR1

Pattern: INC
MOVC
RET
DB
DB
DB
DB
DB
DB
DB
DB
END

A
A, @A+PC
01110001B
01001101B
00010111B
10101010B
10110010B
01001101B
00010111B
10001110B

; Timer 1 interrupt service routine

; Timer 1 Mode 0
; Enable Timer 1 interrupt
; Initialize waveform pattern index
; Force Timer 1 interrupt
; Do nothing
; The pattern index < 8
; Reset the pattern index
; Call Lookup Table
; Output the current pattern
; For next index
; Preload value for Timer 1
; Clear Timer overflow flag
; Start Timer

; The pattern form is constructed


; according to the high/low displayed on
; the given waveforms of Box. 4.

page 2-7

5. (30%, Circuit Design 10%, Program 20%)

Not Provided (Because this topic is related to the final project).


6.
(a) (5%) Serial Port Mode 1, Timer 1 Mode 2, SMOD = 1. Variable baud rate
Baud rate

21
12 10 6

625
32 12 256 156

(b) (5%) Serial Port Mode 2, Timer 1 Mode 2, SMOD = 1. Fixed baud rate
Baud rate

21
12 10 6 375000 375k
64

(c) (5%) Serial Port Mode 1, Timer 1 Mode 1, SMOD = 0. Variable baud rate
Baud rate

20
12 10 6

110
32 12 65536 65252

page 2-8

You might also like