LED单片机定时闹铃程序
;*****led显示单片机定时闹铃程序**************************************
; 变量地址分配
;*********************************************************
Hour EQU 3AH; 小时计数器的地址
Minute EQU 3BH; 分钟计数器的地址
Second EQU 3CH; 秒计数器的地址
P1Val EQU 3DH; 数码管位驱动值的地址
ClockMode BIT 20H.0; 模式(正常走时/闹时)设置寄存器地址,
值为0时正常走时,为1时闹时设定
AlarmOnOff BIT 20H.1; 闹钟开启/关闭标志,为0关闭,为1开启
AlarmTimeOn BIT 20H.2; 此位为1时表示闹时时间到
DispHour EQU 21H; 小时显示寄存器的地址
DispMinute EQU 22H; 分钟显示寄存器的地址
DispSecond EQU 23H; 秒显示寄存器的地址
AlarmHour EQU 2EH; 闹时小时计数器的地址
AlarmMinute EQU 2FH; 闹时分钟计数器的地址
k1 BIT P3.2; 闹钟设置键
k2 BIT P3.3; 小时设置键
k3 BIT P3.5; 分钟设置键
;http://www.51hei.com
;*************************************
; 程序开始
;*************************************
ORG 0000H
AJMP Main
ORG 0BH
AJMP TimeInt
ORG 0020H
Main:
MOV SP,#70H
MOV 39H,#14H
MOV Hour,#12
MOV Minute,#00
MOV Second,#00
MOV AlarmHour,#06
MOV AlarmMinute,#00
CLR ClockMode
CLR AlarmTimeOn
SETB p1.7
MOV TMOD,#00000001B
MOV TH0,#03CH
MOV TL0,#0B0H
MOV IE, #82H
SETB TR0
L1:
JB K1,CheckMinuteKey
LCALL Delay
JB K1,CheckMinuteKey
SETB ClockMode
LCALL AlarmSet
CheckMinuteKey:
JB K3,CheckHourKey
MOV A,Minute
ADD A,#1
MOV Minute,A;
CJNE A,#60,NotOver1
MOV Minute,#0
NotOver1:
JNB K3,$
CheckHourKey:
JB K2,CheckAlarm
MOV A,Hour
ADD A,#1
MOV Hour,A
CJNE A,#24,NotOver2
MOV Hour,#0
NotOver2:
JNB K2,$
CheckAlarm: ;
JNB AlarmTimeOn,ToReturn
LCALL LOOP
ToReturn:
AJMP L1
;**********************************************
; 定时器Timer0中断服务程序
;**********************************************
TimeInt:
MOV TH0,#03CH
MOV TL0,#0B0H
PUSH ACC
PUSH PSW
SETB RS0
CLR RS1
DJNZ 39H,NotoneSecond
MOV 39H,#14H
LCALL Clock
LCALL ConvertoBuffer
NotoneSecond:
LCALL ScanDisplay
POP PSW
POP ACC
RETI
ScanDisplay:
MOV R1,#30H
MOV R4,#11111110B
MOV A,R4
PLAY:
MOV P2,A
MOV A,@R1
MOV DPTR,#TAB
MOVC A,@A+DPTR
MOV P0,A
LCALL Delay
INC R1
MOV A,R4
RL A
JNB ACC.6,LD1
MOV R4,A
AJMP PLAY
LD1: RET
TAB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0FFH
;共阳段码表 "0""1""2" "3""4""5""6""7" "8""9""不亮"
Clock:
MOV A,Second
ADD A,#1
MOV Second,A
CJNE A,#3CH,NotOverFlow
MOV Second,#0
MOV A,Minute
ADD A,#1
MOV Minute,A
CJNE A,#3CH,NotOverFlow
MOV Minute,#0
MOV A,Hour
ADD A,#1
MOV Hour,A
CJNE A,#18H,NotOverFlow
MOV Hour,#0
NotOverFlow:
JNB AlarmOnOff,NotAlarm
MOV A,Minute
CJNE A,AlarmMinute,NotAlarm
MOV A,Hour
CJNE A,AlarmHour,NotAlarm
SETB AlarmTimeOn
NotAlarm:
RET
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
;*************************************
; 闹时设置子程序
;*************************************
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
;**************************************
; 闹时服务子程序
;**************************************
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
- FPGA的DSP性能揭秘(06-16)
- 基于单片机通用引脚的软件UART设计(10-16)
- 分时操作系统思想在单片机中的具体应用 (10-30)
- 基于AT89C51+DSP的双CPU伺服运动控制器的研究(05-26)
- 关于RTX51 TINY的分析与探讨(05-30)
- 基于MC9S12DGl28单片机的智能寻迹车设计(04-03)