diff options
-rw-r--r-- | software/ihu/Makefile | 4 | ||||
-rw-r--r-- | software/ihu/i2c.inc | 30 | ||||
-rw-r--r-- | software/ihu/ihu.asm | 429 | ||||
-rw-r--r-- | software/ihu/rtc.inc | 28 | ||||
-rw-r--r-- | software/ihu/tables.inc | 26 | ||||
-rw-r--r-- | software/ihu/ttx.inc | 230 |
6 files changed, 134 insertions, 613 deletions
diff --git a/software/ihu/Makefile b/software/ihu/Makefile index 7325908..a5184a8 100644 --- a/software/ihu/Makefile +++ b/software/ihu/Makefile @@ -8,10 +8,10 @@ ## ESC im Labor and realraum. ## ## Please visit the project hompage at sat.mur.at for further information. -## +## ## ## Copyright (C) 2011 Christian Pointner <equinox@mur.at> -## +## ## This file is part of mur.sat. ## ## mur.sat is free software: you can redistribute it and/or modify diff --git a/software/ihu/i2c.inc b/software/ihu/i2c.inc index 85d323f..bbd424f 100644 --- a/software/ihu/i2c.inc +++ b/software/ihu/i2c.inc @@ -8,10 +8,10 @@ ;; ESC im Labor and realraum. ;; ;; Please visit the project hompage at sat.mur.at for further information. - ;; + ;; ;; ;; Copyright (C) 2011 Christian Pointner <equinox@mur.at> - ;; + ;; ;; This file is part of mur.sat. ;; ;; mur.sat is free software: you can redistribute it and/or modify @@ -29,6 +29,20 @@ ;; ;; ------------------------------------- +i2c_init + bsf STATUS,RP0 ; make them outputs first + bcf I2C_SDA ; every write access is read-update-write + bcf I2C_SCL ; therefore the second bcf SDA sets SCL again + bcf STATUS,RP0 ; because of the external pull-up + bcf I2C_SCL + bcf I2C_SDA + bsf STATUS,RP0 + bsf I2C_SDA + bsf I2C_SCL + bcf STATUS,RP0 + return + + ;; ------------------------------------- i2c_start bsf STATUS,RP0 bcf I2C_SDA @@ -36,7 +50,7 @@ i2c_start bcf I2C_SCL bcf STATUS,RP0 return - + ;; ------------------ i2c_restart bsf STATUS,RP0 @@ -51,7 +65,7 @@ i2c_restart bcf I2C_SCL bcf STATUS,RP0 return - + ;; ------------------ i2c_stop bsf STATUS,RP0 @@ -60,7 +74,7 @@ i2c_stop bsf I2C_SDA bcf STATUS,RP0 return - + ;; ------------------ i2c_send_byte movwf I2C_BYTE @@ -86,12 +100,12 @@ i2c_send_byte_next bsf I2C_SDA bsf I2C_SCL bcf STATUS,RP0 - movf PORTB,w + movf I2C_PORT,w bsf STATUS,RP0 bcf I2C_SCL bcf I2C_SDA bcf STATUS,RP0 - andlw b'00010000' + andlw I2C_SDA_MASK movwf I2C_BYTE swapf I2C_BYTE,f return @@ -132,7 +146,7 @@ i2c_ack bcf I2C_SCL bcf STATUS,RP0 return - + ;; ------------------ i2c_nack bsf STATUS,RP0 diff --git a/software/ihu/ihu.asm b/software/ihu/ihu.asm index 6c33b5c..eef9547 100644 --- a/software/ihu/ihu.asm +++ b/software/ihu/ihu.asm @@ -44,59 +44,52 @@ #define SOLAR_C0 PORTA,0 #define SOLAR_C1 PORTA,1 #define SOLAR_C2 PORTA,2 -#define SOLAR_C3 PORTA,3 +#define VREF PORTA,3 #define OWIRE PORTA,4 -#define SOLAR_C4 PORTA,5 +#define OW_TEMP PORTA,5 +;#define OSC2 PORTA,6 +;#define OSC1 PORTA,7 ;; PortB -#define DTMF_INT PORTB,0 -#define BAT_V PORTB,1 -#define SOLAR_V PORTB,2 -#define BAT_C PORTB,3 -#define I2C_SDA PORTB,4 -#define I2C_SCL PORTB,5 -#define RTC_INT PORTB,6 -#define RTC_RST PORTB,7 +#define CTR_INT PORTB,0 +#define POWER_FAIL PORTB,1 +#define CAPGOOD PORTB,2 +#define BAT_INT PORTB,3 +#define DEPLOY PORTB,4 +#define RTC_RST PORTB,5 +;#define PGC PORTB,6 +;#define PGD PORTB,7 ;; PortC -#define MPU_PWRDWN PORTC,0 -#define MPU_RESET PORTC,1 -#define UNDEF_C2 PORTC,2 -#define UNDEF_C3 PORTC,3 -#define UNDEF_C4 PORTC,4 -#define UNDEF_C5 PORTC,5 +#define MPU_RST PORTC,0 +#define CTR_RST PORTC,1 +#define BAT_RST PORTC,2 +#define SPI_SCK PORTC,3 +#define SPI_MISO PORTC,4 +#define SPI_MOSI PORTC,5 #define MPU_TX PORTC,6 #define MPU_RX PORTC,7 ;; PortD -#define DTMF_D0 PORTD,0 -#define DTMF_D1 PORTD,1 -#define DTMF_D2 PORTD,2 -#define DTMF_D3 PORTD,3 -#define DTMF_PWRDWN PORTD,4 -#define TTX_RESET PORTD,5 -#define TTX_SCL PORTD,6 -#define TTX_SDA PORTD,7 +#define I2C_SCL PORTD,0 +#define I2C_SDA PORTD,1 +I2C_PORT EQU PORTD +I2C_SDA_MASK EQU b'00000010' +#define CTR_SS PORTD,2 +#define BAT_SS PORTD,3 +#define MPU_EN PORTD,4 +#define HEAT_EN PORTD,5 +#define RADIO_SILENCE PORTD,6 +#define MAIN_OFF PORTD,7 ;; PortE -#define SOLAR_C5 PORTE,0 -#define SOLAR_C6 PORTE,1 -#define SOLAR_C7 PORTE,2 +#define SOLAR_V0 PORTE,0 +#define SOLAR_V1 PORTE,1 +#define SOLAR_V2 PORTE,2 ;; variables ;; page 0 only TMP EQU H'0020' -TTX_BYTE EQU H'0021' -TTX_BIT_CNT EQU H'0022' -TTX_BYTE_CNT EQU H'0023' -TTX_CSUM EQU H'0024' - -RTC_BYTE_CNT EQU H'0028' WAIT_CNT EQU H'002F' -DTMF_BUF EQU H'0030' ; 5Bytes for incoming DTMF commands -DTMF_BUF_END EQU H'0034' -DTMF_BUF_PTR EQU H'0035' -DTMF_CS EQU H'0036' -DTMF_TIMEOUT EQU H'0037' - +RTC_BYTE_CNT EQU H'0028' RTC_TOD0 EQU H'003A' RTC_TOD1 EQU H'003B' RTC_TOD2 EQU H'003C' @@ -105,43 +98,6 @@ RTC_TOD3 EQU H'003D' BUF EQU H'0040' BUF_END EQU H'004F' -ADC_SOLAR_C0 EQU H'0050' -ADC_SOLAR_C1 EQU H'0051' -ADC_SOLAR_C2 EQU H'0052' -ADC_SOLAR_C3 EQU H'0053' -ADC_SOLAR_V0 EQU H'0054' -ADC_SOLAR_C4 EQU H'0055' -ADC_SOLAR_C5 EQU H'0056' -ADC_SOLAR_C6 EQU H'0057' -ADC_SOLAR_C7 EQU H'0058' -ADC_SOLAR_V1 EQU H'0059' -SOL_POWERL EQU H'005A' -SOL_POWERH EQU H'005B' - -SOL_CALC_0 EQU H'005C' -SOL_CALC_1 EQU H'005D' -SOL_CALC_2 EQU H'005E' -SOL_CALC_3 EQU H'005F' -SOL_CALC_4 EQU H'0060' -SOL_CALC_5 EQU H'0061' -SOL_CALC_6 EQU H'0062' -SOL_CALC_7 EQU H'0063' -SOL_CALC_8 EQU H'0064' -SOL_CALC_9 EQU H'0065' -SOL_CALC_CNT EQU H'0066' - - ;; variables - ;; page 2 only -CALC_ACC0 EQU H'0110' -CALC_ACC1 EQU H'0111' -CALC_ACC2 EQU H'0112' -CALC_ACC3 EQU H'0113' -CALC_TEMP0 EQU H'0114' -CALC_TEMP1 EQU H'0115' -CALC_TEMP2 EQU H'0116' -CALC_TEMP3 EQU H'0117' - - ;; all pages I2C_BYTE EQU H'0070' I2C_BIT_CNT EQU H'0071' @@ -157,12 +113,12 @@ STATUS_TEMP EQU H'007F' ;; ------------------------------------- ;; Reset Vector - org 0 + org 0 goto init ;; ------------------------------------- ;; Interrupt Vector - org 4 + org 4 ;; save context movwf W_TEMP swapf STATUS,W @@ -175,63 +131,21 @@ STATUS_TEMP EQU H'007F' ;; dispatch interrupt sources btfsc INTCON,INTF - goto int_dtmf + goto int_ctr btfsc INTCON,RBIF - goto int_rtc + goto int_portchange btfsc PIR1,RCIF goto int_uart_rx - btfsc PIR1,TMR1IF - goto int_tmr1 goto interrupt_end -int_dtmf - movf DTMF_BUF_PTR,w - movwf FSR - movf PORTD,w - andlw b'00001111' - xorwf DTMF_CS,f - movwf INDF - incf DTMF_BUF_PTR,f - movlw DTMF_BUF_END - subwf DTMF_BUF_PTR,w - btfss STATUS,C - goto int_dtmf_end - btfsc STATUS,Z - goto int_dtmf_end - ;; DTMF command complete - movlw .1 - movwf TMP - -int_dtmf_end - bcf T1CON,TMR1ON - clrf TMR1L - clrf TMR1H - movlw .6 - movwf DTMF_TIMEOUT - bsf T1CON,TMR1ON +int_ctr bcf INTCON,INTF goto interrupt_end -int_tmr1 - decfsz DTMF_TIMEOUT,f - goto int_tmr1_end - bsf DTMF_PWRDWN - bcf T1CON,TMR1ON - movlw DTMF_BUF - movwf DTMF_BUF_PTR - clrf DTMF_CS - bcf DTMF_PWRDWN - -int_tmr1_end - bcf PIR1,TMR1IF - goto interrupt_end -int_rtc +int_portchange btfsc RTC_RST call rtc_init - goto int_rtc_end - -int_rtc_end bcf INTCON,RBIF goto interrupt_end @@ -265,76 +179,61 @@ init ;; bank 3 bsf STATUS,RP0 bsf STATUS,RP1 - movlw b'00000000' + movlw b'00010000' ; TX inverted, 8bit Baudrate, no auto baud detect movwf BAUDCTL - movlw b'11111111' - movwf ANSEL - movlw b'00000111' - movwf ANSELH + movlw b'11101111' ; AN0-AN3,AN5-AN7 as analog + movwf ANSEL ; AN4 as digital + clrf ANSELH ; AN8-AN13 as digital ;; bank 1 bsf STATUS,RP0 bcf STATUS,RP1 - movlw b'01110000' - movwf WPUB - movlw b'11000000' - movwf IOCB - movlw b'01000001' - movwf OPTION_REG - clrf PSTRCON - movlw b'00010000' + movlw b'00111111' ; Weak Pull-UPS for + movwf WPUB ; RTC_RST, DEPLOY, CAPGOOD, POWER_FAIL, BAT_INT, CTR_INT + movlw b'00100000' ; Port Change Interrup on + movwf IOCB ; RTC_RST + movlw b'00000010' ; Weak-Pull-UPs enabled, INT -> falling edge, TMR0 internal clock + movwf OPTION_REG ; Prescaler @ TMR0, Prescaler 1:8 + clrf PSTRCON ; disable pulse steering + movlw b'00010000' ; preselct 125 kHz, clock source as configured by configuration word movwf OSCCON - movlw b'11111111' + movlw b'11001111' ; input: RA0-RA3(analog),RA6-RA7(OSC); output: RA4-RA5(1wire) movwf TRISA - movlw b'11111111' + movlw b'11111111' ; input: all (interrupts and stats) movwf TRISB - movlw b'11111100' + ;; movlw b'11010000' ; input: SPI_MISO,RX,TX; output: (MPU|CTR|BAT)_RST,SPI_(CLK|MOSI) + movlw b'11111111' ; input: all; output: none movwf TRISC - movlw b'10001111' + movlw b'00000011' ; input: I2C_(SDA|SCL); output: (CTR,BAT)_SS, (MPU|HEAT)_EN, RADIO_SILENCE, MAIN_OFF movwf TRISD - movlw b'11111111' + movlw b'11111111' ; intput all (analog) movwf TRISE + movlw b'00010000' ; result left justified, V_REF_low = 0, V_REF_high = AN3 clrf ADCON1 - movlw b'00100100' + movlw b'00100100' ; Baudrate = High Speed, async mode, transmit enabled, 8bit movwf TXSTA - movlw .12 + movlw .25 ; Baudrate = 19200 (@ 8MHz) movwf SPBRG clrf SPBRGH - movlw b'00100001' + movlw b'00100000' ; enable UART RX Interrupt movwf PIE1 clrf PIE2 ;; bank 0 bcf STATUS,RP0 bcf STATUS,RP1 - movlw b'01000001' + movlw b'01000001' ; CLK = FOSC/8, select AN0, ADC on movwf ADCON0 - movlw b'10010000' + movlw b'10010000' ; enable Serial Port, 8bit, enable continues receive, disable address detection movwf RCSTA - movlw B'01011000' + movlw B'01011000' ; enabble Peripherial, INT and Port Change movwf INTCON - clrf PORTB - - bcf DTMF_PWRDWN - movlw DTMF_BUF - movwf DTMF_BUF_PTR - clrf DTMF_CS - clrf TMR1L - clrf TMR1H - movlw b'00110000' - movwf T1CON - - bcf TTX_SCL - bcf TTX_SDA - nop - bcf TTX_RESET ;reset TTX + call i2c_init clrf TMR0 - bsf INTCON,GIE clrf TMP - bsf TTX_RESET goto main ;; ------------------------------------- @@ -360,8 +259,8 @@ wait_loop uart_rx_byte btfsc RCSTA,FERR goto uart_rx_fe - movf RCREG,w ; TODO: move to input string - movwf TMP + movf RCREG,w ; TODO: check parity + movwf TMP ; TODO: move to input string return uart_rx_fe @@ -369,10 +268,7 @@ uart_rx_fe return ;; ------------------------------------- - include "math.inc" - - ;; ------------------------------------- - include "ttx.inc" + ;; include "math.inc" ;; ------------------------------------- include "i2c.inc" @@ -381,13 +277,13 @@ uart_rx_fe include "rtc.inc" ;; ------------------------------------- - include "temp.inc" + ;; include "temp.inc" ;; ------------------------------------- - include "adc.inc" + ;; include "adc.inc" ;; ------------------------------------- - include "solar.inc" + ;; include "solar.inc" ;; ------------------------------------- ;; MAINLOOP @@ -395,65 +291,6 @@ main ; sleep ; nop ;; -------------------- - ;; TTX Test - ;; movf TMP,w - ;; btfsc STATUS,Z - ;; goto main - - ;; movlw BUF - ;; movwf FSR - ;; movlw 0x50 - ;; call ttx_send - - ;; clrf TMP - ;; goto main - -;; xorlw .0 -;; btfss STATUS,Z -;; goto main_error - -;; movlw 'O' -;; movwf TXREG -;; movlw .1 -;; call wait_ms -;; movlw 'K' -;; movwf TXREG -;; movlw .1 -;; call wait_ms -;; movlw '\r' -;; movwf TXREG -;; movlw .1 -;; call wait_ms -;; movlw '\n' -;; movwf TXREG -;; movlw .1 -;; call wait_ms -;; goto main - -;; main_error -;; movlw 'E' -;; movwf TXREG -;; movlw .1 -;; call wait_ms -;; movlw 'R' -;; movwf TXREG -;; movlw .1 -;; call wait_ms -;; movlw 'R' -;; movwf TXREG -;; movlw .1 -;; call wait_ms -;; movlw '\r' -;; movwf TXREG -;; movlw .1 -;; call wait_ms -;; movlw '\n' -;; movwf TXREG -;; movlw .1 -;; call wait_ms -;; goto main - - ;; -------------------- ;; ADC Test ;; call adc_get_solar ;; call solar_calc_power @@ -526,61 +363,60 @@ main ;; goto main ;; -------------------- - ;; DTMF Test program + ;; RTC Test program movf TMP,f btfsc STATUS,Z goto main - movlw BUF - movwf FSR - swapf DTMF_BUF+3,w - andlw b'11110000' - call ttx_send + call rtc_get_time - movf DTMF_BUF,w - call dtmfSign + swapf RTC_TOD3,w + call digit movwf TXREG movlw .1 call wait_ms - movf DTMF_BUF+1,w - call dtmfSign + movf RTC_TOD3,w + call digit movwf TXREG movlw .1 call wait_ms - movf DTMF_BUF+2,w - call dtmfSign + swapf RTC_TOD2,w + call digit movwf TXREG movlw .1 call wait_ms - movf DTMF_BUF+3,w - call dtmfSign + movf RTC_TOD2,w + call digit movwf TXREG movlw .1 call wait_ms - movf DTMF_BUF+4,w - call dtmfSign + swapf RTC_TOD1,w + call digit movwf TXREG movlw .1 call wait_ms - movlw ' ' + movf RTC_TOD1,w + call digit movwf TXREG movlw .1 call wait_ms - movf DTMF_CS,f - btfsc STATUS,Z - movlw '!' - btfss STATUS,Z - movlw 'x' + swapf RTC_TOD0,w + call digit movwf TXREG movlw .1 call wait_ms + movf RTC_TOD0,w + call digit + movwf TXREG + movlw .1 + call wait_ms movlw '\r' movwf TXREG @@ -588,92 +424,11 @@ main call wait_ms movlw '\n' movwf TXREG - movlw .1 - call wait_ms - clrf TMP - movlw DTMF_BUF - movwf DTMF_BUF_PTR - clrf DTMF_CS - goto main ;; -------------------- - ;; RTC Test program - ;; movf TMP,f - ;; btfsc STATUS,Z - ;; goto main - - ;; call rtc_get_time - - ;; swapf RTC_TOD3,w - ;; andlw b'00001111' - ;; call digit - ;; movwf TXREG - ;; movlw .1 - ;; call wait_ms - - ;; movf RTC_TOD3,w - ;; andlw b'00001111' - ;; call digit - ;; movwf TXREG - ;; movlw .1 - ;; call wait_ms - - ;; swapf RTC_TOD2,w - ;; andlw b'00001111' - ;; call digit - ;; movwf TXREG - ;; movlw .1 - ;; call wait_ms - - ;; movf RTC_TOD2,w - ;; andlw b'00001111' - ;; call digit - ;; movwf TXREG - ;; movlw .1 - ;; call wait_ms - - ;; swapf RTC_TOD1,w - ;; andlw b'00001111' - ;; call digit - ;; movwf TXREG - ;; movlw .1 - ;; call wait_ms - - ;; movf RTC_TOD1,w - ;; andlw b'00001111' - ;; call digit - ;; movwf TXREG - ;; movlw .1 - ;; call wait_ms - - ;; swapf RTC_TOD0,w - ;; andlw b'00001111' - ;; call digit - ;; movwf TXREG - ;; movlw .1 - ;; call wait_ms - - ;; movf RTC_TOD0,w - ;; andlw b'00001111' - ;; call digit - ;; movwf TXREG - ;; movlw .1 - ;; call wait_ms - - ;; movlw '\r' - ;; movwf TXREG - ;; movlw .1 - ;; call wait_ms - ;; movlw '\n' - ;; movwf TXREG - - ;; clrf TMP - ;; goto main - - ;; -------------------- ;; Temp Test program ;; movf TMP,f ;; btfsc STATUS,Z @@ -681,14 +436,12 @@ main ;; call temp_read_value ;; swapf OWIRE_BYTE,w - ;; andlw b'00001111' ;; call digit ;; movwf TXREG ;; movlw .1 ;; call wait_ms ;; movf OWIRE_BYTE,w - ;; andlw b'00001111' ;; call digit ;; movwf TXREG ;; movlw .1 diff --git a/software/ihu/rtc.inc b/software/ihu/rtc.inc index 7dc4e1d..cb1dc3d 100644 --- a/software/ihu/rtc.inc +++ b/software/ihu/rtc.inc @@ -8,10 +8,10 @@ ;; ESC im Labor and realraum. ;; ;; Please visit the project hompage at sat.mur.at for further information. - ;; + ;; ;; ;; Copyright (C) 2011 Christian Pointner <equinox@mur.at> - ;; + ;; ;; This file is part of mur.sat. ;; ;; mur.sat is free software: you can redistribute it and/or modify @@ -45,8 +45,10 @@ RTC_REG_TCH EQU H'09' 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 - +;; RTC_INIT_TCH EQU b'10101010' ; trickle charger enabled with diode and 2kohm +RTC_INIT_TCH EQU b'10101001' ; trickle charger enabled with diode and 250ohm +;; RTC_INIT_TCH EQU b'00001100' ; trickle charger disabled + ;; ------------------------------------- rtc_init call i2c_start @@ -55,14 +57,14 @@ rtc_init call i2c_send_byte btfsc I2C_BYTE,0 goto rtc_error_ack - + movlw RTC_REG_STAT call i2c_send_byte btfsc I2C_BYTE,0 goto rtc_error_ack call i2c_restart - + movlw RTC_ADDR_R call i2c_send_byte btfsc I2C_BYTE,0 @@ -73,10 +75,10 @@ rtc_init btfsc I2C_BYTE,7 goto rtc_init_after_clock_fail - + call i2c_stop return - + rtc_init_after_clock_fail call i2c_restart @@ -84,7 +86,7 @@ rtc_init_after_clock_fail call i2c_send_byte btfsc I2C_BYTE,0 goto rtc_error_ack - + movlw RTC_REG_TOD0 call i2c_send_byte btfsc I2C_BYTE,0 @@ -99,7 +101,7 @@ rtc_init_clear goto rtc_error_ack decfsz RTC_BYTE_CNT,f goto rtc_init_clear - + movlw RTC_INIT_CTL call i2c_send_byte btfsc I2C_BYTE,0 @@ -128,14 +130,14 @@ rtc_get_time call i2c_send_byte btfsc I2C_BYTE,0 goto rtc_error_ack - + movlw RTC_REG_TOD0 call i2c_send_byte btfsc I2C_BYTE,0 goto rtc_error_ack call i2c_restart - + movlw RTC_ADDR_R call i2c_send_byte btfsc I2C_BYTE,0 @@ -153,7 +155,7 @@ rtc_get_time_loop call i2c_nack call i2c_stop return - + rtc_get_time_next incf FSR,f call i2c_ack diff --git a/software/ihu/tables.inc b/software/ihu/tables.inc index 1ce2beb..3e42a41 100644 --- a/software/ihu/tables.inc +++ b/software/ihu/tables.inc @@ -8,10 +8,10 @@ ;; ESC im Labor and realraum. ;; ;; Please visit the project hompage at sat.mur.at for further information. - ;; + ;; ;; ;; Copyright (C) 2011 Christian Pointner <equinox@mur.at> - ;; + ;; ;; This file is part of mur.sat. ;; ;; mur.sat is free software: you can redistribute it and/or modify @@ -31,6 +31,7 @@ ;; ------------------------------------- ;; digit digit + andlw b'00001111' addwf PCL,f retlw '0' retlw '1' @@ -49,25 +50,6 @@ digit retlw 'E' retlw 'F' -dtmfSign - addwf PCL,f - retlw 'D' - retlw '1' - retlw '2' - retlw '3' - retlw '4' - retlw '5' - retlw '6' - retlw '7' - retlw '8' - retlw '9' - retlw '0' - retlw '*' - retlw '#' - retlw 'A' - retlw 'B' - retlw 'C' - mul10 addwf PCL,f retlw .0 @@ -103,7 +85,7 @@ daysL retlw .18 retlw .49 retlw .79 - + daysH addwf PCL,f retlw .0 diff --git a/software/ihu/ttx.inc b/software/ihu/ttx.inc deleted file mode 100644 index 8fa1479..0000000 --- a/software/ihu/ttx.inc +++ /dev/null @@ -1,230 +0,0 @@ - ;; - ;; mur.sat - ;; - ;; Somewhen in the year 2012, 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 <equinox@mur.at> - ;; - ;; 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 <http://www.gnu.org/licenses/>. - ;; - - ;; ------------------------------------- -ttx_send_byte - bsf STATUS,RP0 - bcf TTX_SDA - bcf STATUS,RP0 - movwf TTX_BYTE - xorwf TTX_CSUM,f - movlw .8 - movwf TTX_BIT_CNT -ttx_send_next_bit - btfsc TTX_BYTE,7 - bsf TTX_SDA - btfss TTX_BYTE,7 - bcf TTX_SDA - bsf TTX_SCL - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - bcf TTX_SCL - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - rlf TTX_BYTE,f - decfsz TTX_BIT_CNT,f - goto ttx_send_next_bit - bsf STATUS,RP0 - bsf TTX_SDA - bcf STATUS,RP0 - return - - ;; ------------------------------------- -ttx_recv_byte - movlw .8 - movwf TTX_BIT_CNT -ttx_recv_next_bit - bsf TTX_SCL - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - bcf TTX_SCL - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - rlf TTX_BYTE,f - btfsc TTX_SDA - bsf TTX_BYTE,0 - btfss TTX_SDA - bcf TTX_BYTE,0 - decfsz TTX_BIT_CNT,f - goto ttx_recv_next_bit - return - - ;; ------------------------------------- -ttx_break - movlw .13 - movwf TTX_BIT_CNT -ttx_wait_octet - decfsz TTX_BIT_CNT,f - goto ttx_wait_octet - return - - ;; ------------------------------------- -ttx_send_frame - movwf TTX_BYTE - andlw b'00001111' - movwf TTX_BYTE_CNT - bsf TTX_SCL - movlw .3 - bcf TTX_SCL - call wait_ms - - clrf TTX_CSUM - movf TTX_BYTE,w - call ttx_send_byte - - movf TTX_BYTE_CNT,f - btfsc STATUS,Z - goto ttx_get_csum - -ttx_next_byte - call ttx_break - movf INDF,w - call ttx_send_byte - - incf FSR,f - decfsz TTX_BYTE_CNT,f - goto ttx_next_byte - -ttx_get_csum - return - - call ttx_break - call ttx_recv_byte - movf TTX_BYTE,w - xorwf TTX_CSUM,w - btfss STATUS,Z - goto ttx_csum_error - retlw .0 - -ttx_csum_error - retlw .1 - - ;; ------------------------------------- -ttx_send - call ttx_send_frame - return - - movwf TTX_BYTE - movwf TXREG - call ttx_break - - bsf TTX_SDA - bsf STATUS,RP0 - bcf TTX_SDA - bcf STATUS,RP0 - btfss TTX_BYTE,0 - bcf TTX_SDA - bsf TTX_SCL - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - bcf TTX_SCL - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - nop - bsf STATUS,RP0 - bsf TTX_SDA - bcf STATUS,RP0 - movf TTX_BYTE,w - return - ;; ------------------------------------- |