=書無情=
|
分享:
▲
▼
RS REG P2.0 RW REG P2.1 EN REG P2.2 CURSOR EQU 36H ; ORG 00H AJMP START ORG 0BH AJMP TIMER0 ;------ ; MAIN ;------ START: MOV SP,#60H SETB P2.7 ;OFF LED SETB F0 ;DISPLAY TIME ACALL INIT ;INITIAL RAM & LCD ACALL SET ;SET TIMER 0 LOOP: JNB TR0,S0 ACALL CONV ;BCD TO ASCII MOV A,#84H ;SET ROW ADDRESS ACALL W_INS ACALL DISP ;LCD DISPLAY DATA ACALL COMP ;COMPARE TIME & ALARM S0: ACALL SCAN CJNE R4,#0,S1 ACALL KEY1 S1: CJNE R4,#1,S2 ACALL KEY2 S2: CJNE R4,#2,S3 ACALL KEY3 S3: CJNE R4,#3,LOOP ACALL KEY4 SJMP LOOP ;------ ; KEY1 ;------ KEY1: PUSH A ;TIME/ALARM JB P2.7,K1 SETB P2.7 SJMP K2 K1: CPL F0 ;F0=1/0,TIME/ALARM K2: POP A RET ;------ ; KEY2 ;------ KEY2: PUSH A ;UP JB TR0,T7 MOV A,#30H JB F0,TIME ADD A,#3 TIME: MOV R0,A ;R0=30H or 33H MOV R1,CURSOR CJNE R1,#84H,T1 MOV A,#10H ;ADJUST HOUR10 ADD A,@R0 MOV @R0,A ANL A,#F0H CJNE A,#20H,T0 MOV A,@R0 ANL A,#0FH MOV @R0,A T0: CJNE A,#30H,T6 MOV A,@R0 ANL A,#0FH MOV @R0,A T1: CJNE R1,#85H,T2 MOV A,@R0 ;ADJUST HOUR ADD A,#1 DA A MOV @R0,A CJNE A,#24H,T6 MOV @R0,#0 T2: INC R0 ;R0=31H or 34H CJNE R1,#87H,T3 MOV A,#10H ;ADJUST MIN10 ADD A,@R0 MOV @R0,A ANL A,#F0H CJNE A,#60H,T6 MOV A,@R0 ANL A,#0FH MOV @R0,A T3: CJNE R1,#88H,T4 MOV A,@R0 ;ADJUST MIN ADD A,#1 DA A MOV @R0,A CJNE A,#60H,T6 MOV @R0,#0 T4: INC R0 ;R0=32H or 35H CJNE R1,#8AH,T5 MOV A,@R0 ;ADJUST SEC10 MOV A,#10H ADD A,@R0 MOV @R0,A ANL A,#F0H CJNE A,#60H,T6 MOV A,@R0 ANL A,#0FH MOV @R0,A T5: CJNE R1,#8BH,T6 MOV A,@R0 ;ADJUST SEC ADD A,#1 DA A MOV @R0,A CJNE A,#60H,T6 MOV @R0,#0 T6: ACALL CONV MOV A,#0CH ;NO CURSOR ACALL W_INS MOV A,#84H ;DISPLAY TIME/ALARM ACALL W_INS ACALL DISP MOV A,#0EH ;DISPLAY CURSOR ACALL W_INS MOV A,CURSOR ACALL W_INS T7: POP A RET ;------ ; KEY3 ;------ KEY3: PUSH A ;SELECT JB TR0,S7 MOV A,CURSOR DEC A CJNE A,#89H,S4 DEC A S4: CJNE A,#86H,S5 DEC A S5: CJNE A,#83H,S6 MOV A,#8BH S6: ACALL W_INS MOV CURSOR,A S7: POP A RET ;------ ; KEY4 ;------ KEY4: PUSH A ;ADJUST/EXCUTE CPL TR0 JNB TR0,S8 MOV A,#0CH ;NO CURSOR ACALL W_INS SJMP S9 S8: MOV A,#0EH ;DISPLAY CURSOR ACALL W_INS MOV A,#8BH ACALL W_INS MOV CURSOR,A S9: POP A RET ;---------- ; SCAN KEY ;---------- SCAN: MOV R4,#0 MOV R7,#2 ;COLUME NUM MOV R5,#11111110B MOV A,R5 COL: MOV P3,A JB P3.2,S10 JNB P3.2,$ ;DEBOUNCE SJMP EXIT1 S10: INC R4 JB P3.3,S11 JNB P3.3,$ ;DEBOUNCE SJMP EXIT1 S11: INC R4 MOV A,R5 RL A MOV R5,A DJNZ R7,COL EXIT1: RET ;------------ ; SET TIMER0 ;------------ SET: MOV R3,#100 MOV TMOD,#01H MOV IE,#10000010B MOV TH0,#>(65536-10000) MOV TL0,#<(65536-10000) SETB TR0 RET ;---------------- ; INIT RAM & LCD ;---------------- INIT: MOV CURSOR,#8BH ;CURSOR ADDRESS MOV R0,#6 MOV R1,#30H CLR A NEXT0: MOV @R1,A INC R1 DJNZ R0,NEXT0 MOV R0,#8 MOV R1,#40H CLR A NEXT1: MOV @R1,A INC R1 DJNZ R0,NEXT1 ; MOV A,#38H ACALL W_INS MOV A,#38H ACALL W_INS MOV A,#38H ACALL W_INS MOV A,#38H ACALL W_INS MOV A,#08H ;FUNCTION SET ACALL W_INS MOV A,#01H ;CLEAR DISPLAY ACALL W_INS MOV A,#06H ;INPUT MODE SET ACALL W_INS MOV A,#0CH ;DISPLAY ON/OFF ACALL W_INS RET ;-------------- ; BCD TO ASCII ;-------------- CONV: MOV A,#30H JB F0,S12 ADD A,#3 S12: MOV R0,A MOV A,@R0 SWAP A ANL A,#0FH ADD A,#30H MOV 40H,A MOV A,@R0 ANL A,#0FH ADD A,#30H MOV 41H,A MOV 42H,#":" INC R0 MOV A,@R0 SWAP A ANL A,#0FH ADD A,#30H MOV 43H,A MOV A,@R0 ANL A,#0FH ADD A,#30H MOV 44H,A MOV 45H,#":" INC R0 MOV A,@R0 SWAP A ANL A,#0FH ADD A,#30H MOV 46H,A MOV A,@R0 ANL A,#0FH ADD A,#30H MOV 47H,A RET ;---------------------- ; COMPARE TIME & ALARM ;---------------------- COMP: PUSH A MOV R0,#30H MOV R1,#33H MOV R2,#3 NEXT2: CLR C MOV A,@R0 SUBB A,@R1 JNZ EXIT2 INC R0 INC R1 DJNZ R2,NEXT2 CLR P2.7 EXIT2: POP A RET ;-------------------- ; DISPLAY TIME/ALARM ;-------------------- DISP: MOV R1,#8 MOV R0,#40H DSP: MOV A,@R0 ACALL W_DATA INC R0 DJNZ R1,DSP RET ;------------------ ; WRITE INS TO LCD ;------------------ W_INS: ACALL CHECK CLR RS CLR RW SETB EN MOV P1,A CLR EN RET ;------------------- ; WRITE DATA TO LCD ;------------------- W_DATA: ACALL CHECK SETB RS CLR RW SETB EN MOV P1,A CLR EN RET ;---------------- ; CHECK LCD BUSY ;---------------- CHECK: PUSH A BUSY: CLR RS SETB RW SETB EN MOV A,P1 CLR EN JB ACC.7,BUSY ACALL DELAY POP A RET ;------- ; DELAY ;------- DELAY: MOV R6,#20 D1: MOV R7,#150 DJNZ R7,$ DJNZ R6,D1 RET ;------- ; JUDGE ;------- JUDGE: MOV A,32H ADD A,#1 DA A MOV 32H,A CJNE A,#60H,FIX MOV 32H,#00 MOV A,31H ADD A,#1 DA A MOV 31H,A CJNE A,#60H,FIX MOV 31H,#00 MOV A,30H ADD A,#1 DA A MOV 30H,A CJNE A,#24H,FIX MOV 30H,#00 FIX: RET ;-------- ; TIMER0 ;-------- TIMER0: PUSH A ;TIMER 1 SEC MOV TH0,#>(65536-10000) MOV TL0,#<(65536-10000) DJNZ R3,EXIT3 MOV R3,#100 ACALL JUDGE EXIT3: POP A RETI END
|