You are on page 1of 29

LCD HOAN CHINH ORG JMP ORG JMP ORG JMP ORG MAIN: DB0 EQU P1.

0 DB1 EQU P1.1 DB2 EQU P1.2 DB3 EQU P1.3 DB4 EQU P1.4 DB5 EQU P1.5 DB6 EQU P1.6 DB7 EQU P1.7 DATAL EQU P1 EN EQU P3.7 RS EQU P3.6 RW EQU P3.5 N DATA 20H X DATA 21H Y DATA 22H S1 DATA 23H S2 DATA 24H M1 DATA 25H M2 DATA 26H H1 DATA 27H H2 DATA 28H TAM DATA 29H;O NHO TAM DE SO SANH SOAMA DATA 2AH;O NHO SO AM A SOAMB DATA 2BH SOA DATA 2CH;SO LUONG SO NHAP VAO CUA A SOB DATA 2DH;SO LUONG SO NHAP VAO CUA B ALONB DATA 2EH; NEU NO KHAC KHONG THI A LON HON B(VE DO LON) PTINH DATA 2FH; O NHO PHEP TINH QUATAM DATA 3FH;O QUA TAM^` TRONG PHEP CONG VA PHEP NHAN A1 DATA 30H;O KO CO DINH DIA CHI BIET A2 DATA 31H;VUNG O NHO TRUNG VOI VUNG CUA VUNG O NHO NHAP KY TU A3 DATA 32H A4 DATA 33H A5 DATA 34H A6 DATA 35H A7 DATA 36H A8 DATA 37H A9 DATA 38H A10 DATA 39H A11 DATA 3AH A12 DATA 3BH A13 DATA 3CH A14 DATA 3DH B1 DATA 40H B2 DATA 41H B3 DATA 42H B4 DATA 43H B5 DATA 44H B6 DATA 45H B7 DATA 46H B8 DATA 47H B9 DATA 48H B10 DATA 49H B11 DATA 4AH B12 DATA 4BH Page 1 00H MAIN;NHAY QUA NGAT 03H CHAYTRAI 13H; NGAT NGOAI 1 CHAYLEN 30H

LCD HOAN CHINH B13 DATA 4CH B14 DATA 4DH MOV TCON,#00H; NGAT TAC DONG MUC CALL WAIT_LCD;CHO LCD SAN SANG NHAN LENH CALL SETUP_LCD; CAI DAT CHO LCD CALL CLEAR_LCD; XOA LCD CHO CURSOR DAT TAI GOC TRAI MOV R5,#00H;KHONG THE GOI CHUNG 1 HAM VI TRONG NO CO DEN 2 HAM CON XUAT9: MOV A,R5 MOV DPTR,#TABLE7 MOVC A,@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5,#13,XUAT9 MOV N,#0C3H CALL POSITIONN CALL WAIT_LCD XUAT10: MOV A,R5 MOVC A,@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5,#23,XUAT10 CALL DELAY CALL DELAY CALL CLEAR_LCD MOV R5,#00H XUAT7: MOV A,R5 MOV DPTR,#TABLE6 MOVC A,@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5,#13,XUAT7 MOV N,#0C0H CALL POSITIONN CALL WAIT_LCD XUAT8: MOV A,R5 MOVC A,@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5,#29,XUAT8 CALL DELAY CALL DELAY CALL CLEAR_LCD MOV R5,#00H XUAT5: MOV A,R5 MOV DPTR,#TABLE5 MOVC A,@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5,#16,XUAT5 MOV N,#0C0H CALL POSITIONN CALL WAIT_LCD XUAT6: MOV A,R5 MOVC A,@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5,#28,XUAT6 Page 2

#00H MOV P2.NEU N=C0 THI NAP LA 8FH MOV N.DELET1.#' ' DEC R0 CJNE R0.P2 CJNE A.TIEP.#0FFH MOV R5.VI DANG O? O NHO CUOI CALL POSITIONN CALL WAIT_LCD JMP TIEPDELET.#8FH CALL POSITIONN CALL WAIT_LCD JMP TIEPDELET.#80H.#80H.XETKYTU JMP CHOCHON XETKYTU: CJNE A.#0FDH.DE KHI CHAY KO BI CAC KY TU LA TA NHAP TAT CA O NHO LA ' ' OTRONG: MOV @R0.#49H.#0FBH.LUI LAI O NHO TRUOC CJNE A.#2FH.KHONG CAN CAT A VI KO CAN NHO DEC R0.#00H.#0FFH.#0FEH.NEU R0=50H TUC LA O NHO CUOI THI SE NAP LAI O 30H Page 3 .OTRONG.#4FH.LUACHON JMP CHONDONGHO NHAPKYTU: CALL CLEAR_LCD MOV R0.KODELETE.BO QUA TIEP VI KO CO DUNG WRITE_TEXT KODELETE: MOV @R0.#TABLE. MOV R0. MO NGAT NGOAI 1 MOV TCON.LUACHON MOV P0.#'%'. NAP BANG CHO DPTR CALL CHONGNHIEU CALL WAIT_CHAR1 CALL TRABANG CJNE A. NGAT TAC DONG MUC THAP WAIT_CHAR: MOV DPTR. MO TOAN NGAT SETB EX0.NEU BANG THI KO CAN DEC N DELET1: CJNE A.P2 CJNE R5.#0C0H.O NHO DAU CHO CAC PHAN SAU MOV N. NEU LA % THI SE THUC HIEN DELETE MOV A.#0FEH CHOCHON: MOV A.80H LA VI TRI DAU CUA LCD SETB EA.N.#0FFH.A.#30H.NEU BANG THI KO CAN DEC N DELET2: DEC N.#0CFH MOV R0.GIAM N CALL POSITIONN CALL WAIT_LCD JMP TIEPDELET.CAT VAO RAM INC R0 CJNE R0.NEU N LA 80H THI LUI LAI LA BFH MOV N.MO NGAT NGOAI 0 SETB EX1.DELET2.LCD HOAN CHINH LUACHON: CALL CHONGNHIEU CALL CHONGNHIEU MOV P0.XETKYTU1 JMP NHAPKYTU XETKYTU1: CJNE A.#50H.XETKYTU2 JMP MAYTINH XETKYTU2: CJNE A.

'R'LA_.#82H.#90H.&VA-(DAU AM).#0FEH DOLAICL: MOV P0.A CLR EN CALL WAIT_LCD INC N TIEPDELET: MOV A.NAP CHO CA O NHO TRI FFH ONHOCL: MOV @R1.TRACOTCL Page 4 .MAC DINH L SO DUONG MOV N.CHUA 1 O DAU DE CO SO AM CALL POSITIONN CALL WAIT_LCD MOV QUATAM.#0D0H.#00H MOV P2.#0FFH.#5DH.R5 MOV A.WAIT_CHARCL DOCL: MOV Y.ONHOTAMCL MOV R1.#0C0H CALL POSITIONN CALL WAIT_LCD JMP TIEPNAO DONG2: CJNE A.#00H MOV PTINH.R1.#00H.VI CAN CAT TRI TRUOC KHOI HOAN DOI VI TRI MOV @R1.VI TRI TRONG O NHO KO THE LA 00H VI NO SE NHAM VOI GIA TRI 0 KHI NHAP VAO DEC R1 MOV A.T LA / CALL CHONGNHIEU MOV P0.#3DH.ONHOCL MOV R1.KY TU TUONG DUONG ' 'VA=.LCD HOAN CHINH MOV R0.NEU KO BANG THI NHAY DEN SO VOI DONG 2 MOV N.#30H TIEP: SETB EN CLR RW SETB RS MOV DATAL.#0FFH.VI KO DUNG CJNE R1 DUOC CJNE A.O NHO TAM DE DUNG DOSOCL ONHOTAMCL:.'Q'VA+.#4DH.#2FH.#00H MOV R5.DONG2.N CJNE A.#80H CALL POSITIONN CALL WAIT_LCD TIEPNAO: NOP JMP WAIT_CHAR MAYTINH: CALL CLEAR_LCD MOV ALONB.P2 CJNE A.MAC DINH LA PHEP CONG WAIT_CHARCL:.VI TRI TRONG O NHO KO THE LA 00H VI NO SE NHAM VOI GIA TRI 0 KHI NHAP VAO DEC R1 MOV A.VI KO DUNG CJNE R1 DUOC CJNE A.TIEPNAO.R1.#4FH.#0FFH.#'+'.#0FFH.S LA *.NAP LUC DAU LA A NHO HON B MOV R1.NEU BANG VI TRI CUOI CUA LCD THI NAP LAI N MOV N.#TABLE MOV SOAMA.O NHO CUA A14 DEN A1 ROI MOI DEN B14 DEN B1 MOV DPTR.#0FFH MOV A.#' ' MOV SOAMB.#' '.P2 CJNE A.

VI N DA CONG 80H NEN KO CAN CONG CALL POSITIONN CALL WAIT_LCD DEC R1.R5 MOV DPTR.NEU CHUA DEN KY TU CUOI THI TIM LAI.X.NHAYCL NEU CY=1 HAY Y=5(5 HANG BAT DAU TU HANG 0) JC DOCL JMP DOLAICL TRACOTCL: MOV X.0 JNC TRATRACL INC X MOV C.NHAYCL.NAP LAI BANG DE DO PHIM JMP WAIT_CHARCL.2.TRI CUA KY TU DAU TRONG TABLE1 MOV A.#00H.XETCL1.0 ANL C.11 LA KY TU ' ' MOV DPTR.#14.R5 MOVC A.#0C0H CALL POSITIONN CALL WAIT_LCD NHAYCACULATOR: Page 5 .NEU TAI S1 MA NHAN THI KO LAM GI CA LUICURSORCL: DEC N.Y.#00H.NEU DA NHAP PHEP TINH THI SE CHAY.VI DA LA KY TU % THI KO CAN THIET GIU TRONG A CJNE A.ACC.A.XUATCL MOV N.VI NHAP TU O CAO DEN O THAP NEN PHAI TANG R1 MOV DPTR.#00H XUATCL: MOV A.PTINH CJNE A.R5 MOV DPTR.A INC Y MOV C.NAP LAI BANG DE DO PHIM JMP WAIT_CHARCL NHAYCL: INC R5. CON KO THI PHAI CHO NHAP MOV R5.TAM.TANG TRI CUA KY TU MOV A.#00H COTKECL: SETB C ANL C.#TABLE4 MOVC A.NEU KHAC 81H THI XET TIEP MOV DPTR.NEU KO = KY TU 0 THI NHAY DEN SO VOI KY TU 1 CJNE R5.TIMSOCL.NHAYCACULATOR.#82H.LENH CJNE NHAY KO XA MOV A.NEU R5 KO = 11 THI DAY LA KY TU SO HOP LE MOV A.#TABLE.#TABLE.NAP LAI BANG DE DO PHIM JMP WAIT_CHARCL.LCD HOAN CHINH MOV A.R5 RL A MOV R5.#TABLE.CAT TRI MOV R5.@A+DPTR CJNE R5.XETCL.@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5.3 JC TRACOTCL RR A JMP COTKECL TRATRACL: CALL TRABANG MOV TAM.@A+DPTR TIMSOCL: CJNE A.N.#17.#TABLE1.Y.NAP BANG KHAC DE QUET MOVC A.#10.NEU KO CO TRONG BANG SO THI BAN DA NHAP SAI KY TU PHEPTINH:.

N.NEU O VI TRI 0C2H BAN AN ' 'THI TA CHO O NHO B14 LA 00H VA TINH TOAN MOV PTINH.#'+' MOV A.NEU TU O 0C2H THI CO CY KHONG BI BAT JC XUONGD.O NHO BAT DAU O DAY B MOV DPTR.XETPHEPT.KHAC VI TRI 0C2 THI TA DA CO SO VA SE TINH TOAN.KE TU O C2 TRO DI THI TA THUC HIEN PHEP TOAN VI CAC O NHO DA NAP TRI 00H XETPHEPT1: CJNE R5.NEU KHAC THI XET TIEP MOV R5.#0C2H CALL POSITIONN CALL WAIT_LCD MOV R1.#12.#0C2H.#82H.#80H CALL POSITIONN Page 6 .XETPHEPT1.MAC DINH LA DAU + NHAYPHEPTINH2:.#25.NEU KHAC 11 THI XEM CO PHAI LA PHEP TOAN KO MOV A.#0C2H.VI CJNE KO NHAY DEN MOV B14.#80H CALL POSITIONN CALL WAIT_LCD MOV PTINH.NEU KHAC CA DONG 2 THI LUI MOV DPTR.PTINH CALL WRITE_TEXT MOV N.NEU KHAC THI XET TIEP MOV R5.#TABLE.XETPHEPT2.#00H.#0C2H.NEU TAI DAY THI KO LAM GI JMP WAIT_CHARCL XETCL:.CAT VI TRI CUSOR HIEN TAI MOV N.#11.XUATCL1 CALL DELAY CALL DELAY CALL DELAY CALL CLEAR_LCD MOV DPTR.N.R5 MOVC A.#'+'.#4DH.CAT VI TRI CUSOR HIEN TAI MOV N.#TABLE.VI CJNE KO NHAY DEN XUONGD: MOV N.#TABLE JMP WAIT_CHARCL XETCL1:.KHONG HIEU TAI SAO NEU TA DE LUICURSORCL CACH XA THI BAO LOI ADDRESS OUT OF RANGE CJNE A.R5.NEU KHAC O DAU THI XET TIEP TRUOC KHI CHO XUONG DONG MOV DPTR.#TABLE JMP WAIT_CHARCL XETCL2: CLR C SUBB A.@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5.N.VI TRI A DA THAY DOI KO CON LA N CJNE A.NHAYPHEPTINH2.VI CA 2 DEU NHAY DEN PHEP TINH JMP PHEPTINH.#TABLE JMP WAIT_CHARCL XUATCL1: MOV A.LUICURSORCL.NEU BANG THI XET CJNE A.LCD HOAN CHINH JMP CHAYCACULATOR.N.TRA LAI VI TRI CURSOR CALL POSITIONN CALL WAIT_LCD MOV DPTR.XEM CO PHAI LA KY TU ' ' KO CJNE R5.XEM CO PHAI DAU + KO CJNE R5.NEU HOP LE THI CY LUON =1 MOV A.#13.VI CHUA NHAP SO KO THE XUONG DONG JMP WAIT_CHARCL XETPHEPT:.XETCL2.

PTINH CALL WRITE_TEXT MOV N.VI DAY LA VI TRI DAU AM B CALL POSITIONN CALL WAIT_LCD MOV A.N CLR C SUBB A.NEU KHAC THI XET TIEP MOV R5.NEU KHAC THI LA KY TU SO THUONG MOV R5.CY=0 NE TU KY TU 0C2H HAY O DONG 2 MOV A.#'/' MOV A.R5.R5.N.#0C2H.#'_' MOV A.#80H CALL POSITIONN CALL WAIT_LCD MOV PTINH.#0C1H.XETPHEPT4.KHAC ' ' THI LA '-' TA DOI THANH ' ' XONGDOIDAUB: MOV N.#TABLE JMP WAIT_CHARCL XETPHEPT3: CJNE R5.SOAMB CJNE A.R5.#' '.NEU TU O 0C2H THI CO CY KHONG BI BAT JC DONG1CL.SOAMB CALL WRITE_TEXT MOV N.TRA LAI VI TRI CURSOR CALL POSITIONN CALL WAIT_LCD MOV DPTR.#'*' MOV A.#80H CALL POSITIONN CALL WAIT_LCD MOV PTINH.#TABLE JMP WAIT_CHARCL XETPHEPT2: CJNE R5.DOIDAUB MOV SOAMB.N MOV A.LCD HOAN CHINH CALL WAIT_LCD MOV PTINH.N.CAT VI TRI CUSOR HIEN TAI MOV N.#TABLE JMP WAIT_CHARCL XETPHEPT4:.#'-' JMP XONGDOIDAUB DOIDAUB: MOV SOAMB.#TABLE JMP WAIT_CHARCL DONG1CL: MOV A.TRA LAI VI TRI CURSOR CALL POSITIONN CALL WAIT_LCD MOV DPTR.TRA LAI VI TRI CURSOR CALL POSITIONN CALL WAIT_LCD MOV DPTR.TRA LAI VI TRI CURSOR CALL POSITIONN CALL WAIT_LCD MOV DPTR.PTINH CALL WRITE_TEXT MOV N.KYTUSOCL.NEU KHAC THI XET TIEP MOV R5.CAT VI TRI CUSOR HIEN TAI MOV N.#15.PTINH CALL WRITE_TEXT MOV N.#16.SOAMA Page 7 .R5.XEM CO PHAI SO AM KO CJNE R5.XETPHEPT3.#14.#' '.

DOIDAUA MOV SOAMA.#' ' XONGDOIDAUA: MOV N.XETCL6.#30H MOV R0.NAP CHO TRI UNG VOI KY TU INC N.#30H.#'-'.SOB.SOA MOV SOB.NEU KO BANG 3FH THI DONG 2 VA CHUA HET KY TU JMP CHAYCACULATOR.R5.SAU LENH SOA VA SOB LA SO LAN MOV A.ALONHONB1 MOV A.R1.NHAYXETTRU PHEPCONG:.O THAP NHAT TRONG DAY B CALL DOSOCL.#' '.XEM B LA AM HAY DUONG MOV R1.XETCL3.VI DAY LA VI TRI DAU AM A CALL POSITIONN CALL WAIT_LCD MOV A.LUC NAY R2 LA SOB TA KO NEN THAY DOI CALL AHAYBLON.#40H.#TABLE.PTINH.SOAMB CJNE A.#'-' JMP XONGDOIDAUA DOIDAUA: MOV SOAMA.#081H.XET GIA TRI SOA VA SO B XUAT RA MOV R1.SO CAC O NHO FAI BANG NHAU(NHUNG SOA KHAC SOB.SAU LENH NAY SOA VA SOB LA SO LAN VA KHAC NHAU CALL SOSANH.A.SOAMA CALL WRITE_TEXT MOV N.ALONB =FFH THI A LON HON B.NEU DA NHAP DEN O CUOI DONG 1 THI XUONG DONG JMP XUONGD.A.CAT SO LUONG SO VAO.#'+'.R2.GIAM XUONG O NHO TIEP THEO MOV A.SAU LENH CONG HOAC TRUKODAU THI SOAMA =00H CLR C.TANG VI TRI CURSOR DEC R1.O THAP NHAT DE THUC HIEN DAT LAI CALL DOSOCL.VI PTINH MAC DINH DA CO NEN TA CHAY LUON CHUAHETCL: MOV DPTR.XOA CO MOV A.SAU CAC LENH THI SOA VA SOB DEU LA SO LAN CALL CLEAR_LCD MOV DPTR.NEU BANG 00H THI B LON HON CJNE A.O NHO CAO NHAT CUA DAY A MOV R3.SOAMA CJNE A.#2FH.#TABLE JMP WAIT_CHARCL KYTUSOCL: CALL WRITE_TEXT MOV A.R2.#3FH. ALONHONB1:.XETCL7.TRA LAI VI TRI CURSOR CALL POSITIONN CALL WAIT_LCD MOV DPTR.DAY LA SO LAN KO PHAI SO O MOV R1.CHUAHETCL.#3DH.CHUA HET THI NHAP TIEP XETCL3: CJNE A.KO CAN NAP R5 VI SAU LENH DOSOCL NO DA VE 0 MOV R3.XET PHEP TINH GI CJNE A.LCD HOAN CHINH CJNE A.DUA TRI QUA A VI KO MOV RX DEN R DUOC MOV @R1.XEM A LA AM HAY DUONG MOV A.#TABLE1.DA CHAY DUNG MOV SOA.CT NAY SE DOI TU CAO VE THAP.KO DUOC THAY DOI A.NAP LAI BANG ROI MOI QUAY VE DO PHIM TIEP JMP WAIT_CHARCL CHAYCACULATOR:.R5.A+B.DAY LA SO LAN(SO LAN = SO O +1).#'-'.NEU KHAC 00H THI A LON HON B MOV A.SOA VA SOB DEU LA SO LAN MOV SOB.#40H Page 8 .#00H.A MOV A.CAN BANG SOA VA SOB MOV SOA.#4DH.VI R1 KO DUNG CJNE DUOC CJNE A.ALONB.

A VA B DEU LA SO DUONG MOV R1.VI B NHO HON A NE LAY A TRU B VA KET QUA LA SO AM MOV R1.KET QUA LA SO DUONG VI B LON HON A.#0FFH.VA N LA C2H JMP WAIT_CHARCL XETTRU: Page 9 .#TABLEX QUATAMTEXT: MOV A.KET QUA TRONG DAY B CAN DOI LAI CALL DOIKETQUA JMP HETPHEPCONG LONHONA:.LCD HOAN CHINH CALL CONGKHONGDAU.#TABLE JMP WAIT_CHARCL KOQUAPC: CALL CLEAR_LCD CALL KETQUA.#00H MOV DPTR.@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5.#30H CALL TRUKHONGDAU.ALONB.#40H.NHAY NEU B LA SO DUONG MOV A.#00H.VI CJNE NHAY KO DEN XETCL7:.#10.#30H MOV R0.KHONG CAN MOV SOAMA HETPHEPCONG: MOV A.KET QUA LA SO DUONG.KET QUA DANG NAM TRONG B NEN CAN DOI LAI CALL DOIKETQUA JMP HETPHEPCONG LONHONA1:.KOQUAPC CALL CLEAR_LCD MOV R5.#30H MOV R0.SAU LENH N=C2H.QUATAMTEXT CALL DELAY CALL DELAY CALL DELAY MOV DPTR.#30H CALL TRUKHONGDAU.#40H.=A-B MOV R1.SAU LENH NAY SOAMB LA ' '.ALONB.KO CAN XOA CO VI LEN TRU DA TU XOA CALL TRUKHONGDAU.NEU ALONB=00H THI B LON HON A MOV R1.VI SOAMA LA ' 'NEN KO CAM MOV LAI JMP HETPHEPCONG XETCL6:.QUATAM CJNE A.LONHONA.-A+(-B) JMP HETPHEPCONG.R1 LA 4DH.SOAMB CJNE A.#' '.#40H MOV R0.A+(-B) CJNE A.#40H CALL TRUKHONGDAU JMP HETPHEPCONG XET8:.DPTR=TABLE CALL CHUYENKETQUA.#00H.#'-'.-A+(B) MOV A.A DUONG B AM VA B NHO A.R5 MOVC A.CONG XONG NHAYXETTRU: JMP XETTRU.XET8.#40H MOV R0.A LA SO DUONG MOV A.NEU ALONB=00THI B LON HON VI A LA DUONG VA B LA AM NEN B-A MOV R1.KET QUA LA SO AM NEN CAN MOV LA SOAMA MOV SOAMA.#'-'.CAN XOA CO VI TRONG LENH CONG KO XOA CO CALL CONGKHONGDAU.THUC HIEN TRU KO DAU MOV SOAMA.#30H MOV R0.LONHONA1.XEM A HAY B LON CJNE A.

#00H.KHONG PHAN BIET SO LON HAY NHO VI CAC O DA BANG NHAU MOV A.NHAY NEU B LA SO DUONG.XETTRUCL8.#40H CALL CONGKHONGDAU.A LA SO AM VA B LA SO DUONG.A DUONG TRU B AM NEN KET QUA LA DUONG =A+B MOV R1.A-B MOV A.#' '.#40H CALL TRUKHONGDAU.XEM B LA AM HAY DUONG MOV A.#40H MOV R0.#30H MOV R0.KO MOV SOAMA JMP HETPHEPTRU.NHAYXETNHAN CALL CLEAR_LCD PHEPTRU:.XEM A LA AM HAY DUONG MOV A.LCD HOAN CHINH CJNE A.#00H.SOAMB CJNE A.A VA B AM NHUNG -A-(-B)=-A+B MOV R1.CHU Y CO QUA TAM XETCLTRU6:.#'-'.DPTR=TABLE CALL CHUYENKETQUA JMP WAIT_CHARCL XETNHAN:.A LON HON B NEN A-B MOV R1.#30H CALL TRUKHONGDAU MOV SOAMA.#30H MOV R0.#'-' CALL DOIKETQUA JMP HETPHEPTRU XETTRUCL9:.XETCLTRU7.#'-'.B LA SO AM NEN A+B MOV R0.SOAMA CALL WRITE_TEXT Page 10 .#40H CALL CONGKHONGDAU.#'+' MOV A.A LON HON B .#40H CALL TRUKHONGDAU HETPHEPTRU: CALL KETQUA.B LON HON A THI B-A VA KET QUA LA AM MOV R1.NHUNG A-B MOV A.#'-'.A-B MOV A.VI KET QUA DUONG CALL DOIKETQUA.SOAMA CJNE A.PTINH CALL WRITE_TEXT MOV A.NEN -A-B VA KET QUA LA SO AM MOV R1.A VA B DEU LA SO DUONG.CO THE QUA TAM XETTRUCL8:.ALONB CJNE A.LUC NAY A LA SO DUONG.KET QUA LA SO AM JMP HETPHEPTRU.TRUALONB.XETTRUCL9.-A-(-B).#'A' CALL WRITE_TEXT CALL DELAY CALL DELAY CALL CLEAR_LCD MOV PTINH.XETCLTRU6.#'_'.-A-(-B) CJNE A.#40H MOV R0.SOAMB CJNE A.DOI LAI KET QUA JMP HETPHEPTRU TRUALONB:.KET QUA LA SO AM JMP HETPHEPTRU NHAYXETNHAN: JMP XETNHAN XETCLTRU7:.#30H MOV R0.B LON HON A NEN B-(A) MOV R1.#30H CALL TRUKHONGDAU MOV SOAMA.#30H.SAU LENH THI N=C2H.ALONB.

#28H. DA CO KY TU MOV TAM.NAP LAI BANG DE DO PHIM JMP WAIT_CHARDH.#19.TRI CUA KY TU DAU TRONG TABLE1 MOV A.#0C5H.A CLR EN CALL WAIT_LCD MOV A.TRI O NHO CUA H2 MOV R5.NEU TAI S1 MA NHAN THI KO LAM GI CA LUICURSOR: DEC N.NEU DEN KY TU 20 THI XONG MOV N.CAT TRI MOV R5.R5 MOVC A.VI TRI O DAU HANG 1 MOV SOAMB.NAP LAI BANG DE DO PHIM JMP WAIT_CHARDH KYTUSO: SETB EN.#3DH JMP WAIT_CHARCL CHONDONGHO: CALL CLEAR_LCD MOV R1.XUONG DONG DE KO MAT CHU MOV N.N.#0C5H.VI NHAP TU O CAO DEN O THAP NEN PHAI TANG R1 MOV DPTR.#82H.XUAT0.NEU R5 KO = 11 THI DAY LA KY TU SO HOP LE MOV A.LCD HOAN CHINH MOV N.TAM.XUAT1.#TABLE2 XUAT0: MOV A.R5 MOV DPTR.#TABLE.KYTUSO.#TABLE.R5 MOVC A.R5.#' ' MOV R1.@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5.LUICURSOR.#00H MOV DPTR.@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5.VI TRI CURSOR TAI 80+NH CLR EN CALL WAIT_LCD INC R1.#14.#TABLE CALL CHONGNHIEU CALL WAIT_CHAR1 CALL TRABANG.NEU KO = KY TU 0 THI NHAY DEN SO VOI KY TU 1 CJNE R5.VI A DA TRUNG VOI KY TU NE KO CAN NAP LAI CLR RW SETB RS MOV DATAL.@A+DPTR TIMSO: CJNE A.#TABLE1.#00H.N SETB EN CLR RS CLR RW MOV DATAL.A.VI DA LA KY TU % THI KO CAN THIET GIU TRONG A CJNE A.A.NEU KHAC S1 THI LUI LAI MOV DPTR.NAP CHO TRI UNG VOI KY TU Page 11 .NHAY.NAP BANG KHAC DE QUET MOVC A.DUA TRI QUA A VI KO MOV RX DEN R DUOC MOV @R1.#0C0H CALL POSITIONN CALL WAIT_LCD XUAT1: MOV A.#10.VI TRI H2 O HANG 2 SAU KY TU WAIT_CHARDH: MOV DPTR.A.VI N DA CONG 80H NEN KO CAN CONG MOV A.

#28H.NHAPLAI.#TABLE1 MOV A.H2.#84H.NHAPLAI.H2.CAC SO DA HOP LE NHAPLAI: MOV R5.#0C5H CALL POSITIONN.#00H.H2.XOA CA CY DE KIEM TRA CAC SO DA NHAP JB H2.R1.NEU KO CO TRONG BANG SO THI BAN DA NHAP SAI KY TU CHAYDONGHO: CALL CLEAR_LCD MOV R4.CHUA HET THI NHAP TIEP CHUAHET: MOV DPTR.VI TRI O NHO H2 JMP WAIT_CHARDH DONGHO: SETB EN CLR RS CLR RW MOV DATAL.NEU AC=KO TUC KY TU NHAP LON HON THI NHAP LAI JMP DONGHO.GIA TRI CUA DELAY1S CLR C.#TABLE3 XUAT2: MOV A.NEU DA NHAP DEN O CUOI THI CHAY DONG HO JMP CHAYDONGHO.M2 MOVC A.NHAY NEU SAU PHEP AND CY=1 MOV A.XUAT2 MOV N.VI R1 KO DUNG CJNE DUOC CJNE A.NEU CHUA DEN KY TU CUOI THI TIM LAI MOV DPTR.@A+DPTR Page 12 .2.NEU S2 NHO HON 6 THI AC BAT LEN 1 JNB AC.#6.#00H.#13.VI H2 LA SO KO PHAI KY TU MOVC A.3.CHUAHET.0 JC NHAPLAI.#TABLE.M2 SUBB A.H1 MOVC A.NAP LAI BANG DE DO PHIM JMP WAIT_CHARDH.@A+DPTR CALL WRITE_TEXT MOV A.#6.NEU M2 NHO HON 6 THI AC BAT LEN 1 JNB AC.S2 SUBB A.VI TRI DAU TABLE3 MOV DPTR.LCD HOAN CHINH INC N.NHAPLAI MOV C.TANG TRI CUA KY TU MOV A.@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5.#':' CALL WRITE_TEXT MOV A.TIMSO.#22H.#11.1 ANL C.#TABLE.@A+DPTR CALL WRITE_TEXT MOV A.TANG SO LENH MOV A.R5 MOVC A.VI TRI CURSOR TAI 80+04H CLR EN CALL WAIT_LCD MOV DPTR.TANG VI TRI CURSOR DEC R1.R5 MOVC A.XEM LAI CALL WAIT_LCD MOV R1.NEU AC=KO TUC KY TU NHAP LON HON THI NHAP LAI MOV A.NHAY NEU BIT 3 CUA H2=1 JB H2.@A+DPTR CJNE R5.NHAPLAI.NAP LAI BANG ROI MOI QUAY VE DO PHIM TIEP JMP WAIT_CHARDH NHAY: INC R5.

TRUOC TIEN PHAI CAT TAM WA ONHOTAM TU 5D DEN 50 MOV A.#00H.#00H DOSOCL1: MOV A.R3.#21.S1 MOVC A.R5.R1.COTRICL MOV A.@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5.VI TRI SO XOAOKO: MOV @R1.CONG VOI O THAP NHAT DAY MOV R1.GIATRI.KHI CHAY XONG TA CAT LAI SO LUONG KY SO MOV R2.@A+DPTR CALL WRITE_TEXT INC R5 CJNE R5.HET CHAY DONG HO DOSOCL:.TIEP TUC DAT SO.@A+DPTR CALL WRITE_TEXT MOV A.A JMP DOXONGCL COTRICL: CJNE A.#00H MOV DPTR.#13.TRI THAP NHAT DAY ADD A.DO TU CAO DEN THAP INC R5.XUAT DONG CHU DESIGNING BY SU MOV R5.R5.M1 MOVC A.@A+DPTR CALL WRITE_TEXT MOV A.#00H.XUAT03 CALL DELAY CALL TANGGIO JMP DONGHO.#0FFH.XUAT3.TRI O NHO CAO NHAT MOV R0.@R1 CJNE A.#0FFH.XOA O NAY LUON DEC R1 MOV A.S2 MOVC A. DEC R0 DEC R1.R5 MOVC A.#00H.#TABLE7 CALL POSITION1 XUAT3: MOV A.@R1 CJNE A.A.GIATRI.DOSOCL1 JMP XOAOKO GIATRI: MOV @R0.R5 MOVC A.DUNG 1 BANG DE TIET KIEM XUAT03: MOV A.A.LCD HOAN CHINH CALL WRITE_TEXT MOV A.#5DH MOV R5.DE CHUYEN THANH O NHO KO PHAI SO LAN MOV A.#0FFH.@A+DPTR CALL WRITE_TEXT MOV R5.DA CO R5 DEC R5.#5DH Page 13 .CHUYEN QUA DAY TAM LA 5D DEN 50H MOV @R1.SO LUONG SO JMP DOSOCL1 DOXONGCL:.#':' CALL WRITE_TEXT MOV A.#24.DUNG DIA CHI GIAN TIEP MOV R0.NEU SO DAU LA 00H THI TA KO GHI CJNE R5.

CHUYEN O CAO DA CONG VAO R1 XETCL4: MOV @R1.LCD HOAN CHINH INC R5.DONG THOI XOA O DAY B INC R1 INC R0 DJNZ SOA.NEU CO CY=1 THI B LON HON A VA NHAY DEC SOA.DOSOCL2 RET.TRU DI 1 VI O NHO LUON BAT DAU TU 30 HOAC 40 DEC SOB MOV A.XOA CO TRUTIEPCL: MOV A.@R0.DOI QUA VUNG NHO KHAC MOV @R1.CAN NAP R1 -R0(R1 LON HON R0) CLR C.SOSANHXONG1.XOA CO.2E LA O NHO CHUA GIA TRI CUA O NHO CAO NHAT CUA DAY B JMP XETCL4 SOSANHXONG1: INC SOA INC SOB.#0FFH.TRUTIEPCL.CONG SO O VA VI TRI O THAP CUA B MOV R1.NAP CHO O NAY LA OOH DEC R1 MOV A.SOA.@R1 CJNE A.A.VI NEU LA SO DAU TIEN THI PHAI XOA CO.SOB.#00H.SOB.#0FFH.TRU CO CO JC MUONTRU.TRA LA LA SO LAN DOSOCL2: MOV A.DE CAC O NHO PHAI BANG NHAU MOV A.NEU KET QUA CO CY=0 THI A LON HON THI TA LUU VAO DAY A MOV @R0.SOSANHXONG1 JMP XETCL5A SOSANHXONG: NOP RET TRUKHONGDAU:.NEU SOA=SOB LA LAN 1 THI PHAI XOA CO KHI MUON TRU Page 14 .A.#30H ADD A.DA DAT XONG SOSANH:.XETCL5.#0FFH.LANN.TRU DI 1 VI O NHO LUON BAT DAU TU 30 HOAC 40 DEC SOA MOV A.#00H.DONG THOI XOA O NHO TAM LUON DEC R1 DEC R0 DJNZ R5.BAY GIO A LA SOA VI DA MOV O TREN SUBB A.NEU 2 SO BANG NHAU THI SOA VA SOB LA SO LAN XETCL5: CLR C.SOA CJNE A.NEU BANG THI THUC HIEN CONG JMP SOSANHXONG.NAP CHO O NAY LA OOH DEC R1 MOV A.CONG SO O VA VI TRI O THAP CUA A MOV R1.@R1 CJNE A.NHUNG SO THU 2 THI PHAI CO CO KHI TRU MOV A.CHUYEN O CAO DA CONG VAO R1 XETCL5A: MOV @R1.CAN NAP SOA LA SO LAN`.A MOV @R0.GIAM SOA CHO DEN SO CUOI CUNG JMP TRUXONGCL MUONTRU:.TRA LAI TRI THUC CUA SOA VA SOB LA SO LAN JMP SOSANHXONG BLON: DEC SOB.#40H ADD A.NEU CY = 1 THI B LON HON A TA CAN DOI LAI MOV @R1.A.@R0.@R1 SUBB A.SOA CJNE A.SOB.SOB JC BLON.#0FFH.

VI LUC NAY CY DA BAT LEN LANN:.VI TU LAN THU 2 THI PHAI TRU CO CO`* MOV A.R5.@R0.CONGKHONGDAU1.#3EH.KET QUA LUU TRONG R1 CLR C CONGKHONGDAU1: MOV A.LUC NAY CY=0 MOV A.TANG LEN 1 CHO LENH CONG SO SAU MOV @R0.SOB.XOA O THUOC DAY B LUON INC R1.A-10 SUBB A.CAT GIA TRI O NHO VAO A ADD A.VI R0 TOI DA LA 9 MOV @R1.CHAC CHAN A LON HON O NHO R0.XONGCKD2 MOV QUATAM.VI A LUC NAY LA KET QUA CUA R1+R0-10<8 KOQUA9: CLR C.GIA TRI SO SANH SUBB A.#10.A.#0FFH MOV @R1.CONGKHONGDAU1.GIAM SO O XUONG 1 JMP XONGCKD QUA9:.#0FFH.R4.CAT TRI MOV R5.#0FFH.#1.A LON NHAT 18.VI NEU CHUA QUA TAM THI O TIEP THEO PHAI LA 1 XONGCKD: NOP RET AHAYBLON:.R5 JC KOQUA9.R1 CJNE A.VI DA MUON 10 NEN PHAI TANG CY KHI TRU O KE INC R1 INC R0 DJNZ SOA.LONNHO.A.CONG THEM 10 SUBB A.XONGCKD1 MOV QUATAM.#3DH.R4.A INC R1.TANG O NHO LEN INC R0 DJNZ SOA.SOA FAI LA SO LAN.TRA LAI TRI R1+R2 MOV @R1.#4EH.SAU LENH CONG CO CY=0 VI A<=18 MOV R4.A MOV @R0.#10.GIAM SO O XUONG 1 MOV A.CONG CO CO.CAN XAC DINH R1 VA R0.#0FFH.NEU CY = 1 THI SO NHO HON 10 JMP QUA9.A= @R1+@R0.DAM BAO SAU CAC LEN SOA VA SOB DEU LA SO LAN CLR C MOV A.XOA CO VI NEU KO THI SE CONG DON SO THU 2 MOV A.@R0.#10.KO CAN XOA CO VI CY SETB C.#4DH Page 15 .NEU KHONG BANG NHAU THI CO THE LON HAY NHO MOV R1.TRA LAI TRI QUA 9 MOV R5.CAT VAO O NHO MOV @R0.NEU QUA TAM THI QUATAM LA FFH JMP XONGCKD XONGCKD2: MOV @R1.NEU SOA VAN KHAC O THI TRU TIEP TRUXONGCL: NOP RET CONGKHONGDAU:.SOA.@R1 ADDC A.NEU QUA TAM THI QUATAM LA FFH JMP XONGCKD XONGCKD1: CJNE A.#0FFH.TRUTIEPCL.XOA O DAY B SETB C.NEU BANG SO LUONG KY TU THI TA SO SO LON NHAT MOV R0.TANG O NHO LEN INC R0 DJNZ SOA.@R1.LCD HOAN CHINH CLR C.SOA LA SO LAN CJNE A.

#32.SOB JC BLONHON.#30H.DA NAP LUC CHAY XONGALONB: NOP RET CHAYLEN: CALL CLEAR_LCD MOV R0.KHONG BANG THI TANG LEN CJNE R0.KHONG CAN DAT N VI N=80H.KHONG BANG O CUOI CALL DELAY CALL DELAY CALL CLEAR_LCD CALL POSITION1.NEU A LON HON THI MOV ALONB FFH JMP XONGALONB BLONHON: MOV ALONB.4EH.#2FH.R1.NEU @R1 KHAC @R0 THI DON GIAN LA CAI NAO LON DEC R1 DEC R0 MOV A.A LON HON B JMP XONGALONB LONNHO: SUBB A.LONNHO1.NEU BANG NHAU HET THI TA CHO A LON HON B MOV ALONB. O NHO DAU MOV N.A MOV A. KHONG BANG O NHO CUOI CALL DELAY CALL DELAY CALL CLEAR_LCD CALL DELAY.#30H.LAP2.XUAT HANG 2 O DONG 1 LAP3: MOV A.LONNHO2.@R0 JC BLONHON.@R0 CALL WRITE_TEXT INC R0 INC N.#0FFH. VI TRI DAU CURSOR LAP2: MOV A.XUAT 2 HANG CJNE A.#0FFH.A LON HON B(TU CHO) JMP XONGALONB LONNHO1: MOV A.4EH SUBB A.@R0 CALL WRITE_TEXT.XEM DEN O CUOI CHUA CJNE A.@R0 CJNE A.CHAY DONG 1 TRUOC INC R0 CJNE R0.NHAY NEU CY=1 TUC B LON HON MOV ALONB.@R1 MOV 4EH.TIEPNAO0 MOV N.#50H.#0FFH.CHAY DONG 2 XUONG TRUOC Page 16 .DONG 1 XUONG DUOI MOV R0.KHOANG TRONG LAN 1 CALL DELAY CALL DELAY MOV R0.#40H.NEU CY=1 THI B LON HON A MOV ALONB.#00H.LAP3.#40H.#16.#00H.DONG20.#00H CALL POSITION2 TIEPNAO0: MOV A.LCD HOAN CHINH LONNHO2: MOV A.NEU KO BANG THI NHAY DEN SO VOI DONG 2 CALL POSITION1 JMP TIEPNAO0 DONG20: CJNE A.N.

NEU CHUA BANG THI NHAY CALL DELAY CALL DELAY CALL DELAY.HET LAN 1 DEC R2 INC N MOV R4.#50H.N. TANG R4 MOV R0.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA0: MOV A.NEU BANG THI OK JMP CHAYLEN RETI.LCD HOAN CHINH CALL CLEAR_LCD LAPX: MOV A.@R0.BOQUA0.NEU KHAC VI TRI 16 THI BO QUA SETB EN.#16.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.NEU KHAC VI TRI 16 THI BO QUA Page 17 .BOQUA1.#30H SETB EN CLR RS MOV DATAL.@R0 CALL WRITE_TEXT INC R0 CJNE R0.#0CFH CALL CHAYTRAI1 MOV R2.#0C0H.#8FH MOV R4.CHUYEN O NHO VAO A SETB EN CLR RW SETB RS MOV DATAL.#16.O NHO DAU SETB EN CLR RS MOV DATAL.LAPX. VI TRI CUOI DONG 2 CLR EN CALL WAIT_LCD LAPTRAI0: CJNE R4.#30H.LAPTRAI0 CALL DELAY.R2.KHONG CO Y NGHIA CHAYTRAI: CALL WAIT_LCD CALL CLEAR_LCD MOV R4.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4.#1 MOV R2.R4 MOV R0.R2 CLR EN CALL WAIT_LCD LAPTRAI1: CJNE R4.#17 CALL CHAYTRAI1 CALL DELAY CALL DELAY CALL DELAY JMP CHAYTRAI RETI CHAYTRAI1: MOV N.

VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA2: MOV A.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.#0C0H.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4.@R0 SETB EN CLR RW SETB RS MOV DATAL.LAPTRAI1 CALL DELAY.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4.LAPTRAI2 CALL DELAY.NEU KHAC VI TRI 16 THI BO QUA SETB EN.R2 CLR EN CALL WAIT_LCD LAPTRAI2: CJNE R4.LCD HOAN CHINH SETB EN. TANG R4 MOV R0.NEU KHAC VI TRI 16 THI BO QUA SETB EN.#16.#30H SETB EN CLR RS MOV DATAL.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA1: MOV A.N.BOQUA3.N.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.HET LAN 3 DEC R2 INC N MOV R4.BOQUA2.#0C0H.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA3: Page 18 .HET LAN 2 DEC R2 INC N MOV R4.#0C0H.#16. TANG R4 MOV R0.@R0 SETB EN CLR RW SETB RS MOV DATAL.#30H SETB EN CLR RS MOV DATAL.R2 CLR EN CALL WAIT_LCD LAPTRAI3: CJNE R4.

NEU KHAC VI TRI 16 THI BO QUA SETB EN.A CLR EN Page 19 .R2 CLR EN CALL WAIT_LCD LAPTRAI5: CJNE R4.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4.#16.@R0 SETB EN CLR RW SETB RS MOV DATAL.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA4: MOV A.#0C0H.LAPTRAI3 CALL DELAY CALL DELAY.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.LAPTRAI4 CALL DELAY.#16.@R0 SETB EN CLR RW SETB RS MOV DATAL. TANG R4 MOV R0.#30H SETB EN CLR RS MOV DATAL.NEU KHAC VI TRI 16 THI BO QUA SETB EN.BOQUA5.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4.#0C0H.LCD HOAN CHINH MOV A.BOQUA4.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA5: MOV A.R2 CLR EN CALL WAIT_LCD LAPTRAI4: CJNE R4.HET LAN 5 DEC R2 INC N MOV R4.@R0 SETB EN CLR RW SETB RS MOV DATAL.N. HET LAN 4 DEC R2 INC N MOV R4.#30H SETB EN CLR RS MOV DATAL. TANG R4 MOV R0.N.

VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA7: MOV A.#30H SETB EN CLR RS MOV DATAL.HET LAN 7 DEC R2 INC N MOV R4.N.#16.HET LAN 8 DEC R2 INC N MOV R4.R2 CLR EN CALL WAIT_LCD LAPTRAI7: CJNE R4.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4. HET LAN 6 DEC R2 INC N MOV R4. TANG R4 MOV R0.#16.N.LAPTRAI7 CALL DELAY.LAPTRAI5 CALL DELAY.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA6: MOV A.#30H SETB EN CLR RS MOV DATAL.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.NEU KHAC VI TRI 16 THI BO QUA SETB EN. TANG R4 Page 20 .BOQUA6.@R0 SETB EN CLR RW SETB RS MOV DATAL.LCD HOAN CHINH CALL WAIT_LCD INC R0 DJNZ R4.#0C0H.NEU KHAC VI TRI 16 THI BO QUA SETB EN.@R0 SETB EN CLR RW SETB RS MOV DATAL.N.R2 CLR EN CALL WAIT_LCD LAPTRAI6: CJNE R4.LAPTRAI6 CALL DELAY.#0C0H. TANG R4 MOV R0.BOQUA7.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.

BOQUA9.BOQUA8.N.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA9: MOV A.R2 CLR EN CALL WAIT_LCD LAPTRAI8: CJNE R4.LAPTRAI9 CALL DELAY.#0C0H.#16.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4.HET LAN 10 DEC R2 INC N MOV R4.LAPTRAI8 CALL DELAY.LCD HOAN CHINH MOV R0.NEU KHAC VI TRI 16 THI BO QUA SETB EN. TANG R4 MOV R0.NEU KHAC VI TRI 16 THI BO QUA SETB EN.#30H SETB EN CLR RS MOV DATAL.HET LAN 9 DEC R2 INC N MOV R4.R2 CLR EN CALL WAIT_LCD LAPTRAI10: Page 21 .@R0 SETB EN CLR RW SETB RS MOV DATAL.R2 CLR EN CALL WAIT_LCD LAPTRAI9: CJNE R4. TANG R4 MOV R0.@R0 SETB EN CLR RW SETB RS MOV DATAL.#16.#30H SETB EN CLR RS MOV DATAL.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA8: MOV A.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.N.#0C0H.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4.#30H SETB EN CLR RS MOV DATAL.

BOQUA12.#16.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.LAPTRAI10 CALL DELAY. TANG R4 MOV R0.NEU KHAC VI TRI 16 THI BO QUA SETB EN.HET LAN 12 DEC R2 INC N MOV R4.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD Page 22 .N.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.NEU KHAC VI TRI 16 THI BO QUA SETB EN.NEU KHAC VI TRI 16 THI BO QUA SETB EN.R2 CLR EN CALL WAIT_LCD LAPTRAI11: CJNE R4.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA11: MOV A.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4.#0C0H.@R0 SETB EN CLR RW SETB RS MOV DATAL.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA10: MOV A.#16.#30H SETB EN CLR RS MOV DATAL.LAPTRAI11 CALL DELAY.N. HET LAN 11 DEC R2 INC N MOV R4.BOQUA10.BOQUA11.#0C0H.#30H SETB EN CLR RS MOV DATAL.@R0 SETB EN CLR RW SETB RS MOV DATAL.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL. TANG R4 MOV R0.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4.#16.R2 CLR EN CALL WAIT_LCD LAPTRAI12: CJNE R4.LCD HOAN CHINH CJNE R4.#0C0H.

LAPTRAI13 CALL DELAY.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4.HET LAN 14 DEC R2 INC N MOV R4.R2 CLR EN CALL WAIT_LCD LAPTRAI13: CJNE R4.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA13: MOV A.BOQUA13. TANG R4 MOV R0.NEU KHAC VI TRI 16 THI BO QUA SETB EN.N.@R0 SETB EN CLR RW SETB RS MOV DATAL.LAPTRAI12 CALL DELAY.#30H SETB EN CLR RS MOV DATAL.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.LCD HOAN CHINH BOQUA12: MOV A.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4.#16.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA14: MOV A.HET LAN 13 DEC R2 INC N MOV R4.#30H SETB EN CLR RS MOV DATAL.N.BOQUA14.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.@R0 SETB EN CLR RW SETB RS MOV DATAL.R2 CLR EN CALL WAIT_LCD LAPTRAI14: CJNE R4.#16. TANG R4 MOV R0.#0C0H.@R0 SETB EN CLR RW SETB RS MOV DATAL.#0C0H.A CLR EN Page 23 .NEU KHAC VI TRI 16 THI BO QUA SETB EN.

10S THI XUONG LAI 0 INC S2.LAP2S CLR TF0 CLR TR0 RET DELAY: MOV TMOD.#0C0H.NEU DUOC 1 GIAY THI TANG S1 MOV A.S1 CJNE A.#LOW(-50000) SETB TR0 LAP1S: JNB TF0.#10.@R0 SETB EN CLR RW SETB RS MOV DATAL.HET LAN 16 RET CHONGNHIEU: MOV TMOD.LCD HOAN CHINH CALL WAIT_LCD INC R0 DJNZ R4.NEU KHAC VI TRI 16 THI BO QUA SETB EN. TANG R4 MOV R0.R2 CLR EN CALL WAIT_LCD LAPTRAI15: CJNE R4.DELAY.NEU LA VI TRI 16 THI XUONG HANG CLR RS CLR RW MOV DATAL.#20.LAPTRAI15 CALL DELAY.#00H.NEU CHUA DU 1 GIAY THI KO LAM GI MOV R4.#HIGH(-50000) MOV TL0.KOTANG MOV S1.A CLR EN CALL WAIT_LCD INC R0 DJNZ R4.N.HET LAN 15 DEC R2 INC N MOV R4.LAPTRAI14 CALL DELAY.#HIGH(-50000) MOV TL0.S2 Page 24 .NEU 60 GIAY THI TANG 1 PHUT MOV A.VI TRI DAU LCD N=80H CLR EN CALL WAIT_LCD BOQUA15: MOV A.LAP1S CLR TF0 CLR TR0 INC R4 CJNE R4.#LOW(-50000) SETB TR0 LAP2S: JNB TF0.#01H MOV TH0.BOQUA15.#16.#00H RET TANGGIO: INC S1.#30H SETB EN CLR RS MOV DATAL.#01H MOV TH0.

#6.#0FFH.#00H . XOA RS DE DU LIEU TRUYEN DEN LCD SETB RW.7.KOTANG1 MOV A.NEU 60 PHUT THI TANG 1H INC H1 MOV M2.H1 CJNE A. LENH DOC MOV DATAL.A CLR EN CALL WAIT_LCD RET WAIT_LCD: MOV R3.KOTANG.#00H MOV A.NAP LAI M1 INC M2 MOV A.TRO VE WRITE_TEXT: SETB EN CLR RW SETB RS MOV DATAL.#38H.KOTANG MOV M1.#2.#00H M2.#00H S2.#00H.M2 CJNE A.60 GIAY THI TANG 1 PHUT MOV A.#6.#00H M1. NHAY NEU BIT 7=1 NGHIA LA LCD BAN JMP XONG CHO: CLR EN CLR RW DJNZ R3.DATAL.XEM CO PHAI 24H KO CJNE A. TAT RW CHO CAC LENH KE RET SETUP_LCD: SETB EN CLR RW CLR RS MOV DATAL.#4.#10. TRUYEN DU LIEU DEN LCD MOV A. DOC TU LCD TRA VE JB ACC.#00H INC M1.LAI XONG: CLR EN.#255 LAI: SETB EN.#10.CHO. XONG LENH CLR RW.H2.#00H H1.KOTANG MOV S2.M1 CJNE A.LCD HOAN CHINH CJNE A. BAT EN DE LCD NHAN LENH CLR RS.KOTANG INC H2 JMP KOTANG HETNGAY: MOV MOV MOV MOV MOV MOV KOTANG: NOP RET.38H=20H+10H(DATA TRUYEN 8 BIT)+8H(HIEN THI 2 DONG) CLR EN CALL WAIT_LCD SETB EN Page 25 S1.KOTANG1 JMP HETNGAY KOTANG1: CJNE A.#00H H2.

** X LA HANG Y LA COT CJNE A.X.#0C0H.DONGX2.#0EH.06H= 04H+02H(SAU MOI KY TU THI CURSOR NHAY SANG PHAI) CLR EN CALL WAIT_LCD RET CLEAR_LCD: SETB EN CLR RW CLR RS MOV DATAL.TRO VE HANG 1 CLR EN CALL WAIT_LCD RET POSITION1: SETB EN.Y.#01H.NEU A KHAC 0 THI NHAY DEN HANG 1 MOV A.VI TRI CURSOR TAI 80+04H CLR EN CALL WAIT_LCD RET POSITIONN: SETB EN. THAP PHAN MUL AB.Y.#06H.X JMP TRA.N.#01H CLR EN CALL WAIT_LCD RET TRABANG: MOV A.A= Y*8+X TRA: MOVC A.#80H. CLR RS CLR RW MOV DATAL.#8.X ADD A.#8. NEU A KHAC 1 THI NHAY DEN HANG 2 MOV A.@A+DPTR.KHI Y LA COT 0 THI A=X NHAY DEN TRA KY TU DONGX1: CJNE A. CLR RS CLR RW MOV DATAL.VI TRI CURSOR TAI N CLR EN CALL WAIT_LCD RET WAIT_CHAR1: Page 26 .DONGX1.NEU Y=1 THI A=8+X JMP TRA DONGX2: MOV A.DUA Y VAO LAI DE AN TOAN MOV B.LCD HOAN CHINH CLR RW CLR RS MOV DATAL.A = Y*8<=48 LUA TRONG BYTE THAP A ADD A.#00H.0CH=08H+04H(BAT LCD ON)+02( THI MO CURSOR) CLR EN CALL WAIT_LCD SETB EN CLR RW CLR RS MOV DATAL. TRA BANG LAY KY TU VA LUU VAO A RET POSITION2: SETB EN CLR RS CLR RW MOV DATAL.

#2FH.2.@R1 CJNE A.#0FFH.R5 MOV A.#0FFH.TRACOT MOV A.#0FFH.#0FEH DOLAI: MOV P0.0 JNC TRATRA INC X MOV C.#0FFH MOV A.A INC Y MOV C.XET10.PTINH SETB EN CLR RW SETB RS MOV DATAL.A CLR EN CALL WAIT_LCD MOV R1.X.Y.ACC.#TABLE RET GHIKYTU: MOVC A.#00H MOV P2.#00H MOV R5.R5 RL A MOV R5.NEU CHUA DEN O CUOI THI TIEP TUC XET11: MOV N.3 JC TRACOT RR A JMP COTKE TRATRA: RET KETQUA: MOV A.R1 CJNE A.WAIT_CHAR1 DO: MOV Y.GHIKYTU DEC R1 MOV A.GHI RA LCD XET10: MOV A.0 ANL C.#0C2H CALL POSITIONN CALL WAIT_LCD MOV DPTR.SOAMA SETB EN CLR RW SETB RS MOV DATAL.P2 CJNE A.@A+DPTR Page 27 .A CLR EN CALL WAIT_LCD MOV A.P2 CJNE A.Y.NHAY NEU CY=1 HAY Y=5(5 HANG BAT DAU TU HANG 0) JC DO JMP DOLAI TRACOT: MOV X.#00H COTKE: SETB C ANL C.LCD HOAN CHINH CALL CHONGNHIEU MOV P0.#3DH.

' '.#0FFH.'C'.'F'.'A'.'3'.'D'.'I'.#4DH.'2'.'H'.VI A DA LA @R1 MOV @R1.'U'.'I'.A MOV @R0.'I'.#3EH.'%'.#' ' RET KETQUA1: MOV @R0.'&' TABLE1: DB '0'.'U'.':'.A INC R1 INC R0 MOV A.R1 CJNE A.'P'.'L'.'P'.KETQUA1 DEC R1 MOV A.'4'.'X'.@R0 MOV @R1.'&' TABLE2: DB 'N'.'I'.' '.'P'.'6'.'E'.'N'.'G'.'4'.'8'.'B'.' '.#2FH.'G'.'Y'.'T'.@R1 CJNE A.'W'.'A'.'O'.' '.'H'.'I'.KETQUA3 MOV R1.R1 CJNE A.':' TABLE5: DB 'K'.'P'.'8'.'5'.'A'.'U'.#5DH KETQUA2: MOV A.'N'.R1 CJNE A.'C'.DONG THOI XOA LUON O NHO TAM TU 5D DEN 50 DEC R1 DEC R0 MOV A.'9'.'R'.@R0 MOV @R1.#2FH.'6'.'Z'.'H'.'!'.' '.'Q'.'T'.'I'.' '.#40H DOICHOABPT: MOV A.'D'.'N'.'N'.' '.#2FH.'R'.'N'.'P'.'3'.'N'.' '.A.'A'.'H'.'N'.'E'.#0FFH.'B'.'P'.'1'.'I'.'A'.'A'.'7'.#2FH.'P'.KETQUA2 KETQUA4: MOV R1.'M'.'M'.'H'.'H'.'.#30H MOV R0.DONG THOI XOA LUON O NHO DAY A DEC R1 DEC R0 MOV A.#0FFH.#3DH MOV R0.'K'.'=' TABLE3: DB 'X'.'.DOICHOABPT RET TABLE: DB 'A'.#5DH KETQUA3: MOV A.'N'.'5'.'H'.'H'.'.'H'.'G'.XET10 JMP XET11 CHUYENKETQUA: MOV R1.'S'.'O'.'%'.':'.VI CHUYENKETQUA DA THAY DOI R1 MOV SOAMB.' '.'Y'.'V'.'Y'.'G'.'I'.'L'.R1 CJNE A.'7'.'T'.'O'.'J'.' ' Page 28 .'T'.A CLR EN CALL WAIT_LCD DEC R1 MOV A.' '.'O'.'T'.KETQUA2 JMP KETQUA4 DOIKETQUA: MOV R1.':'. 'V'.'N'.'0'.'S'.'A'.#3DH MOV R0.'.'T'.'A'.'Q'.':' TABLE4: DB 'X'.'9'.'Y'.' '.' '.'A'.R1 CJNE A.' '.'1'.'2'.' '.' '.LCD HOAN CHINH SETB EN CLR RW SETB RS MOV DATAL.

' ' TABLE7: DB 'D'.'^'.'A'.'U'.' '.'Q'.'T'.'I'.'N'.'N' END Page 29 .LCD HOAN CHINH TABLE6: DB 'C'.'V'.'G'.' '.'A'.'E'.'V'.'n'.'C'.'B'.' '.'i'.' '.' '.'B'.'A'.'e'.'N'.' '.' ' TABLEX: DB 'S'.'V'.' '.'O'.'i'.'H'.'U'.' '.'y'.'A'.'_'.'Y'.'I'.' '.'U'.'g'.'S'.' '.'E'.'n'.'M'.'H'.'s'.'^'.'g'.'O'.' '.'L'.' '.'O'.'T'.' '.'U'.