汇编实现数码管显示年月日时分秒星期温度按键可调万年历.docx
《汇编实现数码管显示年月日时分秒星期温度按键可调万年历.docx》由会员分享,可在线阅读,更多相关《汇编实现数码管显示年月日时分秒星期温度按键可调万年历.docx(25页珍藏版)》请在冰豆网上搜索。
![汇编实现数码管显示年月日时分秒星期温度按键可调万年历.docx](https://file1.bdocx.com/fileroot1/2023-5/20/649e9f5f-d7b5-48b4-afda-01d9ec11a163/649e9f5f-d7b5-48b4-afda-01d9ec11a1631.gif)
汇编实现数码管显示年月日时分秒星期温度按键可调万年历
;///////////////////////////////////////////
;本程序源代码由湖南工程职业技术学院提供.
;专业单片机培训,让你学习单片机更容易.
;程序员:
蒋庆桥
;QQ:
xxxxxxxxx
;本程序用汇编实现数码管显示年,月,日,时,分,秒,星期,温度,按键可调万年历,
H_ADJBITP3.0;时/年调整
M_ADJBITP3.1;分/月调整
S_ADJBITP1.4;秒/日调整
DT_SETBITP1.6;时间/日期选择
STRBITP1.5;启动走时
T_RSTBITP1.0;实时时钟复位线引脚
T_CLKBITP1.1;实时时钟时钟线引脚
T_IOBITP1.2;实时时钟数据线引脚
HH_BITEQU40H;时高位
HL_BITEQU41H;时低位
MH_BITEQU42H;分高位
ML_BITEQU43H;分低位
SH_BITEQU44H;秒高位
SL_BITEQU45H;秒低位
TEMPER_LEQU46H
TEMPER_HEQU47H
YH_BITEQU48H;年高位
YL_BITEQU49H;年低位
MOH_BITEQU4aH;月高位
MOL_BITEQU4bH;月低位
DH_BITEQU4cH;日高位
DL_BITEQU4dH;日低位
SECEQU30H
MINEQU31H
HOUREQU32H
DAYEQU33H
MONTHEQU34H
WEEKEQU35H
YEAREQU36H
TEMPERequ37h
FLAG1BIT20h.0;DS18B20存在标志位
DQBITP1.3
A_BITEQU55H
B_BITEQU56H
DS1302_ADDREQU5EH
DS1302_DATAEQU5FH
ORG00H
LJMPSTART
START:
MOVSP,#60H
MOVTMOD,#11H
MOVTH0,#3CH
MOVTL0,#0B0H
MOVR0,#10
SETBEA
SETBET0
SETBTR0
MOVR1,37H
MOVYEAR,#13H;上电预置日期、时间
MOVWEEK,#03H;周1MON
MOVMONTH,#07H;2011042512:
00:
00
MOVDAY,#05H
MOVHOUR,#23H
MOVMIN,#00H
MOVSEC,#00H
MOV50H,#0
///////////////////////////////////////////////////////////////////////////
MAIN:
LCALLKEY
//MAIN2:
CALLFENLI
LCALLINIT_18B20
LCALLGET_TEMPER
callCHANGE
calldisp
calldisplay
AJMPMAIN
FENLI:
MOVA,YEAR
MOVB,#10H
DIVAB
MOVYL_BIT,B
MOVYH_BIT,A
MOVA,MONTH
MOVB,#10H
DIVAB
MOVMOL_BIT,B
MOVMOH_BIT,A
MOVA,DAY
MOVB,#10H
DIVAB
MOVDL_BIT,B
MOVDH_BIT,A
MOVA,HOUR
MOVB,#10H
DIVAB
MOVHL_BIT,B
MOVHH_BIT,A
MOVA,MIN
MOVB,#10H
DIVAB
MOVML_BIT,B
MOVMH_BIT,A
MOVA,SEC
MOVB,#10H
DIVAB
MOVSL_BIT,B
MOVSH_BIT,A
RET
KEY:
;按键子程序
JBF0,MAIN10;F0=1,开始走时。
走时前写,不读。
走时后读,不写。
LCALLWR1302
AJMPkey_set
MAIN10:
LCALLRD1302
KEY_SET:
JBDT_SET,KEY_H
ACALLD10MS
JNBDT_SET,$-2
CPL7FH
AJMPRT
KEY_H:
JBH_ADJ,KEY_M
ACALLD10MS
JNBH_ADJ,$-2
AJMPH_ADD
KEY_M:
JBM_ADJ,KEY_S
ACALLD10MS
JNBM_ADJ,$-2
AJMPM_ADD
KEY_S:
JBS_ADJ,KEY_ST
ACALLD10MS
JNBS_ADJ,$-2
AJMPS_ADD
KEY_ST:
JBSTR,RT
ACALLD10MS
JNBSTR,$-2
AJMPK_STR
RT:
RET
H_ADD:
JB7FH,Y_ADD;7FH为日期/时间切换键标志。
1为年月日。
MOVA,HOUR
ADDA,#01H
DAA
CJNEA,#24H,H_ADD1
MOVA,#0
H_ADD1:
MOVHOUR,A
AJMPRT
Y_ADD:
MOVA,YEAR
ADDA,#01H
DAA
CJNEA,#20H,Y_ADD1
MOVA,#0
Y_ADD1:
MOVYEAR,A
AJMPRT
M_ADD:
JB7FH,MO_ADD
MOVA,MIN
ADDA,#01H
DAA
CJNEA,#60H,M_ADD1
MOVA,#00H
M_ADD1:
MOVMIN,A
AJMPRT
MO_ADD:
MOVA,MONTH
ADDA,#01H
DAA
CJNEA,#13H,MO_ADD1
MOVA,#1
MO_ADD1:
MOVMONTH,A
AJMPRT
S_ADD:
JB7FH,D_ADD
MOVA,SEC
ADDA,#01H
DAA
CJNEA,#60H,S_ADD1
MOVA,#00H
S_ADD1:
MOVSEC,A
AJMPRT
D_ADD:
MOVA,DAY
ADDA,#01H
DAA
CJNEA,#32H,D_ADD1
MOVA,#01H
D_ADD1:
MOVDAY,A
AJMPRT
W_ADD:
MOVA,WEEK
ADDA,#01H
DAA
CJNEA,#7H,W_ADD1
MOVA,#0
W_ADD1:
MOVWEEK,A
AJMPRT
K_STR:
MOVDS1302_ADDR,#80H;开始振荡
MOVDS1302_DATA,SEC
LCALLWRITE
MOVDS1302_ADDR,#8EH;禁止写入1302
MOVDS1302_DATA,#80H
LCALLWRITE
cplf0
///SETBF0
CLRP2.7
AJMPRT
WR1302:
MOVDS1302_ADDR,#8EH
MOVDS1302_DATA,#00H;允许写1302
LCALLWRITE
MOVDS1302_ADDR,#80H
MOVDS1302_DATA,#80H;1302停止振荡
LCALLWRITE
MOVDS1302_ADDR,#8CH;年写入1302
MOVDS1302_DATA,YEAR
LCALLWRITE
MOVDS1302_ADDR,#8AH;周写入1302
MOVDS1302_DATA,WEEK
LCALLWRITE
MOVDS1302_ADDR,#88H;月写入1302
MOVDS1302_DATA,MONTH
LCALLWRITE
MOVDS1302_ADDR,#86H;日写入1302
MOVDS1302_DATA,DAY
LCALLWRITE
MOVDS1302_ADDR,#84H;时写入1302
MOVDS1302_DATA,HOUR
LCALLWRITE
MOVDS1302_ADDR,#82H;分写入1302
MOVDS1302_DATA,MIN
LCALLWRITE
MOVDS1302_ADDR,#82H;秒写入1302
MOVDS1302_DATA,MIN
LCALLWRITE
RET
WRITE:
CLRT_CLK
NOP
SETBT_RST
NOP
MOVA,DS1302_ADDR
MOVR4,#8
WRITE1:
RRCA
NOP
NOP
CLRT_CLK
NOP
NOP
NOP
MOVT_IO,C
NOP
NOP
NOP
SETBT_CLK
NOP
NOP
DJNZR4,WRITE1
CLRT_CLK
NOP
MOVA,DS1302_DATA
MOVR4,#8
WRITE2:
RRCA
NOP
CLRT_CLK
NOP
NOP
MOVT_IO,C
NOP
NOP
NOP
SETBT_CLK
NOP
NOP
DJNZR4,WRITE2
CLRT_RST
RET
RD1302:
MOVDS1302_ADDR,#8DH;年读出
LCALLREAD
MOVYEAR,DS1302_DATA
MOVDS1302_ADDR,#8BH;周读出
LCALLREAD
MOVWEEK,DS1302_DATA
MOVDS1302_ADDR,#89H;月读出
LCALLREAD
MOVMONTH,DS1302_DATA
MOVDS1302_ADDR,#87H;日读出
LCALLREAD
MOVDAY,DS1302_DATA
MOVDS1302_ADDR,#85H;时读出
LCALLREAD
MOVHOUR,DS1302_DATA
MOVDS1302_ADDR,#83H;分读出
LCALLREAD
MOVMIN,DS1302_DATA
MOVDS1302_ADDR,#81H;秒读出
LCALLREAD
MOVSEC,DS1302_DATA
RET
READ:
CLRT_CLK
NOP
NOP
SETBT_RST
NOP
MOVA,DS1302_ADDR
MOVR4,#8
READ1:
RRCA
MOVT_IO,C
NOP
NOP
NOP
SETBT_CLK
NOP
NOP
NOP
CLRT_CLK
NOP
NOP
DJNZR4,READ1
MOVR4,#8
READ2:
CLRT_CLK
NOP
NOP
NOP
MOVC,T_IO
NOP
NOP
NOP
NOP
NOP
RRCA
NOP
NOP
NOP
NOP
SETBT_CLK
NOP
DJNZR4,READ2
MOVDS1302_DATA,A
CLRT_RST
RET
DISP:
MOVP2,#0FFH
MOVA,YH_BIT
MOVDPTR,#TAB
MOVCA,@A+DPTR
MOVP2,A
MOVP3,#11111011B
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$
DJNZR2,$-4
RET
;////////表的制作////////////////////////
tab:
db0c0h,0f9h,0a4h,0b0h,99h,92h,82h,0f8h,80h,90h;//1-6共阴代码
;/////////延时子程序/////////////////////////
;输入:
无
;输出:
无
;实现的功能:
延时一段时间
delay:
;========1sov
MOVr6,#30
D:
MOVr7,#20
DJNZr7,$
DJNZr6,D
RET
;//////////////////////ds18b20复位子程序////////////////////////////////
;输入:
dq
;输出:
dp
;实现的功能:
将ds18b20复位
INIT_18B20:
SETBDQ
NOP
CLRDQ
MOVR0,#0FBH
TSR1:
DJNZR0,TSR1;延时
SETBDQ
MOVR0,#25H
TSR2:
JNBDQ,TSR3
DJNZR0,TSR2
TSR3:
SETBFLAG1;置标志位,表明DS18B20存在
CLRP2.0;二极管指示
AJMPTSR5
TSR4:
CLRFLAG1
LJMPTSR7
TSR5:
MOVR0,#06BH
TSR6:
DJNZR0,TSR6
TSR7:
SETBDQ;表明不存在
RET
/*;********************设定DS18B20暂存器设定值**************
RE_CONFIG:
JBFLAG1,RE_CONFIG1
RET
RE_CONFIG1:
MOVA,#0CCH;放跳过ROM命令
LCALLWRITE_18B20
MOVA,#4EH
LCALLWRITE_18B20;写暂存器命令
MOVA,#00H;报警上限中写入00H
LCALLWRITE_18B20
MOVA,#00H;报警下限中写入00H
LCALLWRITE_18B20
MOVA,#1FH;选择九位温度分辨率
LCALLWRITE_18B20
RET*/
;//////////////////////读温度子程序////////////////////////////////
;输入:
;输出:
温度
;实现的功能:
读转换后的温度值
GET_TEMPER:
SETBDQ
LCALLINIT_18B20
JBFLAG1,TSS2
RET;若不存在则返回
TSS2:
MOVA,#0CCH;跳过ROM
LCALLWRITE_18B20
MOVA,#44H;发出温度转换命令
LCALLWRITE_18B20
;LCALLDISPLAY;延时
LCALLINIT_18B20
MOVA,#0CCH;跳过ROM
LCALLWRITE_18B20
MOVA,#0BEH;发出读温度换命令
LCALLWRITE_18B20
LCALLREAD2_18B20;读两个字节的温度
RET
;//////////////////////写入ds18b20子程序////////////////////////////////
;输入:
c
;输出:
;实现的功能:
将数据写入ds18b20中
WRITE_18B20:
MOVR2,#8
CLRC
WR1:
CLRDQ
MOVR3,#6
DJNZR3,$
RRCA
MOVDQ,C
MOVR3,#23
DJNZR3,$
SETBDQ
NOP
DJNZR2,WR1
SETBDQ
RET
;//////////////////////读18B20子程序////////////////////////////////
;输入:
;输出:
;实现的功能:
读18B20程序,读出两个字节的温度
READ2_18B20:
MOVR4,#2;低位存在29H,高位存在28H
MOVR1,#29H
RE00:
MOVR2,#8
RE01:
CLRC
SETBC
NOP
NOP
CLRDQ
NOP
NOP
NOP
SETBDQ
MOVR3,#7
DJNZR3,$
MOVC,DQ
MOVR3,#23
DJNZR3,$
RRCA
DJNZR2,RE01
MOV@R1,A
DECR1
DJNZR4,RE00
RET
;//////////////////////转换子程序////////////////////////////////
;输入:
;输出:
;实现的功能:
将读出的温度进行数据的转换
CHANGE:
MOVA,29H
MOVC,28H.0;将28H中的最低位移入C
RRCA
MOVC,28H.1
RRCA
MOVC,28H.2
RRCA
MOVC,28H.3
RRCA
MOV29H,A
ret