chiark / gitweb /
master test for I2C setup inverted. also new in-hex debugging stuff; who knows...
authorian <ian>
Mon, 14 Feb 2005 02:32:06 +0000 (02:32 +0000)
committerian <ian>
Mon, 14 Feb 2005 02:32:06 +0000 (02:32 +0000)
cebpic/i2c-test.asm

index 513265d0ed4e33fd9b55869faedc453971083686..86f54c810a48681f6d40378cff387ae7f28bb9ce 100644 (file)
@@ -13,7 +13,8 @@
 ; In subroutines, unless otherwise stated, W and S may have any
 ; value on entry and will be undefined on exit.
 ;
-; labels ending _if_... and _endif_... are used for if ... then [... else ...]
+; labels ending _if[not_... and _endif_... are used for
+;    if ... then [... else ...]
 ; labels ending _loop are for loops
 ; labels ending _isr are at the start of interrupt service routines
 ;                      (which must end with retfie)
@@ -98,6 +99,54 @@ debug macro debugvalue
        endm
        endif
 
+;----------------------------------------
+; debughf(REGISTER)
+;      reads REGISTER once and writes it to the serial port in hex
+;      for conditions etc. see "debug", above
+;              Before          After
+;      W       any             undefined
+;      S       any             undefined
+ ifdef SLOW_VERSION
+DEBUGHF_VALUE  equ     0x040   ; getting on towards end of access bank
+                               ; FIXME if all of program used udata that
+                               ; would be very nice
+
+debughf macro register
+       movff   register, DEBUGHF_VALUE
+       call    debughf_subroutine
+       endm
+
+debughf_subroutine
+       call    debughf_digit
+       swapf   DEBUGHF_VALUE,1,0
+       call    debughf_digit
+       return
+
+;--------------------
+debughf_digit
+;      transmits bottom nybble of DEBUGHF_VALUE in hex
+;      through serial port, as above
+;                      Before          After
+;      W               any             undefined
+; DEBUGHF_VALUE                xxxxDDDD        preserved
+
+       movf    DEBUGHF_VALUE,0,0
+       andlw   0x0f
+       sublw   10
+       sublw   0
+       bn      debughf_digit_ifnot_ge10
+       addlw   'a'-'0'
+debughf_digit_ifnot_ge10
+       addlw   '0'+10
+       goto    polling_serial_transmit
+
+ else
+debughf macro register
+       endm
+ endif
+
+
+       
 ;****************************************************************************
 ; PORTMANTEAU CODE
 ; which contains lists of checks and calls to function-specific
@@ -123,6 +172,11 @@ vector_reset
 
 ;----------------------------------------
 main
+       debug   'J'
+       debughf SSPSTAT
+       debughf SSPCON1
+       debughf SSPCON2
+
        banksel I2C_CTRL                ; ser BSR=i2c BSR (4)
        btfsc   I2C_CTRL,I2C_CTRL_MASTER,1 ; check =master?, if so
        goto    master_main             ; goto master main routine
@@ -254,6 +308,8 @@ polling_serial_transmit
 ;      serial port hardware must be suitably initialised
 ;      serial port transmit interrupts must be disabled
 ;      will spin until the byte is transmitted
+;              Before          After
+;      W       byte to xmit    preserved
 
        movwf   TXREG,0         ; move contents of W (i.e. debugvalue)
                                ;       to TXREG for transmission
@@ -329,7 +385,7 @@ i2c_setup
        bcf     IPR1,SSPIP,0    ; make interrupt low priority
 
 ; are we master or slave ?
-       btfss   I2C_CTRL,I2C_CTRL_MASTER,1      ; test whether PIC is master
+       btfsc   I2C_CTRL,I2C_CTRL_MASTER,1      ; test whether PIC is master
        goto    i2c_setup_if_master
        goto    i2c_setup_if_slave
 
@@ -391,6 +447,12 @@ wait_for_i2c_interrupt_loop
        goto    wait_for_i2c_interrupt_loop
 
        bcf     PIR1,SSPIF,0    ; clear interrupt bit
+
+       debug   'I'
+       debughf SSPSTAT
+       debughf SSPCON1
+       debughf SSPCON2
+       
        return
 
 ;***************************************************************************