;********************************************************************* ; Revision History: ;********************************************************************* ;---------- 管腳定義 --------------
RST EQU P1.5 ;DS1302 IO EQU P1.6 SCLK EQU P1.7 ;******************************************************************************* ; The following is about DS1302 ;*******************************************************************************
;------------------------------------------------------------------------------- ; RST1302 Reset 1302 ; Function: Sends the command to reset 1302 ; Calls: None ; InPara: None ; OutPara: None ; Register Usage: None ;------------------------------------------------------------------------------- RST1302:clr sclk clr rst setb rst ret ;------------------------------------------------------------------------------- ; WRBYTE Write a byte to 1302 ; Function: Shifts out a byte, starting with the LSB, to the RAM ; Calls: None ; InPara: A = the byte to be sent ; OutPara: None ; Register Usage: R2 ;------------------------------------------------------------------------------- WRBYTE: MOV r2,#08 wrbyt1: rrc a MOV io,C clr sclk setb sclk djnz r2,wrbyt1 ret
;------------------------------------------------------------------------------- ; RDBYTE Read a byte from 1302 ; Function: Recieves a byte, LSB first, from the RAM ; Calls: None ; InPara: None ; OutPara: A = recieved byte ; Register Usage: R2 ;------------------------------------------------------------------------------- RDBYTE: MOV R2, #08 ; Set bit counter to eight clr a setb io rdbyt1: setb sclk ; Bring SCK high clr sclk ; Bring SCK low MOV C, io ; Receive data bit and store in carry rrc A ; Shift byte right through carry djnz R2, rdbyt1 ; Finish if last data bit ret ;------------------------------------------------------------------------------------------------- ; GETTIME Get time from 1302 ; Function: ; Calls: wrbyte,rdbyte ; InPara: R0 = Last address to store time ; OutPara: None ; Register Usage: R0,A ;------------------------------------------------------------------------------------------------- gettime:lcall rst1302 MOV a,#0bfh lcall wrbyte ;clock burst read (eight registers) lcall rdbyte ;sec MOV @r0,a dec r0 lcall rdbyte ;min MOV @r0,a dec r0 lcall rdbyte ;hour MOV @r0,a dec r0 lcall rdbyte ;date MOV @r0,a dec r0 lcall rdbyte ;month MOV @r0,a dec r0 lcall rdbyte ;day MOV @r0,a dec r0 lcall rdbyte ;year MOV @r0,a dec r0 lcall rdbyte ;must read control register in burst mode lcall rst1302 clr rst ret ;------------------------------------------------------------------------------------------------- ; SETTIME Set time to 1302 ; Function: ; Calls: wrbyte,rdbyte ; InPara: R0 = Last address of the time to be sent ; OutPara: None ; Register Usage: R0,A ;------------------------------------------------------------------------------------------------- settime:lcall rst1302 MOV a,#8eh lcall wrbyte ;control register clr a lcall wrbyte ;disable write protect
lcall rst1302 MOV a,#90h lcall wrbyte ;trickle charger register MOV a,#0abh lcall wrbyte ;enable, 2 diodes, 8K resistor lcall rst1302 MOV a,#0beh lcall wrbyte ;clock burst write (eight registers)
MOV a,@r0 dec r0 lcall wrbyte ;sec MOV a,@r0 dec r0 lcall wrbyte ;min MOV a,@r0 dec r0 lcall wrbyte ;hour MOV a,@r0 dec r0 lcall wrbyte ;date MOV a,@r0 dec r0 lcall wrbyte ;mon MOV a,@r0 dec r0 lcall wrbyte ;day MOV a,@r0 dec r0 lcall wrbyte ;year
MOV a,#80h lcall wrbyte ;must write control register in burst mode, enable write protect lcall rst1302 clr rst ret ;******************************************************************************* |