diff options
author | Christian Pointner <equinox@mur.at> | 2011-07-29 00:31:45 +0000 |
---|---|---|
committer | Christian Pointner <equinox@mur.at> | 2011-07-29 00:31:45 +0000 |
commit | 113fbb6190de6413c4d6c0cb9798ff1009b8046a (patch) | |
tree | ea648dba195178bd978a7d20fd58918109fa1b27 | |
parent | improved ihu <-> ttx code (diff) |
first working I2C code
git-svn-id: https://svn.spreadspace.org/mur.sat@68 7de4ea59-55d0-425e-a1af-a3118ea81d4c
-rw-r--r-- | software/ihu/ihu.asm | 183 |
1 files changed, 161 insertions, 22 deletions
diff --git a/software/ihu/ihu.asm b/software/ihu/ihu.asm index d9bdc69..88fc5c0 100644 --- a/software/ihu/ihu.asm +++ b/software/ihu/ihu.asm @@ -38,8 +38,37 @@ ;; ------------------------------------- ;; DEFINES ;; constants +RTC_ADDR_W EQU b'11010000' +RTC_ADDR_R EQU b'11010001' +I2C_SPEED EQU .19 - ;; I/O Pins + ;; I/O Pins +;; PortA +SOLAR_C0 EQU 0 +SOLAR_C1 EQU 1 +SOLAR_C2 EQU 2 +SOLAR_C3 EQU 3 +OWIRE EQU 4 +SOLAR_C4 EQU 5 +;; PortB +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 +ICOM_TX EQU 6 +ICOM_RX EQU 7 +;; PortD DTMF_D0 EQU 0 DTMF_D1 EQU 1 DTMF_D2 EQU 2 @@ -48,6 +77,10 @@ DTMF_PWRDWN EQU 4 TTX_RESET EQU 5 TTX_SCL EQU 6 TTX_SDA EQU 7 +;; PortE +SOLAR_C5 EQU 0 +SOLAR_C6 EQU 1 +SOLAR_C7 EQU 2 ;; variables ;; page 0 only @@ -116,15 +149,25 @@ init bsf STATUS,RP1 movlw b'00000000' movwf BAUDCTL - + movlw b'00000111' + movwf ANSELH + ;; bank 1 bsf STATUS,RP0 bcf STATUS,RP1 movlw b'11000001' + movwf WPUB + movlw b'11000000' + movwf IOCB + movlw b'01000001' movwf OPTION_REG clrf PSTRCON movlw b'00010000' movwf OSCCON + movlw b'11001111' + movwf TRISB + movlw b'11011100' + movwf TRISC movlw b'10001111' movwf TRISD movlw b'00100100' @@ -132,6 +175,9 @@ init movlw .12 movwf SPBRG clrf SPBRGH + movlw I2C_SPEED + movwf SSPADD + bsf SSPSTAT,SMP movlw b'00100000' movwf PIE1 clrf PIE2 @@ -141,6 +187,8 @@ init bcf STATUS,RP1 movlw b'10010000' movwf RCSTA + movlw b'00101000' + movwf SSPCON movlw B'01000000' movwf INTCON @@ -294,7 +342,116 @@ ttx_csum_error movlw 'E' movwf TXREG return + + ;; ------------------------------------- +i2c_start + bcf PIR1,SSPIF + bsf STATUS,RP0 + bsf SSPCON2,SEN + bcf STATUS,RP0 + goto i2c_wait + + ;; ------------------ +i2c_restart + bcf PIR1,SSPIF + bsf STATUS,RP0 + bsf SSPCON2,RSEN + bcf STATUS,RP0 + goto i2c_wait + ;; ------------------ +i2c_stop + bcf PIR1,SSPIF + bsf STATUS,RP0 + bsf SSPCON2,PEN + bcf STATUS,RP0 + goto i2c_wait + + ;; ------------------ +i2c_send_byte + bcf PIR1,SSPIF + movwf SSPBUF + goto i2c_wait + + ;; ------------------ +i2c_recv_byte + bcf PIR1,SSPIF + bsf STATUS,RP0 + bsf SSPCON2,RCEN + bcf STATUS,RP0 + goto i2c_wait + + ;; ------------------ +i2c_ack + bcf PIR1,SSPIF + bsf STATUS,RP0 + bcf SSPCON2,ACKDT + bsf SSPCON2,ACKEN + bcf STATUS,RP0 + goto i2c_wait + + ;; ------------------ +i2c_nack + bcf PIR1,SSPIF + bsf STATUS,RP0 + bsf SSPCON2,ACKDT + bsf SSPCON2,ACKEN + 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 + goto rtc_init_error_ack + bcf STATUS,RP0 + + movlw H'0E' + call i2c_send_byte + bsf STATUS,RP0 + btfsc SSPCON2,ACKSTAT + 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 + goto rtc_init_error_ack + bcf STATUS,RP0 + + call i2c_recv_byte + movf SSPBUF,w + movwf TXREG + call i2c_ack + + call i2c_recv_byte + movf SSPBUF,w + movwf TXREG + call i2c_nack + + call i2c_stop + movlw '.' + movwf TXREG + return + +rtc_init_error_ack + bcf STATUS,RP0 + call i2c_stop + movlw 'E' + movwf TXREG + return + ;; ------------------------------------- ;; MAINLOOP main @@ -302,26 +459,8 @@ main btfsc STATUS,Z goto main - movlw 'M' - movwf BUF - movlw 'U' - movwf BUF + 1 - movlw 'R' - movwf BUF + 2 - movlw '.' - movwf BUF + 3 - movlw 'S' - movwf BUF + 4 - movlw 'A' - movwf BUF + 5 - movlw 'T' - movwf BUF + 6 - - movlw BUF - movwf FSR - movlw b'11110111' - call ttx_send_frame - + call rtc_init + clrf TMP goto main |