LED單片機(jī)定時(shí)鬧鈴程序
;*****led顯示單片機(jī)定時(shí)鬧鈴程序**************************************
; 變量地址分配
;*********************************************************
Hour EQU 3AH; 小時(shí)計(jì)數(shù)器的地址
Minute EQU 3BH; 分鐘計(jì)數(shù)器的地址
Second EQU 3CH; 秒計(jì)數(shù)器的地址
P1Val EQU 3DH; 數(shù)碼管位驅(qū)動(dòng)值的地址
ClockMode BIT 20H.0; 模式(正常走時(shí)/鬧時(shí))設(shè)置寄存器地址,
值為0時(shí)正常走時(shí),為1時(shí)鬧時(shí)設(shè)定
AlarmOnOff BIT 20H.1; 鬧鐘開(kāi)啟/關(guān)閉標(biāo)志,為0關(guān)閉,為1開(kāi)啟
AlarmTimeOn BIT 20H.2; 此位為1時(shí)表示鬧時(shí)時(shí)間到
DispHour EQU 21H; 小時(shí)顯示寄存器的地址
DispMinute EQU 22H; 分鐘顯示寄存器的地址
DispSecond EQU 23H; 秒顯示寄存器的地址
AlarmHour EQU 2EH; 鬧時(shí)小時(shí)計(jì)數(shù)器的地址
AlarmMinute EQU 2FH; 鬧時(shí)分鐘計(jì)數(shù)器的地址
k1 BIT P3.2; 鬧鐘設(shè)置鍵
k2 BIT P3.3; 小時(shí)設(shè)置鍵
k3 BIT P3.5; 分鐘設(shè)置鍵
;http://www.51hei.com
;*************************************
; 程序開(kāi)始
;*************************************
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
;**********************************************
; 定時(shí)器Timer0中斷服務(wù)程序
;**********************************************
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
;共陽(yáng)段碼表 "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
評(píng)論