diff options
author | Christian Pointner <equinox@mur.at> | 2013-06-28 02:11:02 +0000 |
---|---|---|
committer | Christian Pointner <equinox@mur.at> | 2013-06-28 02:11:02 +0000 |
commit | 492d2a620431ae8fb63aa8fc3a9a621464dcf6b5 (patch) | |
tree | 9c1c8fd31d9a117815989209c7bc0625f0776ece /software/ihu/ihu.asm | |
parent | whitespace cleanup (diff) |
ihu and rtc work now
git-svn-id: https://svn.spreadspace.org/mur.sat@794 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software/ihu/ihu.asm')
-rw-r--r-- | software/ihu/ihu.asm | 429 |
1 files changed, 91 insertions, 338 deletions
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 |