summaryrefslogtreecommitdiff
path: root/software/ihu/rtc.inc
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2011-12-13 02:15:26 +0000
committerChristian Pointner <equinox@mur.at>2011-12-13 02:15:26 +0000
commit02170fc7bfdc9a8751fc2525887455aaa9fcb2b2 (patch)
treeafae2323acaf8eae56a1b2d9b6f28786733262b7 /software/ihu/rtc.inc
parentrtc_init only after rtc_rst goes high (diff)
moved i2c stuff to seperate file
git-svn-id: https://svn.spreadspace.org/mur.sat@225 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software/ihu/rtc.inc')
-rw-r--r--software/ihu/rtc.inc147
1 files changed, 15 insertions, 132 deletions
diff --git a/software/ihu/rtc.inc b/software/ihu/rtc.inc
index 3f09557..7890b48 100644
--- a/software/ihu/rtc.inc
+++ b/software/ihu/rtc.inc
@@ -47,148 +47,31 @@ RTC_INIT_CTL EQU b'00001000'
;; RTC_INIT_TCH EQU b'10101011' ; trickle charger enabled with diode and 4kohm
RTC_INIT_TCH EQU b'00001011' ; trickle charger disabled
- ;; -------------------------------------
-i2c_start
- bsf STATUS,RP0
- bcf TRISB,RTC_SDA
- nop
- bcf TRISB,RTC_SCL
- bcf STATUS,RP0
- return
-
- ;; ------------------
-i2c_restart
- bsf STATUS,RP0
- bsf TRISB,RTC_SDA
- nop
- bsf TRISB,RTC_SCL
- nop
- nop
- nop
- bcf TRISB,RTC_SDA
- nop
- bcf TRISB,RTC_SCL
- bcf STATUS,RP0
- return
-
- ;; ------------------
-i2c_stop
- bsf STATUS,RP0
- bsf TRISB,RTC_SCL
- nop
- bsf TRISB,RTC_SDA
- bcf STATUS,RP0
- return
-
- ;; ------------------
-i2c_send_byte
- movwf RTC_BYTE
- movlw .8
- movwf RTC_BIT_CNT
- bsf STATUS,RP0
-i2c_send_byte_next
- btfss RTC_BYTE,7
- bcf TRISB,RTC_SDA
- btfsc RTC_BYTE,7
- bsf TRISB,RTC_SDA
- nop
- bsf TRISB,RTC_SCL
- nop
- nop
- bcf TRISB,RTC_SCL
- rlf RTC_BYTE,f
- decfsz RTC_BIT_CNT,f
- goto i2c_send_byte_next
-
- nop
- nop
- bsf TRISB,RTC_SDA
- bsf TRISB,RTC_SCL
- bcf STATUS,RP0
- movf PORTB,w
- bsf STATUS,RP0
- bcf TRISB,RTC_SCL
- bcf TRISB,RTC_SDA
- bcf STATUS,RP0
- andlw b'00010000'
- movwf RTC_BYTE
- swapf RTC_BYTE,f
- return
-
- ;; ------------------
-i2c_recv_byte
- clrf RTC_BYTE
- movlw .8
- movwf RTC_BIT_CNT
- bsf STATUS,RP0
- bsf TRISB,RTC_SDA
-i2c_recv_byte_loop
- bsf TRISB,RTC_SCL
- bcf STATUS,RP0
- btfsc PORTB,RTC_SDA
- bsf RTC_BYTE,0
- bsf STATUS,RP0
- bcf TRISB,RTC_SCL
- decfsz RTC_BIT_CNT,f
- goto i2c_recv_byte_next
-
- bcf TRISB,RTC_SDA
- bcf STATUS,RP0
- return
-
-i2c_recv_byte_next
- bcf STATUS,C
- rlf RTC_BYTE,f
- goto i2c_recv_byte_loop
-
- ;; ------------------
-i2c_ack
- bsf STATUS,RP0
- bcf TRISB,RTC_SDA
- bsf TRISB,RTC_SCL
- nop
- nop
- bcf TRISB,RTC_SCL
- bcf STATUS,RP0
- return
-
- ;; ------------------
-i2c_nack
- bsf STATUS,RP0
- bsf TRISB,RTC_SDA
- bsf TRISB,RTC_SCL
- nop
- nop
- bcf TRISB,RTC_SCL
- bcf TRISB,RTC_SDA
- bcf STATUS,RP0
- return
-
- ;; -------------------------------------
+ ;; -------------------------------------
rtc_init
call i2c_start
movlw RTC_ADDR_W
call i2c_send_byte
- btfsc RTC_BYTE,0
+ btfsc I2C_BYTE,0
goto rtc_error_ack
movlw RTC_REG_STAT
call i2c_send_byte
- btfsc RTC_BYTE,0
+ btfsc I2C_BYTE,0
goto rtc_error_ack
call i2c_restart
movlw RTC_ADDR_R
call i2c_send_byte
- btfsc RTC_BYTE,0
+ btfsc I2C_BYTE,0
goto rtc_error_ack
call i2c_recv_byte
call i2c_nack
- btfsc RTC_BYTE,7
+ btfsc I2C_BYTE,7
goto rtc_init_after_clock_fail
call i2c_stop
@@ -199,12 +82,12 @@ rtc_init_after_clock_fail
movlw RTC_ADDR_W
call i2c_send_byte
- btfsc RTC_BYTE,0
+ btfsc I2C_BYTE,0
goto rtc_error_ack
movlw RTC_REG_TOD0
call i2c_send_byte
- btfsc RTC_BYTE,0
+ btfsc I2C_BYTE,0
goto rtc_error_ack
movlw .7
@@ -212,24 +95,24 @@ rtc_init_after_clock_fail
rtc_init_clear
clrw
call i2c_send_byte
- btfsc RTC_BYTE,0
+ btfsc I2C_BYTE,0
goto rtc_error_ack
decfsz RTC_BYTE_CNT,f
goto rtc_init_clear
movlw RTC_INIT_CTL
call i2c_send_byte
- btfsc RTC_BYTE,0
+ btfsc I2C_BYTE,0
goto rtc_error_ack
clrw
call i2c_send_byte
- btfsc RTC_BYTE,0
+ btfsc I2C_BYTE,0
goto rtc_error_ack
movlw RTC_INIT_TCH
call i2c_send_byte
- btfsc RTC_BYTE,0
+ btfsc I2C_BYTE,0
goto rtc_error_ack
call i2c_stop
@@ -243,26 +126,26 @@ rtc_get_time
movlw RTC_ADDR_W
call i2c_send_byte
- btfsc RTC_BYTE,0
+ btfsc I2C_BYTE,0
goto rtc_error_ack
movlw RTC_REG_TOD0
call i2c_send_byte
- btfsc RTC_BYTE,0
+ btfsc I2C_BYTE,0
goto rtc_error_ack
call i2c_restart
movlw RTC_ADDR_R
call i2c_send_byte
- btfsc RTC_BYTE,0
+ btfsc I2C_BYTE,0
goto rtc_error_ack
movlw .4
movwf RTC_BYTE_CNT
rtc_get_time_loop
call i2c_recv_byte
- movf RTC_BYTE,w
+ movf I2C_BYTE,w
movwf INDF
decfsz RTC_BYTE_CNT,f
goto rtc_get_time_next