; 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)
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
;----------------------------------------
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
; 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
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
goto wait_for_i2c_interrupt_loop
bcf PIR1,SSPIF,0 ; clear interrupt bit
+
+ debug 'I'
+ debughf SSPSTAT
+ debughf SSPCON1
+ debughf SSPCON2
+
return
;***************************************************************************