📄 clock1.asm
字号:
;==========TIME LED===========
;OSC=12MHZ
;2006/03/19
;========程序向量入口处========
ORG 0000H
AJMP Main
ORG 0003H
RETI
ORG 000bH
AJMP Scan
ORG 0013H
AJMP Music
ORG 001bH
RETI
ORG 0023H
RETI
ORG 002bH
RETI
;========定义寄存器===========
TagBuf0 data 20H
SecTag Bit 00H
Timetag Bit 01H
DateTag Bit 02H
WeekTag Bit 03H
YearTag Bit 04H
ModeTag Bit 05H
AdjTag1 Bit 06H
AdjTag2 Bit 07H
;-----------------------
TagBuf1 data 21H
AdjTag3 Bit 08H
AdjTag4 Bit 09H
OnTag1 Bit 0aH
OffTag1 Bit 0bH
OnTag2 Bit 0cH
OffTag2 Bit 0dH
OnTag3 Bit 0eH
OffTag3 Bit 0fH
;-----------------------
TagBuf2 data 22H
DotTag1 Bit 10H
DotTag2 Bit 11H
OnTag Bit 12H
OffTag Bit 13H
LedTag Bit 14H
RingTag Bit 15H
;=======================
Days data 23H ; 判断每个月的天数
Second data 24H ; 时间寄存器
Minute data 25H
Hour data 26H
Day data 27H
Month data 28H
Week data 29H
Year data 2aH
Cent data 2bH
;=======================
RingBuf data 2cH
;-----------------------
OnHour1 data 2dH
OnMin1 data 2eH
OffHour1 data 2fH
OffMin1 data 30H
;-----------------------
OnHour2 data 31H
OnMin2 data 32H
OffHour2 data 33H
OffMin2 data 34H
;-----------------------
OnHour3 data 35H
OnMin3 data 36H
OffHour3 data 37H
OffMin3 data 38H
;-----------------------
OnHour3 data 39H
OnMin3 data 3AH
OffHour3 data 3BH
OffMin3 data 3CH
;=======================
Ledbuf1 data 3DH
Ledbuf2 data 3EH
Ledbuf3 data 3FH
Ledbuf4 data 40H
WorkBuf1 data 41H
WorkBuf2 data 42H
;=======================
MuiBuf1 data 43H
MuiBuf2 data 44H
MuiBuf3 data 45H
MuiBuf4 data 46H
;=======================
LedCount data 47H
KeyCount data 48H
ModeBuf data 49H
ShowBuf1 data 4AH
ShowBuf2 data 4BH
ShowBuf3 data 4cH
;=======================
Port1 data 90H
Led_A Bit 90H
Led_B Bit 91H
Led_C Bit 92H
Led_D Bit 93H
Led_E Bit 94H
Led_F Bit 95H
Led_G Bit 96H
SCLK Bit 96H
Led_DP Bit 97H
SDATA Bit 97H
;----------------------
Port3 data 0B0H
ModeKey Bit 0B0H
LedCom1 Bit 0B0H
HourKey Bit 0B1H
LedCom2 Bit 0B1H
MinKey Bit 0B2H
LedCom3 Bit 0B2H
YesKey Bit 0B3H
LedCom4 Bit 0B3H
KeyPort Bit 0B4H
RstPort Bit 0B5H
MuiPort Bit 0B6H
;--------工作寄存器--------
Bank00 data 00H
Bank01 data 08H
Bank10 data 10H
Bank11 data 18H
;---------堆栈设置---------
Stacks data 50H
LedNub data 04H
KeyNub data 04H
;==============主程序开始===============
Main: MOV Port1,#00H
MOV Port3,#00H ; 端口初始化
MOV PSW,#00H
MOV SP,#Stacks
MOV R1,#20H
CLR A
Power: MOV @R1,A
INC R1
CJNE R1,#80H,Power
MOV LedCount,#LedBuf1; 从第一数码管扫描
MOV IP,#00H
MOV IE,#82H ; 设置中断
MOV TMOD,#02H ; 00000010B,Gate=0,C/T=0,M1M0=10,
MOV TH0,#0fah
MOV TL0,#0fah ; 定义中断扫描时间
SETB TR0
Main0: JNB RingTag,$
ACALL MuiStart
SJMP Main0
;============调声音子程序==============
MuiStart: MOV MuiBuf4,#00H
MuiNext: MOV A,MuiBuf4
MOV DPTR,#MuiTab
MOVC A,@A+DPTR
MOV R2,A ; 暂存R2
JZ MuiExit ; ?A=0,是 跳结束
ANL A,#0FH
MOV R5,A ; 存入节拍码
MOV A,R2
SWAP A
ANL A,#0FH ; 得出音符码
JNZ MuiSing ; ?A=0,否 跳发音
CLR TR1 ; 禁止启动定时器
AJMP MuiDelay
MuiSing: DEC A
MOV MuiBuf3,A ; 音符暂存MuiBuf3
RL A ; 因为是16字节必须乘以2倍
MOV DPTR,#MuiTab1
MOVC A,@A+DPTR
MOV TH1,A
MOV MuiBuf2,A ; 取到高字节存入TH0与MuiBuf2
MOV A,MuiBuf3 ; 还原音符码
RL A
INC A ; 查低字节
MOV DPTR,#MuiTab1
MOVC A,@A+DPTR
MOV TL1,A
MOV MuiBuf1,A ; 取到低字节存入TL0与MuiBuf1
SETB TR1 ; 启动定时器
MuiDelay: CALL Delay10
INC MuiBuf4
AJMP MuiNext
MuiExit: CLR TR1 ; 禁止启动定时器
RET
;----------------------------
MuiTab: DB 042H,082H,082H,082H,084H,002H,072H
DB 062H,072H,062H,052H,048H
DB 0B2H,0B2H,0B2H,0B2H,0B4H,002H,0A2H ;//1
DB 012H,0A2H,0D2H,092H,088H
DB 082H,0B2H,0B2H,0A2H,084H,002H,072H
DB 062H,072H,062H,052H,044H,002H,012H ;//2
DB 012H,062H,062H,052H,044H,002H,082H
DB 072H,062H,052H,032H,048H,000H ;//3
;----------------------------
MuiTab1: DW 64021,64103,64260,64400,64524,64580,64684,64777
DW 64820,64898,64968,65030,64934
;=============================
Music: PUSH DPL
PUSH DPH
PUSH A ; 现场保护
PUSH B
PUSH PSW
MOV PSW,#Bank11
MOV TL1,MuiBuf1
MOV TH1,MuiBuf2 ; 重新装入新值
CPL MuiPort ; 取反,发出声音
POP PSW ; 恢复现场
POP A
POP B
POP DPH
POP DPL ; 注意先进后出
RETI ; 中断返回
;===========================
NumTab: DB 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh,00H ; 显示代码
;// 0 1 2 3 4 5 6 7 8 9 暗 ; 显示数字
;===========================
Scan: CLR EA
PUSH DPL
PUSH DPH
PUSH A
PUSH B
PUSH PSW
MOV PSW,#Bank01
CPL LedTag ; 消隐
JB LedTag,Scan0
MOV Port1,#00H
ANL Port3,#0Fh
ACALL GetTime ; 不显示,并刷新时间
ACALL GetShow ; 调准备显示模式
ScanRet: CLR TF0
POP PSW
POP B
POP A
POP DPH
POP DPL
SETB EA
RETI
;-----------------------------------
Scan0: PUSH DPL
PUSH DPH ; 数据保护
MOV R0,LedCount
MOV DPTR,#NumTab ;指定查表启始地址
DispLed1: MOV A,@R0
MOVC A,@A+DPTR
CJNE R0,#LedBuf1,DispLed2
SETB LedCom1;//P3.0
JNB DotTag1,DispLed2
SETB ACC.7
DispLed2: CJNE R0,#LedBuf2,DispLed3
SETB LedCom2;//P3.1
JNB DotTag2,DispLed3
SETB ACC.7
DispLed3: CJNE R0,#LedBuf3,DispLed4
SETB LedCom3;//P3.2
JNB OnTag,DisLed4
SETB ACC.7
DispLed4: CJNE R0,#LedBuf4,DispLed
SETB LedCom4;//P3.3
JNB OffTag,DispLed
SETB ACC.7
DispLed: MOV Port1,A
POP DPH
POP DPL
INC KeyCount
INC LedCount
JNB KeyPort,KeyDown
;--------------------------------
Scan1: MOV R0,LedCount
CJNE R0,#LedBuf4,ScanRet
MOV LedCount,#LedBuf1
MOV KeyCount,#00H
AJMP ScanRet
;--------------------------------
KeyDown: ACALL Sound
MOV ShowBuf1,#50H
MOV ShowBuf2,#0a0H
MOV ShowBuf3,#0a0H
MOV A,KeyCount
KeyDown1: CJNE A,#01H,KeyDown2
INC ModeBuf
MOV A,ModeBuf
AJMP ModeSet
KeyDown2: CJNE A,#02H,KeyDown3
MOV R1,WorkBuf1
INC @R1
MOV A,@R1
DA A
MOV @R1,A
AJMP Scan1
KeyDown3: CJNE A,#03H,KeyDown4
MOV R1,WorkBuf2
INC @R1
MOV A,@R1
DA A
MOV @R1,A
AJMP Scan1
KeyDown4: CJNE A,#04H,Scan1
AJMP Scan1
;-------------------------------
ModeSet: SUBB A,#0CH ; 总共11种模式
JNC ModeRet
JB ModeTag,ModeSet1
CLR C
MOV A,TagBuf0
JNZ ModeSet1
MOV TagBuf1,#00H
SETB C
ModeSet1: RLC A
MOV TagBuf0,A
AJMP ModeSet4
ModeSet2: CLR C
MOV A,TagBuf1
JNZ ModeSet2
MOV TagBuf0,#00H
SETB C
ModeSet3: RLC A
MOV TagBuf1,A
AJMP Scan1
ModeSet4: INC WorkBuf1
INC WorkBuf2
ModeRet: MOV ModeBuf,#00H
MOV TagBuf0,#00H
MOV TagBuf1,#00H
MOV ShowBuf1,#00H
MOV ShowBuf2,#00H
MOV ShowBuf3,#00H
SJMP Scan1
;===================================
GetTime:
;===================================
GetShow: MOV A,ShowBuf
JZ ShowTime
DJNZ ShowBuf,ShowTime
ANL TagBuf2,#0fH
ShowTime: JNB TimeTag,ShowDate
MOV R0,#Minute
ORL TagBuf,#0f0H ; 四点全部点亮
SJMP ShowLed
ShowDate: JNB DateTag,ShowWeek
MOV R0,#Day
SJMP ShowLed
ShowWeek: JNB WeekTag,ShowYear
MOV R0,#Week
SJMP ShowLed2
ShowYear: JNB WeekTag,ShowOn1
MOV R0,#Year
SJMP ShowLed2
ShowSec: JNB SecTag,ShowYear
MOV R0,#Day
ShowLed2: MOV LedBuf3,#0AH
MOV LedBuf4,#0AH
MOV R2,#01H
SJMP ShowLed1
;------------------------------
ShowOn1: JNB OnTag1,ShowOff1
MOV R0,#OnMin1
SETB OnTag
SJMP ShowLed
ShowOff1: JNB OffTag1,ShwOn2
MOV R0,#OffMin1
SETB OffTag
SJMP ShowLed
ShowOn2: JNB OnTag1,ShowOff3
MOV R0,#OnMin2
SETB OnTag
SJMP ShowLed
ShowOff2: JNB OffTag2,ShwOn2
MOV R0,#OffMin2
SETB OffTag
SJMP ShowLed
ShowOn3: JNB OnTag1,ShowOff1
MOV R0,#OnMin3
SETB OnTag
SJMP ShowLed
ShowOff3: JNB OffTag1,ShowLed0
MOV R0,#OffMin3
SETB OffTag
SJMP ShowLed
ShowLed: SETB DotTag1
SETB DotTag2
ShowLed0: MOV R1,#LedBuf1
MOV R2,#02H
ShowLed1: MOV A,@R0
ANL A,#0FH
MOV @R1,A
INC R1
MOV A,@R0
SWAP A
ANL A,#0FH
MOV @R1,A
INC R0
INC R1
DJNZ R2,ShowLed1
RET
;------------写HT1380子程序----------
Write: CLR SCLK
NOP
MOV R7,#08H
Write1: RRC A
MOV SDATA,C
NOP
SETB SCLK
NOP
CLR SCLK
DJNZ R7,Write1
RET
;------------读HT1380子程序----------
Read: CLR A
CLR C
MOV R7,#08H
Read1: NOP
MOV C,SDATA
RRC A
SETB SCLK
NOP
CLR SCLK
DJNZ R7,Read1
RET
Init1380: CLR RstPort
NOP
CLR SCLK
NOP
SETB RstPort
MOV A,#81H
LCALL Write
LCALL Read
JNB ACC.7,InitA
MOV A,#8EH
LCALL Write
MOV A,#00H
LCALL Write
MOV A,#80H
LCALL Write
MOV A,#00H
LCALL Write
MOV A,#8EH
LCALL Write
MOV A,#80H
LCALL Write
InitA: NOP
CLR RstPort
RET
;==========声音子程序===========
Sound: MOV R5,#25 ; R6*R5决定响时间长短
Sound1: MOV R6,#25
Sound2: CPL MuiPort ; 反相产生正弦波(产生声)
MOV R7,#100
Sound3: DJNZ R7,Sound3 ; R7延时决定响声频率高低
DJNZ R6,sound2
DJNZ R5,sounD1
CLR MuiPort ; 清零端电压后返回
RET
;==========延时子程序===========
Delay: MOV R5,#05H
Delay10: MOV R6,#125;//#0faH ; 延时125ms子程序
Delay11: MOV R7,#250;//#0faH
Delay12: JNB KeyPort,Quit
DJNZ R7,Delay12
DJNZ R6,Delay11
DJNZ R5,Delay10
RET
Quit: CLR RingTag
CLR TR1
RET
END ;//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -