Bác nào đã làm về Realtime DS12887 xin giúp em với. Em đang làm đồ án về đồng hồ điện tử sử dụng 89C51+DS12887.Không biết chương trình có sai hay ko mà sao led 7 đoạn chỉ hiển thị 969696 thôi. Đây là chương trình em viết:
Còn đây là sơ đồ phần cứng:
real time.pdf
Code:
REGA EQU 0AH REGB EQU 0BH REGSEC EQU 00H ;THANH GHI GIAY REGMIN EQU 02H ;THANH GHI PHUT REGHOUR EQU 04H ;THANH GHI GIO HOUR EQU 32H MIN EQU 31H SEC EQU 30H ORG 0000H CALL DELAY_200MS MOV HOUR,#6 MOV MIN,#0 MOV SEC,#0 MAIN: ACALL SET_RTC ACALL WRITE_HMS BAT_DAU: ACALL READ_HMS ACALL XU_LY_DU_LIEU ACALL HIEN_THI SJMP BAT_DAU ;------------------------------------------- SET_RTC: PUSH 00H PUSH ACC MOV R0,#REGA MOV A,#20H MOVX @R0,A MOV R0,#REGB MOV A,#06H MOVX @R0,A POP ACC POP 00H RET ;--------------------------------------------- WRITE_HMS: PUSH 00H PUSH ACC MOV R0,#REGSEC MOV A,SEC MOVX @R0,A MOV R0,#REGMIN MOV A,MIN MOVX @R0,A MOV R0,#REGHOUR MOV A,HOUR MOVX @R0,A POP ACC POP 00H RET ;---------------------------------------------- READ_HMS: PUSH 00H PUSH ACC MOV R0,#REGSEC MOVX A,@R0 MOV 34H,A MOV R0,#REGMIN MOVX A,@R0 MOV 35H,A MOV R0,#REGHOUR MOVX A,@R0 MOV 36H,A POP ACC POP 00H RET ;---------------------------------------------- XU_LY_DU_LIEU: CALL TM_GIAY CALL TM_PHUT CALL TM_GIO RET TM_GIAY: MOV A,34H CALL BINTOBCD MOV R6,A ANL A,#0FH CALL TRA_BANG MOV 40H,A MOV A,R6 SWAP A ANL A,#0FH CALL TRA_BANG MOV 41H,A RET TM_PHUT: MOV A,35H CALL BINTOBCD MOV R6,A ANL A,#0FH CALL TRA_BANG MOV 42H,A MOV A,R6 SWAP A ANL A,#0FH CALL TRA_BANG MOV 43H,A RET TM_GIO: MOV A,36H CALL BINTOBCD MOV R6,A ANL A,#0FH CALL TRA_BANG MOV 44H,A MOV A,R6 SWAP A ANL A,#0FH CALL TRA_BANG MOV 45H,A RET BINTOBCD: MOV B,#10 DIV AB SWAP A ADD A,B RET TRA_BANG: MOV DPTR,#TABLE MOVC A,@A+DPTR RET TABLE: DB 0A0H,0F9H,0A4H,0D0H,99H,92H,82H,0F8H,80H,90H ;------------------------------------------ HIEN_THI: MOV P2,#0FEH MOV P1,40H CALL DELAY_2MS MOV P2,#0FDH MOV P1,41H CALL DELAY_2MS MOV P2,#0FBH MOV P1,42H CALL DELAY_2MS MOV P2,#0F7H MOV P1,43H CALL DELAY_2MS MOV P2,#0EFH MOV P1,44H CALL DELAY_2MS MOV P2,#0DFH MOV P1,45H CALL DELAY_2MS RET ;---------------------------------------------- DELAY_2MS: PUSH 07H PUSH 06H MOV R7,#4 NHAY3: MOV R6,#250 DJNZ R6,$ DJNZ R7,NHAY3 POP 06H POP 07H RET ;--------------------------------------------- DELAY_200MS: PUSH 07H PUSH 06H PUSH 05H MOV R7,#2 BACK2: MOV R6,#200 BACK1: MOV R5,#250 DJNZ R5,$ DJNZ R6,BACK1 DJNZ R7,BACK2 POP 05H POP 06H POP 07H RET END
real time.pdf
Comment