Tải bản đầy đủ (.pdf) (15 trang)

Tài liệu Thí nghiệm vi xử lý docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (313.28 KB, 15 trang )


1

TNVXL-ĐHBK TPHCM 2008
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟
Đọc liên tục trạng thái P1.0,P1.1,P1.2,P1.3 xuất ra P1.4,P1.5,P1.6,P1.7
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟
ORG 2000h
LOOP:
MOV C,P1.0
MOV P1.4, C
MOV C,P1.1
MOV P1.5,C
MOV C,P1.2
MOV P1.6, C
MOV C,P1.3
MOV P1.7, C
JMP LOOP
END
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟
1
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟
ORG 2000H
LAP : CPL P1.0
CALL DL
SJMP LAP
DL : PUSH 05H
PUSH 06H
PUSH 07H
MOV R5,#10
L2 : MOV R6,#100


L1 : MOV R7,#250
DJNZ R7,$
DJNZ R6,L1
DJNZ R5,L2
POP 07H
POP 06H
POP 05H
RET
END
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟
1Hz )
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟ „
ORG 2000H
LAP : CPL P1.0
CALL DL500
SJMP LAP
DL500: MOV TMOD,#01H;TIMER 0
PUSH 07H
MOV R7,#10
LOOP: MOV TH0,HIGH(-50000)
MOV TL0,HIGH(-50000)
SETB TR0
JNB TF0,$
CLR TR0
DJNZ R7,LOOP
POP 07H
RET
END

„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟



2

TNVXL-ĐHBK TPHCM 2008
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟
ORG 2000H
LJMP MAIN
ORG 200BH
LJMP ISRT0
MAIN: MOV TMOD,#01H;TIMER 0
PUSH 07H

LOOP: MOV TH0,HIGH(-50000)
MOV TL0,HIGH(-50000)
SETB TR0
MOV IE,#82H
SJMP $
ISRT0: DJNZ R7,THOAT
MOV R7,#10
CPL P1.0
THOAT: CLR TR0
MOV TH0,HIGH(-50000)
MOV TL0,HIGH(-50000)
SETB TR0
RETI
END
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟
Thí nghiệm thay đổi tần số P1.0 bằng P1.1(tăng) và P1.2(giảm)
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟

ORG 2000H
MOV 31H,#100;TAO XUNG 0.1Hz
MOV 32H,#20 ;TAO XUNG 0.5Hz
MOV 33H,#10 ;TAO XUNG 1Hz
MOV 34H,#5 ;TAO XUNG 2Hz
MOV 35H,#4 ;TAO XUNG 2.5Hz
MOV 36H,#2 ;TAO XUNG 5Hz
MOV TMOD,#01H
MOV R0,#33H
LOOP:
JNB P1.1,LOOP1 ;TANG TAN SO
JNB P1.2,LOOP2 ;GIAM TAN SO
CALL DELAY
CPL P1.0
SJMP LOOP
DELAY:
MOV A,@R0
LAP:
MOV TH0,#HIGH(-50000)
MOV TL0,#LOW(-50000)
SETB TR0
JNB TF0,$
CLR TF0
CLR TR0
DJNZ ACC,LAP
RET
LOOP1:
JNB P1.1,$
INC R0
CJNE R0,#37H,TANG

MOV R0,#33H
TANG:
SJMP LOOP

3

TNVXL-ĐHBK TPHCM 2008
LOOP2:
JNB P1.2,$
DEC R0
CJNE R0,#30H,GIAM
MOV R0,#33H
GIAM:
SJMP LOOP
END

„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟

2s
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟

ORG 2000H
LAP : MOV R0,#0
LOOP : MOV DPTR,#TABLE
MOV A,R0
MOVC A,@A+DPTR
INC R0
CALL DL
MOV DPTR,#0000H
MOVX @DPTR,A

CJNE R0,#0AH,LOOP
SJMP LAP

DL: MOV R5,#20
L2: MOV R6,#200
L1: MOV R7,#250
DJNZ R7,$
DJNZ R6,L1
DJNZ R5,L2
RET
TABLE:
DB 70H,71H,72H,73H,74H,75H,76H,77H,78H,79H

END


„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟

„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟
ORG 2000H
LAP: MOV R0,#0
LOOP: MOV DPTR,#TABLE
MOV A,R0
MOVC A,@A+DPTR
INC R0
CALL DL
MOV DPTR,#0000H
MOVX @DPTR,A
CJNE R0,#04H,LOOP
SJMP LAP

DL: MOV R6,#100
L1: MOV R7,#15
DJNZ R7,$
DJNZ R6,L1
RET

4

TNVXL-ĐHBK TPHCM 2008
TABLE:
DB 071H, 0B2H, 0D3H, 0E4H
END
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟
T
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟
Chuong trinh 1:
ORG 2000H
MOV R7,#0A0H
MOV A,R7
MOV B,#10
DIV AB
MOV R2,A
MOV A,B
ORL A,#0D0H
MOV R1,A
MOV A,R2
MOV B,#10
DIV AB
MOV R3,A
MOV A,B

ORL A,#0B0H
MOV R2,A
MOV A,R3
ORL A,#70H
MOV R3,A
MOV DPTR,#0000H
LAP: MOV A,R1
MOVX @DPTR,A
CALL DL
MOV A,R2
MOVX @DPTR,A
CALL DL
MOV A,R3
MOVX @DPTR,A
CALL DL
SJMP LAP
DL: MOV R4,#15
L11: MOV R5,#100
DJNZ R5,$
DJNZ R4,L11
RET
END
Chuong trinh 2:
ORG 2000H
LOOP:MOV R7,#0A0H
MOV A,R7
MOV B,#10
DIV AB
MOV R0,B
MOV B,#10

DIV AB
ORL A,#70H
ACALL GHI
MOV A,B
ORL A,#0B0H
ACALL GHI
MOV A,R0

5

TNVXL-ĐHBK TPHCM 2008
ORL A,#0D0H
ACALL GHI
SJMP LOOP
GHI:MOV DPTR,#0000H
MOVX @DPTR,A
RET
END
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟
ED. P1.0:Tăng, P1.1:Giảm
„‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟‟
ORG 2000H

DVI EQU 20H
CHUC EQU 21H
TRAM EQU 22H
MOV R0,#0
MOV R1,#0
MOV DPTR,#0000
AGAIN: JB P1.0,GIAM

JNB P1.0,$
INC R0
GIAM: JB P1.1 ,LOOP
JNB P1.1,$
DEC R0


LOOP: MOV A,R0
MOV B,#10
DIV AB
MOV DVI,B
MOV B,#10
DIV AB
MOV CHUC,B
MOV TRAM,A

MOV A,DVI
ORL A,#0E0H
MOVX @DPTR,A
ACALL DELAY1
MOV A,CHUC
ORL A,#0D0H
MOVX @DPTR,A
ACALL DELAY1
MOV A,TRAM
ORL A,#0B0H
MOVX @DPTR,A
ACALL DELAY1
SJMP AGAIN


DELAY1: MOV R6,#2
LOP: MOV R7,#250
DJNZ R7,$
DJNZ R6,LOP
RET

DELAY: MOV R5,#10
LOOP2: MOV R6,#200
LOOP1: MOV R7,#250

6

TNVXL-ĐHBK TPHCM 2008
DJNZ R7,$
DJNZ R6,LOOP1
DJNZ R5,LOOP2
RET


END
***********************************************************************

***********************************************************************
ORG 2000H
EN BIT P3.4
RS BIT P3.5

MAIN: MOV DPTR, #8000H
CALL LCD_INIT


MOV A,#'H'
CALL WRITE_TEXT
MOV A,#'e'
CALL WRITE_TEXT
MOV A,#'l'
CALL WRITE_TEXT
MOV A,#'l'
CALL WRITE_TEXT
MOV A,#'o'
CALL WRITE_TEXT

MOV A,#' '
CALL WRITE_TEXT
MOV A,#'W'
CALL WRITE_TEXT
MOV A,#'o'
CALL WRITE_TEXT
MOV A,#'r'
CALL WRITE_TEXT
MOV A,#'l'
CALL WRITE_TEXT
MOV A,#'d'
CALL WRITE_TEXT

SJMP $


LCD_INIT: ; LCD
MOV A,#38H
CALL WRITE_COM


MOV A,#0EH
CALL WRITE_COM

MOV A,#06H
CALL WRITE_COM
RET


WAIT_LCD:
DELAY: MOV R7, #100D

×