summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--software/ihu/ihu.asm200
1 files changed, 122 insertions, 78 deletions
diff --git a/software/ihu/ihu.asm b/software/ihu/ihu.asm
index fe4bc66..2b33219 100644
--- a/software/ihu/ihu.asm
+++ b/software/ihu/ihu.asm
@@ -38,7 +38,6 @@
;; -------------------------------------
;; DEFINES
;; constants
-I2C_SPEED EQU .29
RTC_ADDR_W EQU b'11010000'
RTC_ADDR_R EQU b'11010001'
RTC_REG_SEC EQU H'00'
@@ -71,17 +70,17 @@ DTMF_INT EQU 0
BAT_V EQU 1
SOLAR_V EQU 2
BAT_C EQU 3
-MPU_PWRDWN EQU 4
-MPU_RESET EQU 5
-MPU_INT EQU 6
-RTC_INT EQU 7
-;; PortC
-MPU_CLK EQU 0
-MPU_SDO EQU 1
-MPU_SDI EQU 2
-RTC_SCL EQU 3
RTC_SDA EQU 4
-MPU_CS EQU 5
+RTC_SCL EQU 5
+RTC_INT EQU 6
+MPU_INT EQU 7
+;; PortC
+MPU_PWRDWN EQU 0
+MPU_RESET EQU 1
+MPU_CS EQU 2
+MPU_SCK EQU 3
+MPU_SDI EQU 4
+MPU_SDO EQU 5
ICOM_TX EQU 6
ICOM_RX EQU 7
;; PortD
@@ -106,7 +105,7 @@ TTX_BIT_CNT EQU H'0022'
TTX_BYTE_CNT EQU H'0023'
TTX_CSUM EQU H'0024'
-RTC_CNT EQU H'0028'
+RTC_BYTE_CNT EQU H'0028'
WAIT_CNT EQU H'0030'
@@ -114,6 +113,9 @@ BUF EQU H'0040'
BUF_END EQU H'004F'
;; all pages
+RTC_BYTE EQU H'0070'
+RTC_BIT_CNT EQU H'0071'
+
W_TEMP EQU H'007E'
STATUS_TEMP EQU H'007F'
@@ -173,7 +175,7 @@ init
;; bank 1
bsf STATUS,RP0
bcf STATUS,RP1
- movlw b'11000001'
+ movlw b'11110000'
movwf WPUB
movlw b'11000000'
movwf IOCB
@@ -182,9 +184,9 @@ init
clrf PSTRCON
movlw b'00010000'
movwf OSCCON
- movlw b'11001111'
+ movlw b'11111111'
movwf TRISB
- movlw b'11011100'
+ movlw b'11111000'
movwf TRISC
movlw b'10001111'
movwf TRISD
@@ -193,9 +195,6 @@ init
movlw .12
movwf SPBRG
clrf SPBRGH
- movlw I2C_SPEED
- movwf SSPADD
- bsf SSPSTAT,SMP
movlw b'00100000'
movwf PIE1
clrf PIE2
@@ -205,11 +204,11 @@ init
bcf STATUS,RP1
movlw b'10010000'
movwf RCSTA
- movlw b'00101000'
- movwf SSPCON
movlw B'01000000'
movwf INTCON
+ clrf PORTB
+
bsf PORTD,DTMF_PWRDWN
bcf PORTD,TTX_RESET ;reset TTX
nop
@@ -363,137 +362,183 @@ ttx_csum_error
;; -------------------------------------
i2c_start
- bcf PIR1,SSPIF
bsf STATUS,RP0
- bsf SSPCON2,SEN
+ bcf TRISB,RTC_SDA
+ nop
+ bcf TRISB,RTC_SCL
bcf STATUS,RP0
- goto i2c_wait
+ return
;; ------------------
i2c_restart
- bcf PIR1,SSPIF
bsf STATUS,RP0
- bsf SSPCON2,RSEN
+ bsf TRISB,RTC_SDA
+ nop
+ bsf TRISB,RTC_SCL
+ nop
+ nop
+ nop
+ bcf TRISB,RTC_SDA
+ nop
+ bcf TRISB,RTC_SCL
bcf STATUS,RP0
- goto i2c_wait
+ return
;; ------------------
i2c_stop
- bcf PIR1,SSPIF
bsf STATUS,RP0
- bsf SSPCON2,PEN
+ bsf TRISB,RTC_SCL
+ nop
+ bsf TRISB,RTC_SDA
bcf STATUS,RP0
- goto i2c_wait
+ return
;; ------------------
i2c_send_byte
- bcf PIR1,SSPIF
- movwf SSPBUF
- goto i2c_wait
+ 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
+ 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
- bcf PIR1,SSPIF
+ clrf RTC_BYTE
+ movlw .8
+ movwf RTC_BIT_CNT
bsf STATUS,RP0
- bsf SSPCON2,RCEN
+ bsf TRISB,RTC_SDA
+i2c_recv_byte_loop
+ bsf TRISB,RTC_SCL
bcf STATUS,RP0
- goto i2c_wait
+ 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
+ rlf RTC_BYTE,f
+ goto i2c_recv_byte_loop
;; ------------------
i2c_ack
- bcf PIR1,SSPIF
bsf STATUS,RP0
- bcf SSPCON2,ACKDT
- bsf SSPCON2,ACKEN
+ bcf TRISB,RTC_SDA
+ bsf TRISB,RTC_SCL
+ nop
+ nop
+ bcf TRISB,RTC_SCL
bcf STATUS,RP0
- goto i2c_wait
+ return
;; ------------------
i2c_nack
- bcf PIR1,SSPIF
bsf STATUS,RP0
- bsf SSPCON2,ACKDT
- bsf SSPCON2,ACKEN
+ bsf TRISB,RTC_SDA
+ bsf TRISB,RTC_SCL
+ nop
+ nop
+ bcf TRISB,RTC_SCL
+ bcf TRISB,RTC_SDA
bcf STATUS,RP0
-
-i2c_wait
- btfss PIR1,SSPIF
- goto i2c_wait
return
;; -------------------------------------
rtc_init
call i2c_start
-
+
movlw RTC_ADDR_W
call i2c_send_byte
- bsf STATUS,RP0
- btfsc SSPCON2,ACKSTAT
+ btfsc RTC_BYTE,0
goto rtc_init_error_ack
- bcf STATUS,RP0
movlw RTC_REG_STAT
call i2c_send_byte
- bsf STATUS,RP0
- btfsc SSPCON2,ACKSTAT
+ btfsc RTC_BYTE,0
goto rtc_init_error_ack
- bcf STATUS,RP0
call i2c_restart
movlw RTC_ADDR_R
call i2c_send_byte
- bsf STATUS,RP0
- btfsc SSPCON2,ACKSTAT
+ btfsc RTC_BYTE,0
goto rtc_init_error_ack
- bcf STATUS,RP0
call i2c_recv_byte
call i2c_nack
- call i2c_stop
- btfsc SSPBUF,7
- goto rtc_init_clock_fail
+ btfsc RTC_BYTE,7
+ goto rtc_init_after_clock_fail
+ call i2c_stop
movlw '.'
movwf TXREG
return
-rtc_init_clock_fail
- call i2c_start
+rtc_init_after_clock_fail
+ call i2c_restart
movlw RTC_ADDR_W
call i2c_send_byte
- bsf STATUS,RP0
- btfsc SSPCON2,ACKSTAT
+ btfsc RTC_BYTE,0
goto rtc_init_error_ack
- bcf STATUS,RP0
movlw RTC_REG_SEC
call i2c_send_byte
- bsf STATUS,RP0
- btfsc SSPCON2,ACKSTAT
+ btfsc RTC_BYTE,0
goto rtc_init_error_ack
- bcf STATUS,RP0
- movlw .16
- movwf RTC_CNT
+ movlw .14
+ movwf RTC_BYTE_CNT
rtc_init_clear
clrw
call i2c_send_byte
- bsf STATUS,RP0
- btfsc SSPCON2,ACKSTAT
+ btfsc RTC_BYTE,0
goto rtc_init_error_ack
- bcf STATUS,RP0
- decfsz RTC_CNT,f
+ decfsz RTC_BYTE_CNT,f
goto rtc_init_clear
- movlw b'00000011'
+ movlw b'00000001'
call i2c_send_byte
- bsf STATUS,RP0
- btfsc SSPCON2,ACKSTAT
+ btfsc RTC_BYTE,0
+ goto rtc_init_error_ack
+
+ clrw
+ call i2c_send_byte
+ btfsc RTC_BYTE,0
goto rtc_init_error_ack
- bcf STATUS,RP0
call i2c_stop
movlw 'c'
@@ -501,7 +546,6 @@ rtc_init_clear
return
rtc_init_error_ack
- bcf STATUS,RP0
call i2c_stop
movlw 'E'
movwf TXREG