summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--software/ihu/ihu.asm81
1 files changed, 68 insertions, 13 deletions
diff --git a/software/ihu/ihu.asm b/software/ihu/ihu.asm
index 88fc5c0..fe4bc66 100644
--- a/software/ihu/ihu.asm
+++ b/software/ihu/ihu.asm
@@ -38,9 +38,25 @@
;; -------------------------------------
;; DEFINES
;; constants
+I2C_SPEED EQU .29
RTC_ADDR_W EQU b'11010000'
RTC_ADDR_R EQU b'11010001'
-I2C_SPEED EQU .19
+RTC_REG_SEC EQU H'00'
+RTC_REG_MIN EQU H'01'
+RTC_REG_HOUR EQU H'02'
+RTC_REG_DOW EQU H'03'
+RTC_REG_DOM EQU H'04'
+RTC_REG_MON EQU H'05'
+RTC_REG_YEAR EQU H'06'
+RTC_REG_A1S EQU H'07'
+RTC_REG_A1M EQU H'08'
+RTC_REG_A1H EQU H'09'
+RTC_REG_A1D EQU H'0A'
+RTC_REG_A2M EQU H'0B'
+RTC_REG_A2H EQU H'0C'
+RTC_REG_A2D EQU H'0D'
+RTC_REG_CON EQU H'0E'
+RTC_REG_STAT EQU H'0F'
;; I/O Pins
;; PortA
@@ -89,7 +105,9 @@ TTX_BYTE EQU H'0021'
TTX_BIT_CNT EQU H'0022'
TTX_BYTE_CNT EQU H'0023'
TTX_CSUM EQU H'0024'
-
+
+RTC_CNT EQU H'0028'
+
WAIT_CNT EQU H'0030'
BUF EQU H'0040'
@@ -224,7 +242,7 @@ wait_loop
decfsz WAIT_CNT,f
goto wait_next
return
-
+
;; -------------------------------------
uart_rx_byte
btfsc RCSTA,FERR
@@ -414,7 +432,7 @@ rtc_init
goto rtc_init_error_ack
bcf STATUS,RP0
- movlw H'0E'
+ movlw RTC_REG_STAT
call i2c_send_byte
bsf STATUS,RP0
btfsc SSPCON2,ACKSTAT
@@ -431,27 +449,64 @@ rtc_init
bcf STATUS,RP0
call i2c_recv_byte
- movf SSPBUF,w
- movwf TXREG
- call i2c_ack
-
- call i2c_recv_byte
- movf SSPBUF,w
- movwf TXREG
call i2c_nack
-
call i2c_stop
+
+ btfsc SSPBUF,7
+ goto rtc_init_clock_fail
+
movlw '.'
movwf TXREG
return
+rtc_init_clock_fail
+ call i2c_start
+
+ movlw RTC_ADDR_W
+ call i2c_send_byte
+ bsf STATUS,RP0
+ btfsc SSPCON2,ACKSTAT
+ goto rtc_init_error_ack
+ bcf STATUS,RP0
+
+ movlw RTC_REG_SEC
+ call i2c_send_byte
+ bsf STATUS,RP0
+ btfsc SSPCON2,ACKSTAT
+ goto rtc_init_error_ack
+ bcf STATUS,RP0
+
+ movlw .16
+ movwf RTC_CNT
+rtc_init_clear
+ clrw
+ call i2c_send_byte
+ bsf STATUS,RP0
+ btfsc SSPCON2,ACKSTAT
+ goto rtc_init_error_ack
+ bcf STATUS,RP0
+ decfsz RTC_CNT,f
+ goto rtc_init_clear
+
+ movlw b'00000011'
+ call i2c_send_byte
+ bsf STATUS,RP0
+ btfsc SSPCON2,ACKSTAT
+ goto rtc_init_error_ack
+ bcf STATUS,RP0
+
+ call i2c_stop
+ movlw 'c'
+ movwf TXREG
+ return
+
rtc_init_error_ack
bcf STATUS,RP0
call i2c_stop
movlw 'E'
movwf TXREG
return
-
+
;; -------------------------------------
;; MAINLOOP
main