AT89C52用MAX7219驱动的万年历,弄不出来,求帮忙看看
时间:10-02
整理:3721RD
点击:
程序如下,不知道哪错了:T_RST BIT P3.5 ;实时时钟复位线引脚
T_CLK BIT P3.6 ;实时时钟时钟线引脚
T_IO BIT P3.7 ;实时时钟数据线引脚
H_ADJ BIT P2.0 ;时/年调整
M_ADJ BIT P2.1 ;分/月调整
S_ADJ BIT P2.2 ;秒/日调整
DT_SET BIT P2.3 ;时间/日期选择
STR BIT P2.4 ;启动走时
SEC EQU 30H ;当前秒
MIN EQU 31H
HOUR EQU 32H
DAY EQU 33H
MONTH EQU 34H
WEEK2 EQU 35H
YEAR EQU 36H
A_BIT EQU 20H
B_BIT EQU 21H
C_BIT EQU 22H
D_BIT EQU 23H
E_BIT EQU 24H
F_BIT EQU 25H
G_BIT EQU 26H
H_BIT EQU 27H
CD_BIT EQU 29H ;分/月
AB_BIT EQU 28H ;秒/日
EF_BIT EQU 2AH ;时/年
DS1302_ADDR EQU 5EH
DS1302_DATA EQU 5FH;
;//********DS18B20 引脚定义********//
;//********DS18B20 引脚控制********//
DQ EQU P1.0
FLAG EQU 00H ;18B20存在标志位
;//********7219引脚定义*********//
DIN EQU P0.1
LOAD EQU P0.2
CLK EQU P0.3
//*****************************//
ORG 0000H
AJMP MAIN
ORG 000BH
LJMP TT0
ORG 0030H
MAIN: MOV SP,#64H
MOV TH0,#0B1H
MOV TL0,#0E0H
SETB EA
SETB ET0
MOV YEAR,#17H ;上电预置日期、时间
MOV MONTH,#04H ;2017 04 12 12:50:55
MOV DAY,#12H
MOV HOUR,#12H
MOV MIN,#50H
MOV SEC,#55H
LCALL DISIN0
MOV R7,#10
SETB TR0
MAIN1: LCALL KEY
JB F0,MAIN10 ;F0=1,开始走时。走时前写,不读。走时后读,不写。
LCALL WR1302
AJMP MAIN2
MAIN10: LCALL RD1302
MAIN2: JB 7FH,YMD
MOV EF_BIT,HOUR
MOV CD_BIT,MIN
MOV AB_BIT,SEC
AJMP MAIN20
YMD: MOV EF_BIT,YEAR
MOV CD_BIT,MONTH
MOV AB_BIT,DAY
MAIN20: AJMP MAIN1
//*****************************//
KEY: ;按键子程序
KEY_SET:JB DT_SET,KEY_H
JNB DT_SET,$
CPL 7FH
AJMP RT
KEY_H: JB H_ADJ,KEY_M
JNB H_ADJ,$
AJMP H_ADD
KEY_M: JB M_ADJ,KEY_S
JNB M_ADJ,$
AJMP M_ADD
KEY_S: JB S_ADJ,KEY_ST
JNB S_ADJ,$
AJMP S_ADD
KEY_ST: JB STR,RT
JNB STR,$
AJMP K_STR
RT: RET
H_ADD: JB 7FH,Y_ADD
MOV A,HOUR
ADD A,#01H
DA A
CJNE A,#24H,H_ADD1
MOV A,#0
H_ADD1: MOV HOUR,A
AJMP RT
Y_ADD: MOV A,YEAR
ADD A,#01H
DA A
CJNE A,#20H,Y_ADD1
MOV A,#0
Y_ADD1: MOV YEAR,A
AJMP RT
M_ADD: JB 7FH,MO_ADD
MOV A,MIN
ADD A,#01H
DA A
CJNE A,#60H,M_ADD1
MOV A,#0
M_ADD1: MOV MIN,A
AJMP RT
MO_ADD: MOV A,MONTH
ADD A,#01H
DA A
CJNE A,#13H,MO_ADD1
MOV A,#1
MO_ADD1:MOV MONTH,A
AJMP RT
S_ADD: JB 7FH,D_ADD
MOV A,SEC
ADD A,#01
DA A
CJNE A,#60H,S_ADD1
S_ADD1: MOV SEC,A
AJMP RT
D_ADD: MOV A,DAY
ADD A,#01H
DA A
CJNE A,#32H,D_ADD1
MOV A,#01H
D_ADD1: MOV DAY,A
AJMP RT
K_STR: MOV DS1302_ADDR,#80H
MOV DS1302_DATA,SEC
LCALL WRITE
MOV DS1302_ADDR,#8EH
MOV DS1302_DATA,#80H
LCALL WRITE
CPL F0
AJMP RT
WR1302: MOV DS1302_ADDR,#8EH
MOV DS1302_DATA,#00H
LCALL WRITE
MOV DS1302_ADDR,#80H
MOV DS1302_DATA,#80H
LCALL WRITE
MOV DS1302_ADDR,#8CH
MOV DS1302_DATA,YEAR
LCALL WRITE
MOV DS1302_ADDR,#88H
MOV DS1302_DATA,MONTH
LCALL WRITE
MOV DS1302_ADDR,#86H
MOV DS1302_DATA,DAY
LCALL WRITE
MOV DS1302_ADDR,#84H
MOV DS1302_DATA,HOUR
LCALL WRITE
MOV DS1302_ADDR,#82H
MOV DS1302_DATA,MIN
LCALL WRITE
MOV DS1302_ADDR,#80H;秒写入1302
MOV DS1302_DATA,SEC
LCALL WRITE
RET
WRITE: CLR T_CLK
NOP
SETB T_RST
NOP
MOV A,DS1302_ADDR
MOV R4,#8
WRITE1: RRC A
NOP
NOP
CLR T_CLK
NOP
NOP
NOP
MOV A,DS1302_DATA
MOV R4,#8
WRITE2: RRC A
NOP
CLR T_CLK
NOP
NOP
MOV T_IO,C
NOP
NOP
NOP
SETB T_CLK
NOP
NOP
DJNZ R4,WRITE2
CLR T_RST
RET
RD1302: MOV DS1302_ADDR,#8DH
LCALL READ
MOV YEAR,DS1302_DATA
MOV DS1302_ADDR,#8BH
LCALL READ
MOV WEEK2,DS1302_DATA
MOV DS1302_ADDR,#89H
LCALL READ
MOV MONTH,DS1302_DATA
MOV DS1302_ADDR,#87H
LCALL READ
MOV DAY,DS1302_DATA
MOV DS1302_ADDR,#85H
LCALL READ
MOV HOUR,DS1302_DATA
MOV DS1302_ADDR,#83H
LCALL READ
MOV MIN,DS1302_DATA
MOV DS1302_ADDR,#81H
LCALL READ
MOV SEC,DS1302_DATA
MOV DS1302_ADDR,#79H
RET
READ: CLR T_CLK
NOP
NOP
SETB T_RST
NOP
MOV A,DS1302_ADDR
MOV R4,#8
READ1: RRC A
NOP
MOV T_IO,C
NOP
NOP
SETB T_CLK
NOP
NOP
NOP
SETB T_CLK
NOP
NOP
CLR T_CLK
NOP
NOP
NOP
NOP
CLR T_CLK
DJNZ R4,READ1
NOP
MOV R4,#8
NOP
READ2: CLR T_CLK
DJNZ R4,READ1
MOV R4,#8
READ3: CLR T_CLK
NOP
NOP
NOP
MOV C,T_IO
NOP
NOP
NOP
NOP
NOP
RRC A
NOP
NOP
NOP
NOP
SETB T_CLK
NOP
DJNZ R4,READ2
MOV DS1302_DATA,A
CLR T_RST
RET
;//*************200ms定时***********//
TT0: MOV TH0,#0BH
MOV TL0,#0E0H
DJNZ R7,INN2
MOV R7,#10
LCALL DS1820
LCALL SHOW
INN2: RET
;//**************7219**********//
DISIN0: MOV R4,#09H
MOV R5,#0FFH
LCALL DINPUT
MOV R4,#0AH
MOV R5,#08H
LCALL DINPUT
MOV R4,#0BH
MOV R5,#07H
LCALL DINPUT
MOV R4,#0CH
MOV R5,#01H
LCALL DINPUT
RET
;//**************7219显示子程序************//
SHOW: MOV A,40H
MOV B,#10
div AB
MOV G_BIT,B
MOV H_BIT,A
MOV R4,#01H
MOV R5,H_BIT
LCALL DINPUT
MOV R4,#02H
MOV R5,G_BIT
LCALL DINPUT
MOV A,EF_BIT
MOV B,#10H
div AB
MOV E_BIT,B
MOV F_BIT,A
MOV R4,#03H
MOV R5,F_BIT
LCALL DINPUT
MOV R4,#04H
MOV R5,E_BIT
LCALL DINPUT
MOV A,CD_BIT
MOV B,#10H
div AB
MOV C_BIT,B
MOV D_BIT,A
MOV R4,#05H
MOV R5,D_BIT
LCALL DINPUT
MOV R4,#06H
MOV R5,C_BIT
LCALL DINPUT
MOV A,AB_BIT
MOV B,#10H
div AB
MOV A_BIT,B
MOV B_BIT,A
MOV R4,#07H
MOV R5,B_BIT
LCALL DINPUT
MOV R4,#08H
MOV R5,A_BIT
LCALL DINPUT
RET
;//************7219命令写入子程序*********//
DINPUT: MOV A,R4
MOV B,#8
LOOP0: RLC A
MOV P0.1,C
CLR P0.3
SETB P0.3
DJNZ B,LOOP0
MOV A,R5
MOV B,#8
LOOP1: RLC A
MOV P0.1,C
CLR P0.3
SETB P0.3
DJNZ B,LOOP1
CLR P0.2
SETB P0.2
RET
;//**************DS18B20**********//
DS1820: LCALL TEMP
LCALL CHULI
RET
;//*********DS18B20的温度转换子程序******//
TEMP: LCALL REST_1820
MOV A,#0CCH
LCALL WRITE_1820
MOV A,#44H
LCALL WRITE_1820
LCALL REST_1820
MOV A,#0CCH
LCALL WRITE_1820
MOV A,#0BEH
LCALL WRITE_1820
LCALL READ_1820
RET
;//************DS18B20复位程序*******//
REST_1820:
SETB DQ
NOP
CLR DQ
MOV R2,#250
DJNZ R2,$
SETB DQ
MOV R2,#30
DJNZ R2,$
JNB DQ,REST1
JMP REST_1820
REST1: MOV R2,#120
DJNZ R2,$
JB DQ,REST2
JMP REST_1820
REST2: MOV R2,#240
DJNZ R2,$
RET
;//****写DS18B20的子程序(有具体的是需要求)****//
WRITE_1820:
MOV B,#8
WR1: CLR DQ
MOV R3,#7
DJNZ R3,$
RRC A
MOV DQ,C
MOV R3,#20
DJNZ R3,$
SETB DQ
NOP
NOP
DJNZ B,WR1
SETB DQ
RET
;//****读DS18B20的程序,从DS18B20中读出两个字节的温度数据****//
READ_1820:
MOV R2,#2
MOV R1,#3EH
RE0: MOV B,#8
RE1: SETB DQ
NOP
NOP
CLR DQ
NOP
NOP
SETB DQ
MOV R3,#9
DJNZ R3,$
MOV C,DQ
MOV R3,#30
DJNZ R3,$
RRC A
DJNZ B,RE1
MOV R1,A
INC R1
DJNZ R2,RE0
RET
;//*****************数据处理************//
CHULI: MOV A,3EH
ANL A,#0F0H
SWAP A
MOV 3DH,A
MOV A,3EH
ANL A,#0F0H
JNB ACC.3,GW
INC 3DH
GW: MOV A,3FH
ANL A,#0F0H
SWAP A
ORL A,3DH
MOV 40H,A
RET
;//**************************//
END
T_CLK BIT P3.6 ;实时时钟时钟线引脚
T_IO BIT P3.7 ;实时时钟数据线引脚
H_ADJ BIT P2.0 ;时/年调整
M_ADJ BIT P2.1 ;分/月调整
S_ADJ BIT P2.2 ;秒/日调整
DT_SET BIT P2.3 ;时间/日期选择
STR BIT P2.4 ;启动走时
SEC EQU 30H ;当前秒
MIN EQU 31H
HOUR EQU 32H
DAY EQU 33H
MONTH EQU 34H
WEEK2 EQU 35H
YEAR EQU 36H
A_BIT EQU 20H
B_BIT EQU 21H
C_BIT EQU 22H
D_BIT EQU 23H
E_BIT EQU 24H
F_BIT EQU 25H
G_BIT EQU 26H
H_BIT EQU 27H
CD_BIT EQU 29H ;分/月
AB_BIT EQU 28H ;秒/日
EF_BIT EQU 2AH ;时/年
DS1302_ADDR EQU 5EH
DS1302_DATA EQU 5FH;
;//********DS18B20 引脚定义********//
;//********DS18B20 引脚控制********//
DQ EQU P1.0
FLAG EQU 00H ;18B20存在标志位
;//********7219引脚定义*********//
DIN EQU P0.1
LOAD EQU P0.2
CLK EQU P0.3
//*****************************//
ORG 0000H
AJMP MAIN
ORG 000BH
LJMP TT0
ORG 0030H
MAIN: MOV SP,#64H
MOV TH0,#0B1H
MOV TL0,#0E0H
SETB EA
SETB ET0
MOV YEAR,#17H ;上电预置日期、时间
MOV MONTH,#04H ;2017 04 12 12:50:55
MOV DAY,#12H
MOV HOUR,#12H
MOV MIN,#50H
MOV SEC,#55H
LCALL DISIN0
MOV R7,#10
SETB TR0
MAIN1: LCALL KEY
JB F0,MAIN10 ;F0=1,开始走时。走时前写,不读。走时后读,不写。
LCALL WR1302
AJMP MAIN2
MAIN10: LCALL RD1302
MAIN2: JB 7FH,YMD
MOV EF_BIT,HOUR
MOV CD_BIT,MIN
MOV AB_BIT,SEC
AJMP MAIN20
YMD: MOV EF_BIT,YEAR
MOV CD_BIT,MONTH
MOV AB_BIT,DAY
MAIN20: AJMP MAIN1
//*****************************//
KEY: ;按键子程序
KEY_SET:JB DT_SET,KEY_H
JNB DT_SET,$
CPL 7FH
AJMP RT
KEY_H: JB H_ADJ,KEY_M
JNB H_ADJ,$
AJMP H_ADD
KEY_M: JB M_ADJ,KEY_S
JNB M_ADJ,$
AJMP M_ADD
KEY_S: JB S_ADJ,KEY_ST
JNB S_ADJ,$
AJMP S_ADD
KEY_ST: JB STR,RT
JNB STR,$
AJMP K_STR
RT: RET
H_ADD: JB 7FH,Y_ADD
MOV A,HOUR
ADD A,#01H
DA A
CJNE A,#24H,H_ADD1
MOV A,#0
H_ADD1: MOV HOUR,A
AJMP RT
Y_ADD: MOV A,YEAR
ADD A,#01H
DA A
CJNE A,#20H,Y_ADD1
MOV A,#0
Y_ADD1: MOV YEAR,A
AJMP RT
M_ADD: JB 7FH,MO_ADD
MOV A,MIN
ADD A,#01H
DA A
CJNE A,#60H,M_ADD1
MOV A,#0
M_ADD1: MOV MIN,A
AJMP RT
MO_ADD: MOV A,MONTH
ADD A,#01H
DA A
CJNE A,#13H,MO_ADD1
MOV A,#1
MO_ADD1:MOV MONTH,A
AJMP RT
S_ADD: JB 7FH,D_ADD
MOV A,SEC
ADD A,#01
DA A
CJNE A,#60H,S_ADD1
S_ADD1: MOV SEC,A
AJMP RT
D_ADD: MOV A,DAY
ADD A,#01H
DA A
CJNE A,#32H,D_ADD1
MOV A,#01H
D_ADD1: MOV DAY,A
AJMP RT
K_STR: MOV DS1302_ADDR,#80H
MOV DS1302_DATA,SEC
LCALL WRITE
MOV DS1302_ADDR,#8EH
MOV DS1302_DATA,#80H
LCALL WRITE
CPL F0
AJMP RT
WR1302: MOV DS1302_ADDR,#8EH
MOV DS1302_DATA,#00H
LCALL WRITE
MOV DS1302_ADDR,#80H
MOV DS1302_DATA,#80H
LCALL WRITE
MOV DS1302_ADDR,#8CH
MOV DS1302_DATA,YEAR
LCALL WRITE
MOV DS1302_ADDR,#88H
MOV DS1302_DATA,MONTH
LCALL WRITE
MOV DS1302_ADDR,#86H
MOV DS1302_DATA,DAY
LCALL WRITE
MOV DS1302_ADDR,#84H
MOV DS1302_DATA,HOUR
LCALL WRITE
MOV DS1302_ADDR,#82H
MOV DS1302_DATA,MIN
LCALL WRITE
MOV DS1302_ADDR,#80H;秒写入1302
MOV DS1302_DATA,SEC
LCALL WRITE
RET
WRITE: CLR T_CLK
NOP
SETB T_RST
NOP
MOV A,DS1302_ADDR
MOV R4,#8
WRITE1: RRC A
NOP
NOP
CLR T_CLK
NOP
NOP
NOP
MOV A,DS1302_DATA
MOV R4,#8
WRITE2: RRC A
NOP
CLR T_CLK
NOP
NOP
MOV T_IO,C
NOP
NOP
NOP
SETB T_CLK
NOP
NOP
DJNZ R4,WRITE2
CLR T_RST
RET
RD1302: MOV DS1302_ADDR,#8DH
LCALL READ
MOV YEAR,DS1302_DATA
MOV DS1302_ADDR,#8BH
LCALL READ
MOV WEEK2,DS1302_DATA
MOV DS1302_ADDR,#89H
LCALL READ
MOV MONTH,DS1302_DATA
MOV DS1302_ADDR,#87H
LCALL READ
MOV DAY,DS1302_DATA
MOV DS1302_ADDR,#85H
LCALL READ
MOV HOUR,DS1302_DATA
MOV DS1302_ADDR,#83H
LCALL READ
MOV MIN,DS1302_DATA
MOV DS1302_ADDR,#81H
LCALL READ
MOV SEC,DS1302_DATA
MOV DS1302_ADDR,#79H
RET
READ: CLR T_CLK
NOP
NOP
SETB T_RST
NOP
MOV A,DS1302_ADDR
MOV R4,#8
READ1: RRC A
NOP
MOV T_IO,C
NOP
NOP
SETB T_CLK
NOP
NOP
NOP
SETB T_CLK
NOP
NOP
CLR T_CLK
NOP
NOP
NOP
NOP
CLR T_CLK
DJNZ R4,READ1
NOP
MOV R4,#8
NOP
READ2: CLR T_CLK
DJNZ R4,READ1
MOV R4,#8
READ3: CLR T_CLK
NOP
NOP
NOP
MOV C,T_IO
NOP
NOP
NOP
NOP
NOP
RRC A
NOP
NOP
NOP
NOP
SETB T_CLK
NOP
DJNZ R4,READ2
MOV DS1302_DATA,A
CLR T_RST
RET
;//*************200ms定时***********//
TT0: MOV TH0,#0BH
MOV TL0,#0E0H
DJNZ R7,INN2
MOV R7,#10
LCALL DS1820
LCALL SHOW
INN2: RET
;//**************7219**********//
DISIN0: MOV R4,#09H
MOV R5,#0FFH
LCALL DINPUT
MOV R4,#0AH
MOV R5,#08H
LCALL DINPUT
MOV R4,#0BH
MOV R5,#07H
LCALL DINPUT
MOV R4,#0CH
MOV R5,#01H
LCALL DINPUT
RET
;//**************7219显示子程序************//
SHOW: MOV A,40H
MOV B,#10
div AB
MOV G_BIT,B
MOV H_BIT,A
MOV R4,#01H
MOV R5,H_BIT
LCALL DINPUT
MOV R4,#02H
MOV R5,G_BIT
LCALL DINPUT
MOV A,EF_BIT
MOV B,#10H
div AB
MOV E_BIT,B
MOV F_BIT,A
MOV R4,#03H
MOV R5,F_BIT
LCALL DINPUT
MOV R4,#04H
MOV R5,E_BIT
LCALL DINPUT
MOV A,CD_BIT
MOV B,#10H
div AB
MOV C_BIT,B
MOV D_BIT,A
MOV R4,#05H
MOV R5,D_BIT
LCALL DINPUT
MOV R4,#06H
MOV R5,C_BIT
LCALL DINPUT
MOV A,AB_BIT
MOV B,#10H
div AB
MOV A_BIT,B
MOV B_BIT,A
MOV R4,#07H
MOV R5,B_BIT
LCALL DINPUT
MOV R4,#08H
MOV R5,A_BIT
LCALL DINPUT
RET
;//************7219命令写入子程序*********//
DINPUT: MOV A,R4
MOV B,#8
LOOP0: RLC A
MOV P0.1,C
CLR P0.3
SETB P0.3
DJNZ B,LOOP0
MOV A,R5
MOV B,#8
LOOP1: RLC A
MOV P0.1,C
CLR P0.3
SETB P0.3
DJNZ B,LOOP1
CLR P0.2
SETB P0.2
RET
;//**************DS18B20**********//
DS1820: LCALL TEMP
LCALL CHULI
RET
;//*********DS18B20的温度转换子程序******//
TEMP: LCALL REST_1820
MOV A,#0CCH
LCALL WRITE_1820
MOV A,#44H
LCALL WRITE_1820
LCALL REST_1820
MOV A,#0CCH
LCALL WRITE_1820
MOV A,#0BEH
LCALL WRITE_1820
LCALL READ_1820
RET
;//************DS18B20复位程序*******//
REST_1820:
SETB DQ
NOP
CLR DQ
MOV R2,#250
DJNZ R2,$
SETB DQ
MOV R2,#30
DJNZ R2,$
JNB DQ,REST1
JMP REST_1820
REST1: MOV R2,#120
DJNZ R2,$
JB DQ,REST2
JMP REST_1820
REST2: MOV R2,#240
DJNZ R2,$
RET
;//****写DS18B20的子程序(有具体的是需要求)****//
WRITE_1820:
MOV B,#8
WR1: CLR DQ
MOV R3,#7
DJNZ R3,$
RRC A
MOV DQ,C
MOV R3,#20
DJNZ R3,$
SETB DQ
NOP
NOP
DJNZ B,WR1
SETB DQ
RET
;//****读DS18B20的程序,从DS18B20中读出两个字节的温度数据****//
READ_1820:
MOV R2,#2
MOV R1,#3EH
RE0: MOV B,#8
RE1: SETB DQ
NOP
NOP
CLR DQ
NOP
NOP
SETB DQ
MOV R3,#9
DJNZ R3,$
MOV C,DQ
MOV R3,#30
DJNZ R3,$
RRC A
DJNZ B,RE1
MOV R1,A
INC R1
DJNZ R2,RE0
RET
;//*****************数据处理************//
CHULI: MOV A,3EH
ANL A,#0F0H
SWAP A
MOV 3DH,A
MOV A,3EH
ANL A,#0F0H
JNB ACC.3,GW
INC 3DH
GW: MOV A,3FH
ANL A,#0F0H
SWAP A
ORL A,3DH
MOV 40H,A
RET
;//**************************//
END
已退回1积分