MOV C,DAT RRC A MOV 55H,#30 RD3A:
DJNZ 55H,RD3A DJNZ 58H,RD1A SETB DAT RET
3.2.2 读、写DS1302子程序
;写1302程序WRITE: CLR SCLK NOP SETB RST NOP MOV A,32H MOV R4,#8 WRITE1:
RRC A ;送地址给1302 NOP NOP CLR SCLK NOP NOP
NOP MOV IO,C NOP NOP NOP SETB SCLK NOP NOP
DJNZ R4,WRITE1 CLR SCLK NOP MOV A,31H MOV R4,#8 WRITE2: RRC A
NOP ;送数据给1302 CLR SCLK NOP NOP MOV IO,C NOP NOP NOP SETB SCLK NOP
NOP
DJNZ R4,WRITE2 CLR RST RET ;读1302程序 READ: CLR SCLK NOP NOP SETB RST NOP MOV A,32H MOV R4,#8 READ1:
RRC A ;送地址给1302 NOP MOV IO,C NOP NOP NOP SETB SCLK NOP NOP NOP CLR SCLK
NOP NOP
DJNZ R4,READ1 MOV R4,#8 READ2: CLR SCLK
NOP ;从1302中读出数据 NOP NOP MOV C,IO NOP NOP NOP NOP NOP RRC A NOP NOP NOP NOP SETB SCLK NOP
DJNZ R4,READ2 MOV 31H,A CLR RST