update RTC code
This commit is contained in:
parent
3d3b27baad
commit
bf7af0e761
33
lisp/rtc.lsp
33
lisp/rtc.lsp
|
@ -1,16 +1,5 @@
|
||||||
(defvar *rtc-port* 0)
|
(defvar *rtc-port* 0)
|
||||||
|
|
||||||
(defun rtc-set (hr min)
|
|
||||||
"(rtc-set hr min)
|
|
||||||
Set the time on a DS3231 RTC. Times are in BCD, so use
|
|
||||||
the appropriate reader macro, e.g. (rtc-set #x12 #x34)
|
|
||||||
for 12:34. Assumes seconds are zero."
|
|
||||||
(with-i2c (str *rtc-port* #x68)
|
|
||||||
(write-byte 0 str)
|
|
||||||
(write-byte 0 str)
|
|
||||||
(write-byte min str)
|
|
||||||
(write-byte hr str)))
|
|
||||||
|
|
||||||
(defun bcd-to-dec (x)
|
(defun bcd-to-dec (x)
|
||||||
"(bcd-to-dec x)
|
"(bcd-to-dec x)
|
||||||
Convert the BCD-encoded number x to a decimal value."
|
Convert the BCD-encoded number x to a decimal value."
|
||||||
|
@ -21,7 +10,24 @@ Convert the BCD-encoded number x to a decimal value."
|
||||||
(defun dec-to-bcd (x)
|
(defun dec-to-bcd (x)
|
||||||
"(dec-to-bcd x)
|
"(dec-to-bcd x)
|
||||||
Converts the decimal value to a BCD-encoded number.
|
Converts the decimal value to a BCD-encoded number.
|
||||||
Number must be in the range 0 to 99.")
|
Number must be in the range 0 to 99."
|
||||||
|
(+
|
||||||
|
(ash (floor x 10) 4)
|
||||||
|
(logand (rem x 10) #xf)))
|
||||||
|
|
||||||
|
(defun rtc-set (h m s)
|
||||||
|
"(rtc-set hr min sec)
|
||||||
|
Set the time on a DS3231 RTC. Times are in BCD, so use
|
||||||
|
the appropriate reader macro, e.g. (rtc-set #x12 #x34 #x00)
|
||||||
|
for 12:34:00."
|
||||||
|
(let ((h (dec-to-bcd h))
|
||||||
|
(m (dec-to-bcd m))
|
||||||
|
(s (dec-to-bcd s)))
|
||||||
|
(with-i2c (str *rtc-port* #x68)
|
||||||
|
(write-byte 0 str)
|
||||||
|
(write-byte s str)
|
||||||
|
(write-byte m str)
|
||||||
|
(write-byte h str)))
|
||||||
|
|
||||||
(defun rtc-get ()
|
(defun rtc-get ()
|
||||||
(with-i2c (str *rtc-port* #x68)
|
(with-i2c (str *rtc-port* #x68)
|
||||||
|
@ -40,4 +46,7 @@ Set the time using the RTC."
|
||||||
(apply now (rtc-get)))
|
(apply now (rtc-get)))
|
||||||
|
|
||||||
(defun now-rtc ()
|
(defun now-rtc ()
|
||||||
|
"(now-rtc)
|
||||||
|
Sets the RTC time using the now function."
|
||||||
|
(apply rtc-set (now)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue