From 02170fc7bfdc9a8751fc2525887455aaa9fcb2b2 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 13 Dec 2011 02:15:26 +0000 Subject: moved i2c stuff to seperate file git-svn-id: https://svn.spreadspace.org/mur.sat@225 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/ihu/i2c.inc | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++ software/ihu/ihu.asm | 13 +++-- software/ihu/rtc.inc | 147 ++++++-------------------------------------------- 3 files changed, 171 insertions(+), 137 deletions(-) create mode 100644 software/ihu/i2c.inc (limited to 'software/ihu') diff --git a/software/ihu/i2c.inc b/software/ihu/i2c.inc new file mode 100644 index 0000000..8742adc --- /dev/null +++ b/software/ihu/i2c.inc @@ -0,0 +1,148 @@ + ;; + ;; mur.sat + ;; + ;; Somewhen in the year 2011, mur.at will have a nano satellite launched + ;; into a low earth orbit (310 km above the surface of our planet). The + ;; satellite itself is a TubeSat personal satellite kit, developed and + ;; launched by interorbital systems. mur.sat is a joint venture of mur.at, + ;; ESC im Labor and realraum. + ;; + ;; Please visit the project hompage at sat.mur.at for further information. + ;; + ;; + ;; Copyright (C) 2011 Christian Pointner + ;; + ;; This file is part of mur.sat. + ;; + ;; mur.sat is free software: you can redistribute it and/or modify + ;; it under the terms of the GNU General Public License as published by + ;; the Free Software Foundation, either version 3 of the License, or + ;; any later version. + ;; + ;; mur.sat is distributed in the hope that it will be useful, + ;; but WITHOUT ANY WARRANTY; without even the implied warranty of + ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ;; GNU General Public License for more details. + ;; + ;; You should have received a copy of the GNU General Public License + ;; along with mur.sat. If not, see . + ;; + + ;; ------------------------------------- +i2c_start + bsf STATUS,RP0 + bcf TRISB,I2C_SDA + nop + bcf TRISB,I2C_SCL + bcf STATUS,RP0 + return + + ;; ------------------ +i2c_restart + bsf STATUS,RP0 + bsf TRISB,I2C_SDA + nop + bsf TRISB,I2C_SCL + nop + nop + nop + bcf TRISB,I2C_SDA + nop + bcf TRISB,I2C_SCL + bcf STATUS,RP0 + return + + ;; ------------------ +i2c_stop + bsf STATUS,RP0 + bsf TRISB,I2C_SCL + nop + bsf TRISB,I2C_SDA + bcf STATUS,RP0 + return + + ;; ------------------ +i2c_send_byte + movwf I2C_BYTE + movlw .8 + movwf I2C_BIT_CNT + bsf STATUS,RP0 +i2c_send_byte_next + btfss I2C_BYTE,7 + bcf TRISB,I2C_SDA + btfsc I2C_BYTE,7 + bsf TRISB,I2C_SDA + nop + bsf TRISB,I2C_SCL + nop + nop + bcf TRISB,I2C_SCL + rlf I2C_BYTE,f + decfsz I2C_BIT_CNT,f + goto i2c_send_byte_next + + nop + nop + bsf TRISB,I2C_SDA + bsf TRISB,I2C_SCL + bcf STATUS,RP0 + movf PORTB,w + bsf STATUS,RP0 + bcf TRISB,I2C_SCL + bcf TRISB,I2C_SDA + bcf STATUS,RP0 + andlw b'00010000' + movwf I2C_BYTE + swapf I2C_BYTE,f + return + + ;; ------------------ +i2c_recv_byte + clrf I2C_BYTE + movlw .8 + movwf I2C_BIT_CNT + bsf STATUS,RP0 + bsf TRISB,I2C_SDA +i2c_recv_byte_loop + bsf TRISB,I2C_SCL + bcf STATUS,RP0 + btfsc PORTB,I2C_SDA + bsf I2C_BYTE,0 + bsf STATUS,RP0 + bcf TRISB,I2C_SCL + decfsz I2C_BIT_CNT,f + goto i2c_recv_byte_next + + bcf TRISB,I2C_SDA + bcf STATUS,RP0 + return + +i2c_recv_byte_next + bcf STATUS,C + rlf I2C_BYTE,f + goto i2c_recv_byte_loop + + ;; ------------------ +i2c_ack + bsf STATUS,RP0 + bcf TRISB,I2C_SDA + bsf TRISB,I2C_SCL + nop + nop + bcf TRISB,I2C_SCL + bcf STATUS,RP0 + return + + ;; ------------------ +i2c_nack + bsf STATUS,RP0 + bsf TRISB,I2C_SDA + bsf TRISB,I2C_SCL + nop + nop + bcf TRISB,I2C_SCL + bcf TRISB,I2C_SDA + bcf STATUS,RP0 + return + + ;; ------------------------------------- diff --git a/software/ihu/ihu.asm b/software/ihu/ihu.asm index 18c0db4..e110783 100644 --- a/software/ihu/ihu.asm +++ b/software/ihu/ihu.asm @@ -52,8 +52,8 @@ DTMF_INT EQU 0 BAT_V EQU 1 SOLAR_V EQU 2 BAT_C EQU 3 -RTC_SDA EQU 4 -RTC_SCL EQU 5 +I2C_SDA EQU 4 +I2C_SCL EQU 5 RTC_INT EQU 6 RTC_RST EQU 7 ;; PortC @@ -129,8 +129,8 @@ CALC_TEMP3 EQU H'0117' ;; all pages -RTC_BYTE EQU H'0070' -RTC_BIT_CNT EQU H'0071' +I2C_BYTE EQU H'0070' +I2C_BIT_CNT EQU H'0071' OWIRE_BYTE EQU H'0072' OWIRE_BIT_CNT EQU H'0073' OWIRE_CNT EQU H'0074' @@ -336,6 +336,9 @@ uart_rx_fe ;; ------------------------------------- include "ttx.inc" + ;; ------------------------------------- + include "i2c.inc" + ;; ------------------------------------- include "rtc.inc" @@ -348,7 +351,7 @@ uart_rx_fe ;; ------------------------------------- ;; MAINLOOP main - sleep +; sleep nop ;; -------------------- 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 -- cgit v1.2.3