From: ian Date: Mon, 14 Feb 2005 02:32:06 +0000 (+0000) Subject: master test for I2C setup inverted. also new in-hex debugging stuff; who knows... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=e5c006c4b6f1af09cf632f75880d9a9ce1dd5e10;p=trains.git master test for I2C setup inverted. also new in-hex debugging stuff; who knows if it will work --- diff --git a/cebpic/i2c-test.asm b/cebpic/i2c-test.asm index 513265d..86f54c8 100644 --- a/cebpic/i2c-test.asm +++ b/cebpic/i2c-test.asm @@ -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 ;***************************************************************************