Bài báo cáo môn Vi xử lý
QUANG BÁO:
ORG 2000H
START: CLR 74H
CLR 75H
MOV P1,#0FFH
MOV A,#0FFH
LCALL HT_COT
MOV A,#0FFH
LCALL HT_HANG
JB P1.2,START
;-------------------------------------------------------------------------
; 2 bit 74H ,75H trong vung RAM noi dung lam bit kiem tra
;-------------------------------------------------------------------------
TT: MOV R4,#30
MOV DPTR,#CHAR+85
MOV R6,DPL
;--------------------------------------------------------------------------
;R6 chua gia tri vi tri cuoi cung khi dich sang phai
;--------------------------------------------------------------------------
MOV DPTR,#CHAR+7
MOV R7,DPL
;--------------------------------------------------------------------------
;R7 chua gia tri vi tri cuoi cung khi dich sang trai
;--------------------------------------------------------------------------
MOV DPTR,#CHAR
MOV R2,DPH
MOV R3,DPL
LOOP: MOV DPH,R2
MOV DPL,R3
CALL HTHI
DJNZ R4 , LOOP
;------------------------------------------------------------------------------------
;qua trinh lap lai de xuat 1 ki tu ra led ma tran
;-----------------------------------------------------------------------------------
JB P1.1 , NHAY1
JNB P1.1,$
CPL 75H
NHAY1: MOV R4,#30
JNB 75H , NHAY2
MOV R4,#60
T_TINH ; hien thi gia tri TIEN len LCD MOV 6AH,#32 MOV 70H , #13 MOV 71H , #'a' MOV R1,#40 JJJ: MOV A,#8 CALL SEND DJNZ R1,JJJ MOV R1,#50H TT4: MOV A,@R1 CJNE A,#'a',GUI1 SJMP KT GUI1: CALL SEND INC R1 SJMP TT4 KT: JB P1.7 , CHAYR LJMP MAIN ;------------------------------------------------ ; nut P1.7 dung lam nut chuyen lai che do ban dau ;----------------------------------------------- CHAYR: MOV DPTR,#4000H MOV A,#0 MOVX @DPTR,A ACALL DELAY_100US MOVX A,@DPTR ;-------------------------------------------------- ; doc lai gia tri gia san pham tu ADC de kiem tra xem gia tri nay co thay doi khong ;------------------------------------------------ MOV 2DH,A ADD A,#2 CLR C SUBB A,2CH ; gia tri doc duoc tu ADC truoc do ta da luu vao o nho 2CH JC NHAYK MOV A,2DH CLR C SUBB A,#2 SUBB A,2CH JNC NHAYK ;--------------------------------------------------------- ;do ADC doc gia tri khong duoc chuan nen ta chap nhan gia tri doc duoc van khong doi neu (25H)-5 < gia tri doc duoc < (25H)+5 ;--------------------------------------------------------- JB P1.0, NHAYT JNB P1.0,$ INC 1AH LJMP LAPLAI1 NHAYT: JB P1.1, KT JNB P1.1,$ CLR C MOV A,1AH SUBB A,#1 MOV 1AH,A JNC NHAYK MOV 1AH,#0 ;---------------------------------------------------------------------- ;kiem tra xem co tang giam gia tri KL ;----------------------------------------------------------------------- NHAYK: LJMP LAPLAI1 ; quay lai chuong trinh LAPLAI1 de dieu chinh thay doi ;----------------------------------- ;tinh toan gia tri TIEN ;----------------------------------- TINH: MOV 11H,#5 MOV A,1AH MOV B,1BH MUL AB MOV 1DH,A MOV 1EH,B MOV R0,#40H LOOP9: MOV 2AH,#200 MOV 2BH,#0 LOOP7: MOV A,1EH JZ TTUC LOOP6: MOV A,1DH CLR C SUBB A,1CH MOV 1DH,A MOV A,1EH SUBB A,#0 MOV 1EH,A DJNZ 2AH,NHAY5 INC 2BH MOV 2AH,#200 NHAY5: SJMP LOOP7 TTUC: MOV A,1DH CJNE A,1CH,TT TT: JNC LOOP6 INC R0 MOV @R0,A MOV A,#200 MOV B,2BH MUL AB MOV 1EH,B MOV 1DH,A MOV A,#200 CLR C SUBB A,2AH ADD A,1DH MOV 1DH,A MOV A,1EH ADDC A,#0 MOV 1EH,A DJNZ 11H , LOOP9 RET ;---------------------------------------- ;xuat gia tri tien ra ;-------------------------------------- HT_TINH: MOV 46H,#5 MOV R0,#45H MOV R1,#65H MOV R2,#0C6H LAP: MOV A,R2 CALL INIT_LCD MOV A,@R0 ORL A,#30H CALL WRITE_TEXT MOV @R1,A INC R1 DEC R0 INC R2 DJNZ 46H,LAP RET ;---------------------------------- ;hien thi gia tri kluong ;---------------------------------- HTHI: MOV A,1AH MOV B,#10 DIV AB MOV R3,B MOV B,#10 DIV AB MOV 1FH,A MOV A,#88H CALL INIT_LCD MOV A,1FH ORL A,#30H CALL WRITE_TEXT MOV 58H,A MOV A,#89H CALL INIT_LCD MOV A,B ORL A,#30H CALL WRITE_TEXT MOV 59H,A MOV A,#8AH CALL INIT_LCD MOV A,R3 ORL A,#30H CALL WRITE_TEXT MOV 5AH,A CALL DELAY RET ;---------------------------------- ;doc don gia tu ADC ;---------------------------------- ADC: MOV DPTR,#4000H MOV A,#0 MOVX @DPTR,A ACALL DELAY_100US MOVX A,@DPTR MOV 1BH,A MOV 2CH,A MOV DPTR,#8000H MOV B,#10 DIV AB MOV R0,B MOV B,#10 DIV AB ORL A,#30H ACALL WRITE_TEXT MOV @R1,A INC R1 MOV A,B ORL A,#30H ACALL WRITE_TEXT MOV @R1,A INC R1 MOV A,R0 ORL A,#30H ACALL WRITE_TEXT MOV @R1,A INC R1 RET ;---------------------lenh khoi tao chuong trinh START: MOV A,#38H CALL INIT_LCD MOV A,#0CH CALL INIT_LCD MOV A,#06H CALL INIT_LCD MOV A,#01H CALL INIT_LCD MOV A,#80H CALL INIT_LCD RET ;-----------doi LCD WAIT_LCD: MOV R7,#4 BB: MOV R6,#250 DJNZ R6,$ DJNZ R7,BB RET ;------------xuat lenh INIT_LCD: MOV DPTR,#8000H LCALL WAIT_LCD CLR RS MOVX @DPTR,A SETB EN CLR EN RET ;------------xuat ki tu WRITE_TEXT: MOV DPTR,#8000H LCALL WAIT_LCD SETB RS MOVX @DPTR,A SETB EN CLR EN RET ;-----------tra bang TRABANG: MOV DPTR,#TABLE MOVC A,@A+DPTR RET TRABANG2: MOV DPTR,#TABLE2 MOVC A,@A+DPTR RET ;----------------tao tre thoi gian DELAY: MOV 0FH,#5 LOOP5: MOV TH0,#HIGH(-50000) MOV TL0,#LOW(-50000) SETB TR0 JNB TF0,$ CLR TF0 CLR TR0 DJNZ 0FH,LOOP5 RET DELAY_100US: MOV 10H,#200 DJNZ 10H,$ RET ; gui ra cong noi tiep SEND: JNB TI,SEND MOV SBUF,A CLR TI RET TABLE: DB 'KLUONG: GIA: 000 SET' TABLE2: DB 'KL: GIA:000TIEN: RUN' END ĐỒNG HỒ ORG 0000H LJMP MAIN ORG 000BH LJMP ISR_T0 MAIN: MOV TMOD,#21H MOV TL1,#-3 MOV TH1,#-3 MOV SCON,#52H SETB TR1 MOV P1,#0FFH RS BIT P3.5 EN BIT P3.4 MOV R1,#0 MOV R2,#0 MOV R3,#0 MAIN1: MOV 5AH,R1 MOV 5BH,R2 MOV 5CH,R3 CLR ET0 MOV DPTR,#8000H CALL START MOV R0,#16 MOV A,#0 PUSH ACC LOOP3: CALL TRABANG1 CALL WRITE_TEXT POP ACC INC A PUSH ACC DJNZ R0,LOOP3 ;------------------------------------------------ ;xuat dong chu ' BAN MUON CAI DAT ' ;------------------------------------------------ ACALL HIENTHI1 ;------------------------------------------------ ;xuat '00:00:00' ;------------------------------------------------ ACALL CAI_DAT ;------------------------------------------------------------------ ;goi chuong trinh cai dat voi cac nut dieu khien P1.2 , P1.3 , P1.4 ;------------------------------------------------------------------ MOV R1,5AH MOV R2,5BH MOV R3,5CH MOV DPTR,#8000H ACALL START ;----------------------------------------------------------------- ;chuong trinh bat dau chay theo thoi gian cai dat ;----------------------------------------------------------------- MOV R4,#21 SETB TF0 MOV IE ,#82H LAP4: MOV DPTR,#8000H CALL START MOV R0,#1 LAP: MOV 1BH,A MOV A,1AH JNB ACC.0,NHAY MOV A,1BH JNB P1.0,NHAY10 ;----------------------------------------------------------------------- ; khi vao chuong trinh chay thoi gian neu muon cai dat bao thuc nhan P1.0 ;----------------------------------------------------------------------- JB P1.1,KK LJMP MAIN1 KK: JB P1.5,LAP MOV 5DH,#255 SJMP LAP NHAY: MOV A,#80H CALL INIT_LCD MOV A,R3 ACALL HIEN_THI MOV A,#':' ACALL WRITE_TEXT MOV A,R2 ACALL HIEN_THI MOV A,#':' ACALL WRITE_TEXT MOV A,R1 ACALL HIEN_THI DJNZ R0,LAP7 ;---------------------------------------------------------------------------------------------------------------- ;khi thoi gian thuc dung bang thoi gian bao thuc thi cho nhap nhay chu 'RENG RENG RENG' len man hinh may tinh 10s ;--------------------------------------------------------------------------------------------------------------- MOV R0,#1 MOV R5,#30 LAP7A: MOV A,#8 ACALL SEND DJNZ R5,LAP7A MOV A,R1 CJNE A,5DH,LAP MOV A,R2 CJNE A,5EH,LAP MOV A,R3 CJNE A,5FH,LAP MOV R0,#10 MOV R5,#30 LAP7: MOV A,#8 ACALL SEND DJNZ R5,LAP7 MOV DPTR,#TABLE3 TTUC4: CLR A MOVC A,@A+DPTR CJNE A,#'0',NHAY9 LJMP LAP NHAY9: ACALL SEND INC DPTR SJMP TTUC4 NHAY10: JNB P1.0,$ PUSH ACC MOV A,#80H ACALL INIT_LCD MOV R0,#16 MOV A,#0 PUSH ACC LOOP3A: CALL TRABANG2 CALL WRITE_TEXT POP ACC INC A PUSH ACC DJNZ R0,LOOP3A ACALL HIENTHI1 MOV 5AH,R1 MOV 5BH,R2 MOV 5CH,R3 ACALL CAI_DAT MOV 5DH,5AH MOV 5EH,5BH MOV 5FH,5CH LJMP LAP4 CAI_DAT: TTUC1: JB P1.2,NHAY3 JNB P1.2,$ INC 5AH MOV A,5AH CJNE A,#60,NHAY4B MOV 5AH,#0 SJMP NHAY4B NHAY3: JB P1.3,NHAY4 JNB P1.3,$ DEC 5AH MOV A,5AH CJNE A,#255,NHAY4B MOV 5AH,#59 SJMP NHAY4B NHAY4B: ACALL HIENTHI2 NHAY4: JB P1.0,TTT1 JNB P1.0,$ RET TTT1: JB P1.4,TTUC1 JNB P1.4,$ TTUC6: JB P1.2,NHAY5 JNB P1.2,$ INC 5BH MOV A,5BH CJNE A,#60,NHAY6B MOV 5BH,#0 SJMP NHAY6B NHAY5: JB P1.3,NHAY6 JNB P1.3,$ DEC 5BH MOV A,5BH CJNE A,#255,NHAY6B MOV 5BH,#59 SJMP NHAY6B NHAY6B: ACALL HIENTHI2 NHAY6: JB P1.0,TTT2 JNB P1.0,$ RET TTT2: JB P1.4,TTUC6 JNB P1.4,$ TTUC7: JB P1.2,NHAY7 JNB P1.2,$ INC 5CH MOV A,5CH CJNE A,#12,NHAY8B MOV 5CH,#0 SJMP NHAY8B NHAY7: JB P1.3,NHAY8 JNB P1.3,$ DEC 5CH MOV A,5CH CJNE A,#255,NHAY8B MOV 5CH,#11 NHAY8B: ACALL HIENTHI2 NHAY8: JB P1.0,TTT3 JNB P1.0,$ RET TTT3: JB P1.4,TTUC7 JNB P1.4,$ LJMP TTUC1 ISR_T0: MOV 1BH,A SETB ACC.0 MOV 1AH,A MOV A,1BH DJNZ R4,TT MOV 1BH,A CLR ACC.0 MOV 1AH,A MOV A,1BH MOV R4,#20 INC R1 CJNE R1,#60,TT1 MOV R1,#0 INC R2 TT1: CJNE R2,#60,TT2 MOV R2,#0 INC R3 TT2: CJNE R3,#60,TT MOV R3,#0 TT: CLR TR0 MOV TH0,#HIGH(-35000) MOV TL0,#LOW(-35000) SETB TR0 RETI TRABANG1: MOV DPTR,#TABLE1 MOVC A,@A+DPTR RET TRABANG2: MOV DPTR,#TABLE2 MOVC A,@A+DPTR RET SEND: JNB TI,SEND MOV SBUF,A CLR TI RET HIEN_THI: MOV B,#10 DIV AB ORL A,#30H ACALL WRITE_TEXT MOV A,B ORL A,#30H ACALL WRITE_TEXT RET HIENTHI1: MOV A,#0C0H CALL INIT_LCD MOV A,R3 ACALL HIEN_THI MOV A,#':' ACALL WRITE_TEXT MOV A,R2 ACALL HIEN_THI MOV A,#':' ACALL WRITE_TEXT MOV A,R1 ACALL HIEN_THI RET HIENTHI2: MOV A,#0C0H CALL INIT_LCD MOV A,5CH ACALL HIEN_THI MOV A,#':' ACALL WRITE_TEXT MOV A,5BH ACALL HIEN_THI MOV A,#':' ACALL WRITE_TEXT MOV A,5AH ACALL HIEN_THI RET ;---------------------lenh khoi tao chuong trinh START: MOV A,#38H CALL INIT_LCD MOV A,#0CH CALL INIT_LCD MOV A,#06H CALL INIT_LCD MOV A,#01H CALL INIT_LCD MOV A,#80H CALL INIT_LCD RET ;-----------doi LCD WAIT_LCD: MOV R7,#4 BB: MOV R6,#250 DJNZ R6,$ DJNZ R7,BB RET ;------------xuat lenh INIT_LCD: MOV DPTR,#8000H LCALL WAIT_LCD CLR RS MOVX @DPTR,A SETB EN CLR EN RET ;------------xuat ki tu WRITE_TEXT: MOV DPTR,#8000H LCALL WAIT_LCD SETB RS MOVX @DPTR,A SETB EN CLR EN RET TABLE1: DB'BAN MUON CAI DAT' TABLE2: DB'CAI DAT BAO THUC' TABLE3: DB'RENG RENG RENG 0' END
File đính kèm:
- bai_bao_cao_mon_vi_xu_ly.docx
- VXL.pdf