LED單片機(jī)定時鬧鈴程序
ConvertoBuffer:
MOV R1,#30H
JB ClockMode,DispAlarmSet
MOV A,Second;
MOV DispSecond,A;
MOV A,Minute;
MOV Dispminute,A;
MOV A,Hour;
MOV DispHour,A
AJMP Convert
DispAlarmSet:
JB AlarmOnOff,AlarmOn
MOV DispSecond,#00H
AJMP Next
AlarmOn:
MOV DispSecond,#11
Next:
MOV A,AlarmMinute
MOV Dispminute,A
MOV A,AlarmHour
MOV DispHour,A
Convert:
MOV A,DispSecond
MOV B,#10
DIV AB
MOV @R1,B
INC R1
MOV @R1,A
INC R1
MOV A,DispMinute
MOV B,#10
DIV AB
MOV @R1,B
INC R1
MOV @R1,A
INC R1
MOV A,DispHour
MOV B,#10
DIV AB
MOV @R1,B
INC R1
MOV @R1,A
RET
;*************************************
; 鬧時設(shè)置子程序
;*************************************
AlarmSet:
JNB K1,$
LCALL Delay
CheckArmMinuteKey:
JB K3,CheckArmHourKey
CL1: SETB AlarmOnOff
MOV A,AlarmMinute
ADD A,#1
MOV AlarmMinute,A
CJNE A,#60,ArmNotOver1
MOV AlarmMinute,#0
ArmNotOver1:
JNB K3,$
CheckArmHourKey:
JB K2,AlarmSetEnd
SETB AlarmOnOff
MOV A,AlarmHour
ADD A,#1
MOV AlarmHour,A
CJNE A,#24,ArmNotOver2
MOV AlarmHour,#0
ArmNotOver2:
JNB K2,$
JB K3,AlarmSetEnd
ACALL CL1
AlarmSetEnd:
JB K1,AlarmSet
JNB K1,$
CLR ClockMode
RET
;**************************************
; 鬧時服務(wù)子程序
;**************************************
LOOP:
CLR P1.7
ACALL Delay1
SETB P1.7
JB K1,LOOP
JNB K1,$
CLR AlarmOnOff
CLR AlarmTimeOn
AlarmReturn: RET
;**************************************
; 延時子程序
;**************************************
DELAY1: MOV R3,#15
LOOP1: MOV R5,#90
NOP
LOOP2: DJNZ R5,LOOP2
DJNZ R3,LOOP1
RET
Delay:
MOV R6,#05H
Del:
MOV R7,#08Fh
DJNZ R7,$
DJNZ R6,Del
RET
END
這個程序到這里就完畢了,再來一個簡單一點(diǎn)的單片機(jī)定時鬧鈴程序,不過不帶led顯示,定時1秒,要其他時間自己修改R0和R1的就可以了。
ORG 0000H
;LJMP MAIN
;ORG 0030H
;MAIN:MOV SP,#60H
MOV TMOD,#02H
MOV TL0,#06H
MOV TH0,#06H
MOV R0,#100
MOV R1,#20
SETB TR0
WAIT:JNB TF0,$
CLR TF0
DJNZ R1,WAIT
MOV R1,#20
DJNZ R0,WAIT
MOV R0,#100
CPL P1.0
AJMP WAIT
END
評論