历史上的今天
今天是:2025年01月16日(星期四)
2018年01月16日 | ds1302时钟芯片源程序
2018-01-16 来源:eefocus
;*********************************************************************
; 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
;*******************************************************************************
上一篇:PC机与单片机的通讯程序
史海拾趣
|
WinCE5.0选中文为默认语言后HPC的图片资源编不进来 现象就是开机后,桌面上只有“我的电脑”,“回收站”,“我的文档”等文字,没有相应的图标。 Default Language选“中文”,并且增加了Multilingual User Interface(MUI) 编译出来的image就是 ...… 查看全部问答> |
|
上海机房服务器托管|15900452544,上海\浙江\山东双线机房服务器托管 上海速腾数据主要经营:上海电信机房托管 上海电信主机租用 上海双线服务器托管 QQ:712296031 MSN/mail:chenxiaokai18@hotmail.com 手机:15900452544 网址:www.sutenw.com … 查看全部问答> |
|
我在上海,我的硬盘Maxtor牌子的,由于电源线当时接反了,导致硬盘磁头已经坏,我上面的数据很重要,现在请教各地的高手或者介绍有比较强的技术和单位帮助恢复数据,不知道谁能介绍这样的单位和个人能恢复我的数据?… 查看全部问答> |
|
请教个配置问题:在初始化下载链时,能找到FPGA芯片与配置芯片,可是在下载程序时,无论是下载到配置芯片,还是直接下载FPGA芯片,都遇到IDCODE 不匹配的错误(如图所示),请问高手这是什么原因造成的?(配置芯片上存有程序,且现在程序能正常运 ...… 查看全部问答> |




