pcf8563t - pcf8563t Clock Module#
Adaptation status unknown
Note
This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!
Example
-- Data Sheet https://www.nxp.com.cn/docs/zh/data-sheet/PCF8563.pdf
local pcf8563t = require "pcf8563t"
local i2cid = 1
i2c.setup(i2cid, i2c.FAST)
pcf8563t.setup(i2cid) -- Select an i2c, which can also be a software i2c object
-- Set time
local time = {year=2023,mon=11,day=2,wday=5,hour=13,min=14,sec=15}
pcf8563t.write(time)
-- Read Time
local time = pcf8563t.read()
log.info("time",time.year,time.mon,time.day, time.hour,time.min,time.sec, "week=".. time.wday)
-- Set the alarm clock, and automatically clear the interrupt flag, open the alarm function
alarm = {day=2,hour=13,min=14,sec=15}
pcf8563t.alarm(alarm)
local alarm_int = 1 -- Select a GPIO and connect it to the INT pin of the clock module
gpio.setup(1, function()
log.info("alarm!!!")
pcf8563t.control(nil, nil, 0, nil)
end, gpio.PULLUP)
-- Active Clearing of Interrupt Flag
pcf8563t.control(nil, nil, 0, nil)
-- Close alarm
pcf8563t.control(0, nil, 0, nil)
pcf8563t.setup(id, by)#
Initialization
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
i2c The id of the device, or the object of the software i2c, must be filled in |
int |
The year benchmark, which is 2000 by default, can be left unfilled. |
Return Value
return value type |
explanation |
---|---|
boolean |
Returns true on success, otherwise false |
Examples
None
pcf8563t.read()#
Read-out time
Parameters
None
Return Value
return value type |
explanation |
---|---|
table |
Time information, which returns an empty table if the read fails. |
Examples
local time = pcf8563t.read()
if time and time.year then
log.info("time", json.encode(time))
end
-- time It is a table with the following fields and is compatible with OS. date
-- time.year Year
-- time.mon Months
-- time.day Days in Month
-- time.hour Hour, base 24
-- time.min Minutes
-- time.sec Seconds
-- time.wday Week N, 1 on Sunday and 1 on Saturday 7
pcf8563t.write(time)#
Set time
Parameters
Incoming Value Type |
Explanation |
---|---|
table |
Time information, which is the same as the field rules of pcf8563t.read |
Return Value
return value type |
explanation |
---|---|
nil |
No return value |
Examples
local time = {year=2023,mon=11,day=2,wday=5,hour=13,min=14,sec=15}
pcf8563t.write(time)
pcf8563t.alarm(time)#
Set an alarm
Parameters
Incoming Value Type |
Explanation |
---|---|
table |
Time information |
Return Value
return value type |
explanation |
---|---|
nil |
No return value |
Examples
-- Set the alarm clock, and automatically clear the interrupt flag, open the alarm function
-- Note that only days (wday)/hours (hour)/minutes (min)/weeks (wday) can be set, and the year and month cannot be set.
alarm = {day=2,hour=13,min=14}
pcf8563t.alarm(alarm)
local alarm_int = 1 -- Select a GPIO and connect it to the INT pin of the clock module
gpio.setup(1, function()
log.info("alarm!!!")
pcf8563t.control(nil, nil, 0, nil)
end, gpio.PULLUP)
-- Pay attention to the rules!!! The value passed in. All matches are required to be triggered.
-- For example, whenever min = 1 triggers, do not judge hour/day/wday
alarm = {min=1}
-- For example, whenever min = 1 and hour = 0, it is triggered and does not judge.day/wday
alarm = {min=1, hour=0}
-- Trigger only when all day/hour/min are met
alarm = {day=2,hour=13,min=14}
-- Trigger only when all day/hour/min/wday are satisfied
alarm = {day=2,hour=13,min=14,wday=2}
pcf8563t.control(AIE, TIE, AF, TF)#
Set an alarm
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
Alarm switch, 0 off, 1 on, nil as is |
int |
Timer switch, 0 off, 1 on, nil remains as is |
int |
Clear alarm interrupt, 0 clear, nil as is |
int |
Clear timer interrupt, 0 clear, nil remains as is |
Return Value
return value type |
explanation |
---|---|
nil |
No return value |
Examples
-- Active Clearing of Interrupt Flag
pcf8563t.control(nil, nil, 0, nil)
-- Close alarm
pcf8563t.control(0, nil, 0, nil)