summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--software/ihu/ihu.asm3
-rw-r--r--software/ihu/rtc.inc54
2 files changed, 50 insertions, 7 deletions
diff --git a/software/ihu/ihu.asm b/software/ihu/ihu.asm
index 48045ce..93780f7 100644
--- a/software/ihu/ihu.asm
+++ b/software/ihu/ihu.asm
@@ -269,6 +269,9 @@ main
btfsc STATUS,Z
goto main
+ movlw BUF
+ movwf FSR
+ call rtc_get_time
clrf TMP
goto main
diff --git a/software/ihu/rtc.inc b/software/ihu/rtc.inc
index 18ac185..5a1446c 100644
--- a/software/ihu/rtc.inc
+++ b/software/ihu/rtc.inc
@@ -150,19 +150,19 @@ rtc_init
movlw RTC_ADDR_W
call i2c_send_byte
btfsc RTC_BYTE,0
- goto rtc_init_error_ack
+ goto rtc_error_ack
movlw RTC_REG_STAT
call i2c_send_byte
btfsc RTC_BYTE,0
- goto rtc_init_error_ack
+ goto rtc_error_ack
call i2c_restart
movlw RTC_ADDR_R
call i2c_send_byte
btfsc RTC_BYTE,0
- goto rtc_init_error_ack
+ goto rtc_error_ack
call i2c_recv_byte
call i2c_nack
@@ -179,12 +179,12 @@ rtc_init_after_clock_fail
movlw RTC_ADDR_W
call i2c_send_byte
btfsc RTC_BYTE,0
- goto rtc_init_error_ack
+ goto rtc_error_ack
movlw RTC_REG_SEC
call i2c_send_byte
btfsc RTC_BYTE,0
- goto rtc_init_error_ack
+ goto rtc_error_ack
movlw .16
movwf RTC_BYTE_CNT
@@ -192,14 +192,54 @@ rtc_init_clear
clrw
call i2c_send_byte
btfsc RTC_BYTE,0
- goto rtc_init_error_ack
+ goto rtc_error_ack
decfsz RTC_BYTE_CNT,f
goto rtc_init_clear
call i2c_stop
return
-rtc_init_error_ack
+ ;; ---------------
+rtc_get_time
+ call i2c_start
+
+ movlw RTC_ADDR_W
+ call i2c_send_byte
+ btfsc RTC_BYTE,0
+ goto rtc_error_ack
+
+ movlw RTC_REG_SEC
+ call i2c_send_byte
+ btfsc RTC_BYTE,0
+ goto rtc_error_ack
+
+ call i2c_restart
+
+ movlw RTC_ADDR_R
+ call i2c_send_byte
+ btfsc RTC_BYTE,0
+ goto rtc_error_ack
+
+ movlw .7
+ movwf RTC_BYTE_CNT
+rtc_get_time_loop
+ call i2c_recv_byte
+ movf RTC_BYTE,w
+ movwf INDF
+ decfsz RTC_BYTE_CNT,f
+ goto rtc_get_time_next
+
+ call i2c_nack
+ call i2c_stop
+ return
+
+rtc_get_time_next
+ incf FSR,f
+ call i2c_ack
+ goto rtc_get_time_loop
+
+ ;; ---------------
+rtc_error_ack
call i2c_stop
;; TODO: add error handling
return