高縣住房和城鄉(xiāng)建設(shè)部網(wǎng)站百度文庫官網(wǎng)
學(xué)物聯(lián)網(wǎng),來萬物簡單IoT物聯(lián)網(wǎng)!!
一、產(chǎn)品簡介
DS1302 是DALLAS 公司推出的涓流充電時鐘芯片,內(nèi)含有一個實時時鐘/日歷和31字節(jié)靜態(tài)RAM,實時時鐘/日歷電路提供秒、分、時、日、周、月、年的信息,每月的天數(shù)和閏年的天數(shù)可自動調(diào)整。
DS1302 與單片機(jī)之間能簡單地采用同步串行的方式進(jìn)行通信,只需要三個數(shù)據(jù)線:
(1)RST 復(fù)位
(2)I/O 數(shù)據(jù)線
(3)SCLK串行時鐘
引腳定義
- VCC:3.3V
- GND:地
- CLK:時鐘輸出
- DAT:數(shù)據(jù)輸入輸出
- RST:復(fù)位引腳
二、技術(shù)參數(shù)
- 工作電壓:2V-5.5V
- 接口簡單:GPIO三線接口
- 工作溫度:-40°C~85°C
- 低功耗:工作電壓2V,電流300nA
- 電源供應(yīng):支持主電源和備份電源
- 電路板尺寸:4.4cm*2.3cm
三、軟件接口
DS1302(o_clk, o_rst, dio_num) - 創(chuàng)建RTC時鐘對象
- 函數(shù)原型
ds1302Obj = DS1302(o_clk, o_rst, dio_num)
- 參數(shù)說明
參數(shù) | 類型 | 必選參數(shù)? | 說明 |
---|---|---|---|
o_clk | Pin | 是 | 傳入Pin對象 |
o_rst | Pin | 是 | 傳入Pin對象 |
dio_num | Pin num | 是 | 傳入Pin Num數(shù) |
- 返回值
DS1302對象成功,返回DS1302對象;DS1302對象創(chuàng)建失敗,拋出Exception
- 示例代碼-無回調(diào)函數(shù)
from machine import Pin
import ds1302gpiodionum = 18
gpioclk = Pin(16 , Pin.OUT , Pin.PULL_DOWN)
gpiorst = Pin(17 , Pin.OUT , Pin.PULL_DOWN)
ds1302_obj = ds1302.DS1302(gpioclk,gpiorst,gpiodionum)
print('start init ds1302')
- 輸出
start init ds1302
setDatetime() - 設(shè)置RTC時鐘信息
- 函數(shù)功能:
設(shè)置RTC時鐘信息
- 函數(shù)原型:
DS1302.setDatetime(data)
- 參數(shù)說明:
data日期格式分別為:年-月-日-時-分-秒-星期
- 返回值:
無
getDatetime() - 獲取RTC時鐘信息
- 函數(shù)功能:
獲取RTC時鐘信息
- 函數(shù)原型:
data = DS1302.getDatetime()
- 參數(shù)說明:
無
- 返回值:
成功返回data日期格式分別為:年-月-日-時-分-秒-星期
- 示例:
from machine import Pin
import ds1302gpiodionum = 18
gpioclk = Pin(16 , Pin.OUT , Pin.PULL_DOWN)
gpiorst = Pin(17 , Pin.OUT , Pin.PULL_DOWN)
ds1302_obj = ds1302.DS1302(gpioclk,gpiorst,gpiodionum)
print('start init ds1302')
ds1302_obj.getDatetime([2023, 6, 13 , 0, 0, 30, 1])
print(ds1302_obj.getDatetime())
- 輸出
start init ds1302
[2023, 6, 13, 0, 0, 31, 1]
四、接口案例
- 案例代碼
import utime # 延時函數(shù)在utime庫中
from machine import Pin
import ds1302ds1302_obj = Nonedef ds1302_init():gpiodionum = 18gpioclk = Pin(16 , Pin.OUT , Pin.PULL_DOWN)gpiorst = Pin(17 , Pin.OUT , Pin.PULL_DOWN)ds1302_obj = ds1302.DS1302(gpioclk,gpiorst,gpiodionum)print('start init ds1302')if __name__ == '__main__':ds1302_init()ds1302_obj.setDatetime([2023, 6, 13 , 0, 0, 30, 1])while True:print(ds1302_obj.getDatetime())utime.sleep(1)
- 輸出
start init ds1302
[2023, 6, 13, 0, 0, 31, 1]
[2023, 6, 13, 0, 0, 32, 1]
[2023, 6, 13, 0, 0, 33, 1]
[2023, 6, 13, 0, 0, 34, 1]
[2023, 6, 13, 0, 0, 35, 1]
[2023, 6, 13, 0, 0, 36, 1]
參考文獻(xiàn)及購買鏈接
[1] RTC時鐘模塊購買鏈接