星期五, 3月 06, 2009

EE3120 (B) MP & ASSEMBLY LANGUAGE PROG (02EE3120) Quiz 3 Solution

Quiz 3 (Total 60 marks)

1.

Show the stack and stack content for the following code:

003B 120300 LCALL DELAY
003E 80F0 BACK: SJMP BACK ;keep doing this
0040
0040 ;----------------------this is the delay subroutine
0500 ORG 500H
0500 DELAY:
0500 7DFF MOV R5,#0FFH ;R5=255
0502 DDFE AGAIN: DJNZ R5,AGAIN ;stay here
0504 22 RET ;return [10 marks]

Ans:
Stack /Stack Content

003B 120300 / 09 / 00 3E
003E 80F0 /07
0040 /?
0040 /?
0500 /09 /00 3E
0500 /09 /00 3E
0500 7DFF /09 /00 3E
0502 DDFE /09 /00 3E
0504 22 /07


2. Find the value (in hex) loaded into TH in each of the following.
(a) MOV TH0,#110
(b) MOV TH0,#-30
[10 marks]
(a) 6EH

(b) E2H


3. Given the LCD command write routine COMNWRT. Assume connections P2.1 = RS, P2.2 =R/W, P2.3 = E, write i) a program to call the display the data and ii) a subroutine to display the data (iii) the data "Hello" is checked again its completion of write by a busy flag connected to P2.7. Use the instruction MOVC.
.
[20 marks]
Ans:

MAIN:
MOV DPTR, #MYDATA
HERE:
CLR A
MOVC A, @A+DPTR
JZ DONE
ACALL DISPLAY_DATA
INC DPTR
SJMP HERE
DONE: SJMP DONE [10 marks]

DISPLAY_DATA:
ACALL READY
MOV P1,A ; port 1 fort DATA
SETB P2.1 ;RS=1 FOR Control DATA
CLR P2.2 ;R/W=0 FOR Control WRITE
SETB P2.3 ;H-TO-L FOR Control Enable
CLR P2.3
RET
READY:
SETB P2.7
CLR P2.1
SETB P2.2
BACK:
CLR P2.3
SETB P2.3
CLR P2.3
JB P2.7, BACK
RET [10 marks]

;P2.7=INPUT TO READ BUSY FLAG
;RS=0
;R/W=-1 FOR READ
ORG 300H
MYDATA: DB "Hello",0

ORG 400H
COMNWRT:
MOV P2,A
CLR P2.1
CLR P2.2
SETB P2.3
CLR P2.3
RET

4. Program Timer 1 to be an event counter. Use mode 2 and display the decimal count on P2, P1, and P0 continuously. Set the initial count to 55.
Ans:
MOV TMOD, #60h ; 0110 0000 [timer 1 c/t = 1 time 1 =1]
MOV TL1, #-55 ; count value
MOV TH1, #-55 ; preload
SETB P3.5
AGAIN: SETB TR1
BACK: MOV A, TL1
ACALL CONVERT
JNB TF1, BACK
CLR TR1
CLR TF1
SJMP AGAIN [10 marks]
;--This will convert from, binary (hex)
;to decimal and send each digit to the port
CONVERT:
MOV B,#10
DIV AB
MOV P0,B
MOV B,#10
DIV AB
MOV P1,B
MOV P2,A
RET [10 marks]

[20 marks]

沒有留言:

張貼留言