Searching \ for '[PIC] rangefinder via i2c in assembler' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=rang
Search entire site for: 'rangefinder via i2c in assembler'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] rangefinder via i2c in assembler'
2005\03\02@224622 by Ian Smith-Heisters

flavicon
face
Hello everyone,

I'm having a problem figuring out how to connect with a PIC 18F452's i2c
to an SRF08 ultrasonic rangefinder. The SRF08's default address is 0xE0
(write enabled), the command register is 0x00, and writing to the
command register with 0x50 should start ranging in inches. You can see
more details on the SRF08 here:
http://www.robot-electronics.co.uk/htm/srf08tech.shtml

I've been going off these resources:
www.robot-electronics.co.uk/htm/using_the_i2c_bus.htm
http://www.piclist.com/techref/microchip/w-r_i2c.gif

After loading the attached code into the PIC and powering up, the SRF08
blinks one long blink, indicating that its address is set to 0xE0. The
PIC then prints that it has reached the first two debug statements and
then it halts and nothing happens.

I've tried rewriting it with a few alternatives, specifically with
stopping and starting instead of just restarting between the read
command and setting the PIC to receive. I've also tried lengthening the
delay since I think my delay sub is slightly... inaccurate. I've also
tried rewiring everything and using a different SRF08. None of this has
yielded anything (of course, or I wouldn't be here).

If you could please look at the code and just whack me upside the
cranium with anything obvious you notice, I'll be forever grateful.
There's very little information on the web about doing this with
assembler, but I'll put anything I figure out on my tutorials page at
http://www.0x09.com/Marlboro/physcomp . It's hard for me to tell if this
is my ineptitude with i2c, or my ineptitude with the SRF08, both of
which this is my first stab at.

Thank you so much,
Ian

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; srf08.asm
;        Controls an array of 8 SRF08 ultrasonic rangefinders
;
;        by Ian Smith-Heisters
;                February 26th, 2005:        Started
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

       title "SRF08 Control"
       List p=18f452,f=inhx32
       #include <p18f452.inc>

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Initialization
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;The config aliases are already defined in the 18f452 header file.
       __CONFIG    _CONFIG1H, _OSCS_ON_1H & _XT_OSC_1H ; External Clock on
OSC1 & OSC2
       __CONFIG    _CONFIG2L, _BOR_ON_2L & _BORV_20_2L & _PWRT_OFF_2L ; Brown
out reset on at 2.0V, no power-up timer
       __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H ; watchdog off,
postscaler count to 128
       __CONFIG    _CONFIG3H, _CCP2MX_ON_3H ; CCP2 pin Mux enabled. What is this?
       __CONFIG    _CONFIG4L, _STVR_ON_4L & _LVP_ON_4L & _DEBUG_OFF_4L ; Stack
under/overflow reset on, LVP on, debug off
       __CONFIG    _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L &
_CP3_OFF_5L ; all protection off
       __CONFIG    _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
       __CONFIG    _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L &
_WRT3_OFF_6L
       __CONFIG    _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
       __CONFIG    _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L &
_EBTR3_OFF_7L
       __CONFIG    _CONFIG7H, _EBTRB_OFF_7H

       org        0x0000

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Variable Definitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Define Constants
COUNT1                equ        0x00
COUNT2                equ        0x01
COUNT3                equ        0x02
DELIMETER        equ 0x03
EOL                        equ 0x04

#define startb        SSPCON2, SEN
#define stopb        SSPCON2, PEN

; Define variables
char                equ 0x05
NumH                equ 0x06
NumL                equ 0x07
TenK                equ 0x08
Thou                equ 0x09
Hund                equ 0x0A
Tens                equ 0x0B
Ones                equ 0x0C

; Set port D to all output
       clrf        TRISD

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Macro Definitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

mov                MACRO litval, file
               movlw        litval
               movwf        file
       endm

ENCDA MACRO x
               movlw        0x30                        ; convert to 0-9 in ASCII
               addwf        x, F
       endm

_puts MACRO S                                        ; output a NUL-terminated inline string
               call putstrpc
               dw S
       endm

; initialize variables and constants
       mov                ' ', DELIMETER
       mov                '\n', EOL

; call initialization subs
       call        UART_Init
       call        I2C_Init
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Main loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Main
               mov                'a', char

       ;; Start ranging
               bsf                SSPCON2, SEN        ; start sequence
               btfsc        SSPCON2, SEN
               bra                $-2

               mov                0xE0, SSPBUF        ; slave's address, write bit set
               btfsc        SSPSTAT, R_W
               bra                $-2

               mov                0x00, SSPBUF        ; writing to command register
               btfsc        SSPSTAT, R_W
               bra                $-2

               mov                0x50, SSPBUF        ; start ranging in inches
               btfsc        SSPSTAT, R_W
               bra                $-2

               bsf                SSPCON2, PEN        ; stop bit
               btfsc        SSPCON2, PEN
               bra                $-2

               call        del_5msec

               _puts        "reached debug point 1\n\r"

       ;; Read results
               bsf                SSPCON2, SEN        ; start sequence
               btfsc        SSPCON2, SEN
               bra                $-2

               mov                0xE0, SSPBUF        ; slave's address
               btfsc        SSPSTAT, R_W
               bra                $-2

               mov                0x02, SSPBUF        ; 1st reading location
               btfsc        SSPSTAT, R_W
               bra                $-2

               bsf                SSPCON2, RSEN        ; repeated start sequence
               btfsc        SSPCON2, RSEN
               bra                $-2

               mov                0xE1, SSPBUF        ; slave's address with read set
               btfsc        SSPSTAT, R_W
               bra                $-2

               _puts        "reached debug 2\n\r\0"

               bsf                SSPCON2, RCEN        ; enable reception

               btfsc        SSPSTAT, RCEN        ; byte received
               bra                $-2

               _puts        "reached debug 3\n\r\0"

               bsf                SSPCON2, ACKDT        ; output acknowledgment
               bsf                SSPCON2, ACKEN
               btfsc        SSPCON2, ACKEN        ; NACK finished
               bra                $-2

               bsf                SSPCON2, PEN        ; stop bit
               btfsc        SSPCON2, PEN
               bra                $-2

               _puts        "reached debug 4\n\r\0"

               call        I2C_Print

               goto        Main

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Subroutine Definitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
               #include <UART.inc>

;; ----- I2C
--------------------------------------------------------------------

I2C_Init
               mov                b'00011000', TRISC                ; SDA and SCL to I2C
               mov                b'00101000', SSPCON1        ; I2C on, set to master
               mov                b'10000000', SSPSTAT        ; slew disabled: standard speed control
               mov                0x28, SSPADD                        ; 100kHz @ 4MHz
       return

I2C_Print
               _puts        "sensor value: \0"
               movff        SSPBUF, Ones
               ENCDA        Ones
               movff        Ones, W
               call        UART_Put
               _puts        "\n\r"
       return

;; ----- Delays
-----------------------------------------------------------------
;; A 1 millisecond delay @ 4MHz
del_1msec
               mov                d'16', COUNT2
               mov                d'250', COUNT1
               decfsz        COUNT1, F
               bra                $-2
               decfsz        COUNT2, F
               bra                $-4
       return

;; A 5 msec (+~ .5 msec) delay based on del_1msec
del_5msec
               mov                d'5', COUNT3
               call        del_1msec
               decfsz        COUNT3, F
               bra                $-2
       return

;; ----- Strings
------------------------------------------------------------------
;; print NUL-terminated string at TBLPTR
putstrtail:
loop:          tblrd *+
               movf TABLAT,w
               bz done
           rcall UART_Put
           bra loop
done:return

;; print NUL-terminated string at PC
putstrpc:
               movff TOSU,TBLPTRU
               movff TOSH,TBLPTRH
               movff TOSL,TBLPTRL
putstr2:rcall putstrtail
       ; adjust return address to after end of string
fixuppc:btfsc TBLPTRL,0                ; is ptr odd?
               tblrd *+                        ; yes, bump it by one
               movf TBLPTRU,w                ; copy to return PC
               movwf TOSU                        ; ** cannot use movff **
               movf TBLPTRH,w
               movwf TOSH
               movf TBLPTRL,w
               movwf TOSL
       return

       end

2005\03\03@040154 by Jan-Erik Soderholm

face picon face
Hi.
I'm not any I2C guru, but I'd be glad to make
a few notes about your code. Don't know if it solves
your problem, but it might help maybe... :-)

Regards,
Jan-Erik.

Of Ian Smith-Heisters wrote :

> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ; Variable Definitions
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Using EQU to "define" your variables does work (if used
carefully) but might not be the prefered method, depending
on who you ask... :-)

> ; Define Constants
> COUNT1                equ        0x00
> COUNT2                equ        0x01



> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ; Macro Definitions
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Be *very* carefully *NOT* to use these macros
as the first "intruction" after a BTFSx (or any other "skip"
instruction) !!!
The same with using "GOTO $..." constructs that jumps
over one of these macros...

> mov                MACRO litval, file
>                movlw        litval
>                movwf        file
>        endm
>


Where is the code to handle braches over the interrupt vector ?


{Quote hidden}

Do yourself a *BIG* favour and replace *ALL* addressing
using "$" with proper labels !!


{Quote hidden}

Don't you want this "BRA" to jump to the "CALL" instruction ??
It does not, AFAIK. If I'm not wrong, it jumps the the "DECFSZ"
instruction instead. As I said before, use labels !!




2005\03\03@052646 by Jinx

face picon face
> I'm having a problem figuring out how to connect with a PIC 18F452's i2c

Is this any help ?

http://www.piclist.com/techref/microchip/w-r_i2c.gif

2005\03\03@083430 by Ian Smith-Heisters

flavicon
face
Jinx wrote:
>>I'm having a problem figuring out how to connect with a PIC 18F452's i2c
>
>
> Is this any help ?
>
> www.piclist.com/techref/microchip/w-r_i2c.gif
>

That's exactly what I was already using as a reference... Thanks though.

-Ian

--
http://www.0x09.com

2005\03\03@084943 by Ian Smith-Heisters

flavicon
face
Jan-Erik Soderholm wrote:
> Hi.
> I'm not any I2C guru, but I'd be glad to make
> a few notes about your code. Don't know if it solves
> your problem, but it might help maybe... :-)

Thanks for the tips. What should I use besides equ to set variables,
#define? Not using BTFSx before the macros is a *VERY* good tip that
makes sense when I think about it.

There is no code that handles branches over the interrupt vector....
because I don't know what that is.. heh heh. <insert sheepish grin here>
Is that necessary for a project like this, or 'just' good programming
practice?

Soo... bra $-2 would jump one line back as opposed to 2? The datasheet
says bra changes the PC by 2+2n, so bra $-2 would pull it back 2 lines,
no? Maybe thinking of this in terms of 'lines' is not right? Either way,
I'll label things out the wazoo and try it again. Is there a difference
between using bra and goto for going to labels? The datasheet says
they're both "unconditional branches", what's the difference?

Anyhow, thanks for your help, I'll spiff things up and see how it goes!

-Ian

{Quote hidden}

--
http://www.0x09.com

2005\03\03@101818 by Jan-Erik Soderholm

face picon face
Ian Smith-Heisters wrote :

> Thanks for the tips. What should I use besides equ to set variables,
> #define?

Well, as I said, it depends on who you ask. :-)
Some on the piclist would say that you should
learn to write relocatable code, use RES to allocate RAM
vaiables and start using the linker (MPLINK). Now, you don't
*have* to do that, but it's sure nice and produces
clean and re-usable code.

Now, this doesn't say that EQU dosn't work, but it's a bit
of Yesterdays way of coding...

> Not using BTFSx before the macros is a *VERY* good tip that
> makes sense when I think about it.

Yep, you would skip right into the middle of the macro, right ?
Not *over* it. The skip is executed after the macro name
have been replaced with the actual code, of course.

>
> There is no code that handles branches over the interrupt vector....
> because I don't know what that is.. heh heh. <insert sheepish
> grin here>

Well, if you are 100% sure that no interrupt will ever trigger,
I'd guess that it's OK anyway. But it's usualy part of any
general startup code to have something there. You could look
at just about any 18F code example...

> Is that necessary for a project like this,

Depends on your definition of "necessary"...

> or 'just' good programming practice?

Yes.

> Soo... bra $-2 would jump one line back as opposed to 2?

$-2 jumps two *BYTES* back in program memery.
Each (or *most* actualy, which makes things worse) instructions
are one 16-bit *WORD*, or 2 bytes (some are 2 words / 4 bytes).

> The datasheet says bra changes the PC by 2+2n, so bra $-2
> would pull it back 2 lines, no?

Just uise lables and you don't have to bother...

> Maybe thinking of this in terms of 'lines' is not right?

Note that one "line" of code, could be 2 or 4 bytes in program memory.

> Either way,
> I'll label things out the wazoo and try it again. Is there a
> difference
> between using bra and goto for going to labels? The datasheet says
> they're both "unconditional branches", what's the difference?

Goto can "jump" longer. BRA is faster.
You *have* read the data sheet, right ?

> Anyhow, thanks for your help, I'll spiff things up and see
> how it goes!

Yes, I'm not saying that these things will cure your problem,
but having cleaner code makes the debugging easier, in
particular since you've asked *us* to read it :-)

Regards,
Jan-Erik.



2005\03\03@104051 by Jan-Erik Soderholm

face picon face
Hi again...

For better descriptions of the instruction set (that in
the data sheet), download Section 31 of the PIC18
Reference Manual :

http://ww1.microchip.com/downloads/en/DeviceDoc/39531.pdf

Most instructions have 2 to 4 clear code examples...

Enjoy ! :-)

Jan-Erik.



2005\03\04@042159 by Lee Jones

flavicon
face
> Soo... bra $-2 would jump one line back as opposed to 2?

Depends.  When MPASM is set for 12-bit or 14-bit core (16F) parts,
$-2 goes back 2 instructions.

When MPASM is set for enhanced 16-bit core (18 family) parts, $-2
goes back 2 _bytes_.  This is either 1 or 1/2 instruction since
most instructions are 2-bytes long but a few are 4-bytes long.

> The datasheet says bra changes the PC by 2+2n, so bra $-2 would
> pull it back 2 lines, no?

Again, depends on the processor you have selected in MPASM.  And
it depends on what is on the "line" -- one 18-series line could
translate into 2-bytes, 4-bytes, or (if it's a macro) many bytes.

You are confusing the datasheet description of the bit meanings
inside the PIC CPU and the interpretation of symbols in MPASM.  The
18-series PIC hardware, as with other PIC familes, treat offsets
and absolute locations in terms of words.

MPASM, on the other hand, treats operand values in terms of words
for 12-bit and 14-bit parts but treats operand values in terms of
bytes for 16-bit parts.  MPASM has to convert all those byte values
into words when building the instruction bit patterns.


> Is there a difference between using bra and goto for going to
> labels? The datasheet says they're both "unconditional branches",
> what's the difference?

On 18-series parts, BRA <label> is a single-word instruction with
the target label having to be within 1024 words (either direction).
GOTO <label> is a double-word instruction where the target label
can be located anywhere in program memory.

                                               Lee Jones

2005\03\04@055844 by Russell McMahon

face
flavicon
face
>> Soo... bra $-2 would jump one line back as opposed to 2?

> Depends.  When MPASM is set for 12-bit or 14-bit core (16F) parts,
> $-2 goes back 2 instructions.

Use the tools, Jim.

The key thing is to let the assembler handle the detail
UNLESS
   you are an expert and know all the ins and outs
AND
   you need to do things at such a raw level
OR
   you have a good reason for doing it (eg fun).

There are so many traps at the very bottom level that using a few
basic tools (such as an assembler and labels) to get a tiny bit above
pure machine code makes good sense. You have (I'm sure ;-) ) better
things to spend your time on. It's excellent to want to understand
what goes on at the bottom most level, but you probably want to do
that on long wet winter evenings with a cup of coffee (or whatever)
when you have no project actually needing doing. [Lest you may think I
speak without experience :-) - I did a masters thesis project long
long long ago, hand coding without an assembler. You get to know an
awful lot about the hardware, but you wish you didn't have to :-) ].



       RM



2005\03\04@092535 by Ian Smith-Heisters

flavicon
face
Jan-Erik Soderholm wrote:

> Now, this doesn't say that EQU dosn't work, but it's a bit
> of Yesterdays way of coding...
>

So what I've tried now is to just use a cblock. This is better, but
since I'm not looking for relocatabitility, is it necessary to go
further? If so, can you point me towards a resource? Google has not been
helpful in finding PIC18 asm tutorials/howtos.


> Well, if you are 100% sure that no interrupt will ever trigger,
> I'd guess that it's OK anyway. But it's usualy part of any
> general startup code to have something there. You could look
> at just about any 18F code example...
>

Again, I haven't found much. I did find this:
www.acm.uiuc.edu/sigarch/projects/pinball/code/pic/controlboard.asm
Since I'm not really using the interrupt for triggering things yet, I
just put "retfie 0" in Interrupt1 and Interrup2, is this an ok thing to
do? (See the new code below).

>
> Goto can "jump" longer. BRA is faster.
> You *have* read the data sheet, right ?
>

Reading and understanding fully are *totally* different things.

>
> Yes, I'm not saying that these things will cure your problem,
> but having cleaner code makes the debugging easier, in
> particular since you've asked *us* to read it :-)
>

So now I've got some code that uses lots of labels, subroutines, macros,
and has interrupt vectors. It still doesn't work, but at least I know
it's getting to the main loop, something that took me a while ;) I
thought I might just ask you if I'm on the right track. I have found
some new resources for the I2C, so I'll exhaust those before I ask you
to help me again with that.

Thanks again, one-hundred times.

-Ian

Is this clearer? Am I handling the interrupt vectors correctly, given
that I'm not really /using/ them?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; srf08.asm
;        Controls an array of 8 SRF08 ultrasonic rangefinders
;
;        by Ian Smith-Heisters
;                February 26th, 2005:        Started
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

       title "SRF08 Control"
       List p=18f452,f=inhx32
       #include <p18f452.inc>

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Configuration

;The config aliases are already defined in the 18f452 header file.
       __CONFIG    _CONFIG1H, _OSCS_ON_1H & _XT_OSC_1H ; External Clock on
OSC1 & OSC2
       __CONFIG    _CONFIG2L, _BOR_ON_2L & _BORV_20_2L & _PWRT_OFF_2L ; Brown
out reset on at 2.0V, no power-up timer
       __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H ; watchdog off,
postscaler count to 128
       __CONFIG    _CONFIG3H, _CCP2MX_ON_3H ; CCP2 pin Mux enabled. What is this?
       __CONFIG    _CONFIG4L, _STVR_ON_4L & _LVP_ON_4L & _DEBUG_OFF_4L ; Stack
under/overflow reset on, LVP on, debug off
       __CONFIG    _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L &
_CP3_OFF_5L ; all protection off
       __CONFIG    _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
       __CONFIG    _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L &
_WRT3_OFF_6L
       __CONFIG    _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
       __CONFIG    _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L &
_EBTR3_OFF_7L
       __CONFIG    _CONFIG7H, _EBTRB_OFF_7H

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Variable Definitions

; Define Constants
#define DELIMETER        ' '
#define EOL                        '\n'

; Define variables
       cblock 0x000
               count1                ; count variables. Useful for loops etc.
               count2
               count3
               char                ; a holder for a single character
               NumH                ; digit variables for sending 10 bit hex
               NumL                ;                numbers as decimal
               TenK
               Thou
               Hund
               Tens
               Ones
       endc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Macro Definitions

mov                MACRO litval, file                ; move a literal directly to a register
               movlw        litval
               movwf        file
       endm

_encda MACRO x                                        ; encode in ASCII
               movlw        0x30
               addwf        x, F
       endm

_puts MACRO s                                        ; output a NUL-terminated inline string
               call        putstrpc
               dw                s
       endm

_i2c_write MACRO x                                ; write x on the I2C bus
               movlw        x
               call        I2C_WriteW
       endm

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Vectors

       org        0x0000                                        ; reset vector

Start
       goto        Init

       org                0x0008                                ; high priority interrupt vector
Interrupt1
       goto        HighInterrupt

       org                0x0018                                ; low priority interrupt vector
Interrupt2
       goto        LowInterrupt

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Initialize

Init
; Set port D to all output
       clrf        TRISD

; call initialization subs
       call        UART_Init
       call        I2C_Init

       goto        Main

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Main loop

Main
               mov                        'a', char
               _puts                "beginning...\n\r\0"
       ;; Start ranging
               call                I2C_Start
               _i2c_write        0xE0                ; slave's address
               _i2c_write        0x00                ; command register
               _i2c_write        0x50                ; start ranging in inches
               call                I2C_Stop
               call                del_5msec

               _puts                "reached debug point 1\n\r"

       ;; Read results
               call                I2C_Start
               _i2c_write        0xE0                ; slave's address
               _i2c_write        0x02                ; first read address
               call                I2C_Restart
               _i2c_write        0xE1                ; slave's read address

               _puts                "reached debug 2\n\r\0"

               call                I2C_Receive

               _puts                "reached debug 3\n\r\0"

               call                I2C_Ack
               call                I2C_Stop

               _puts                "reached debug 4\n\r\0"

               call                I2C_Print

               goto        Main

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Interrupt Handling

;; High Interrupt
HighInterrupt
       _puts        "High priority interrupt triggered.\n\r\0"
       retfie        0
       goto        Start
;; Low Interrupt
LowInterrupt
       _puts        "Low priority interrupt triggered.\n\r\0"
       retfie        0
       goto        Start        ; I don't think these need to be here, but better safe than
sorry

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Subroutine Definitions
               #include <UART.inc>

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  I2C

;; Initialize the PIC I2C
I2C_Init
               mov                b'00011000', TRISC                ; SDA and SCL to I2C
               mov                b'00101000', SSPCON1        ; I2C on, set to master
               mov                b'10000000', SSPSTAT        ; slew disabled: standard speed control
               mov                0x28, SSPADD                        ; 100kHz @ 4MHz
               bsf                TRISC, SCL                                ; I2C SCL pin is input
               bsf                PORTC, SCL                                ; (will be controlled by SSP)
               bsf                TRISC, SDA                                ; I2C SDA pin is input
               bsf                PORTC, SDA                                ; (will be controlled by SSP)
       return

;; Send an I2C start sequence
I2C_Start
                       bsf                SSPCON2, SEN                ; start sequence
i2cstart        btfsc        SSPCON2, SEN
                       bra                i2cstart
       return

;; Repeat an I2C start sequence
I2C_Restart
                       bsf                SSPCON2, RSEN                ; repeated start sequence
i2crestart        btfsc        SSPCON2, RSEN
                       bra                i2crestart
       return

;; Send an I2C stop sequence
I2C_Stop
                       bsf                SSPCON2, PEN                ; stop bit
i2cstop                btfsc        SSPCON2, PEN
                       bra                i2cstop
       return

;; Write the WREG to the I2C bus
I2C_WriteW
                       mov                W, SSPBUF                        ; slave's address, write bit set
i2cwritew        btfsc        SSPSTAT, R_W
                       bra                i2cwritew
       return

;; Receive a byte over I2C
I2C_Receive
                       bsf                SSPCON2, RCEN                ; enable reception
i2creceive        btfsc        SSPSTAT, RCEN                ; byte received
                       bra                i2creceive
       return

;; Send an acknowledgement over I2C
I2C_Ack
                       bsf                SSPCON2, ACKDT                ; output acknowledgment
                       bsf                SSPCON2, ACKEN
i2cack                btfsc        SSPCON2, ACKEN                ; NACK finished
                       bra                i2cack
       return

;; Print a value from the I2C via UART
I2C_Print
               _puts        "sensor value: \0"
               movff        SSPBUF, Ones
               _encda        Ones
               movff        Ones, W
               call        UART_Put
               _puts        "\n\r"
       return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  Delays
;; A 1 millisecond delay @ 4MHz
del_1msec
               mov                d'16', count2
loop1        mov                d'250', count1
               decfsz        count1, F
               bra                loop1
               decfsz        count2, F
               bra                loop1
       return

;; A 5 msec (+~ .5 msec) delay based on del_1msec
del_5msec
               mov                d'5', count3
               call        del_1msec
               decfsz        count3, F
               bra                $-2
       return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  Strings

;; print NUL-terminated string at TBLPTR
;;                from http://forum.microchip.com/tm.asp?m=69235
putstrtail:
loop:          tblrd        *+
               movf        TABLAT,w
               bz                done
           rcall        UART_Put
           bra        loop
done:return

;; print NUL-terminated string at PC
putstrpc:
               movff        TOSU,TBLPTRU
               movff        TOSH,TBLPTRH
               movff        TOSL,TBLPTRL
putstr2:rcall        putstrtail
       ; adjust return address to after end of string
fixuppc:btfsc        TBLPTRL,0        ; is ptr odd?
               tblrd        *+                        ; yes, bump it by one
               movf        TBLPTRU,w        ; copy to return PC
               movwf        TOSU                ; ** cannot use movff **
               movf        TBLPTRH,w
               movwf        TOSH
               movf        TBLPTRL,w
               movwf        TOSL
       return

; Binary (16-bit) to BCD. From Microchip PICDEM 2 PLUS DEMO BOARD
; xxx = highest possible result
bin16_bcd:
               ; Takes number in NumH:NumL
               ; Returns decimal in TenK:Thou:Hund:Tens:Ones
               swapf        NumH,W
               andlw        0x0F
               addlw        0xF0
               movwf        Thou
               addwf        Thou,F
               addlw        0xE2
               movwf        Hund
               addlw        0x32
               movwf        Ones
               movf        NumH,W
               andlw        0x0F
               addwf        Hund,F
               addwf        Hund,F
               addwf        Ones,F
               addlw        0xE9
               movwf        Tens
               addwf        Tens,F
               addwf        Tens,F
               swapf        NumL,W
               andlw        0x0F
               addwf        Tens,F
               addwf        Ones,F
               rlcf        Tens,F
               rlcf        Ones,F
               comf        Ones,F
               rlcf        Ones,F
               movf        NumL,W
               andlw        0x0F
               addwf        Ones,F
               rlcf        Thou,F
               movlw        0x07
               movwf        TenK
               movlw        0x0A ; Ten
Lb1:
               decf        Tens,F
               addwf        Ones,F
               btfss        STATUS,C
               bra        Lb1
Lb2:
               decf        Hund,F
               addwf        Tens,F
               btfss        STATUS,C
               bra        Lb2
Lb3:
               decf        Thou,F
               addwf        Hund,F
               btfss        STATUS,C
               bra        Lb3
Lb4:
               decf        TenK,F
               addwf        Thou,F
               btfss        STATUS,C
               bra        Lb4
       return

       end

2005\03\04@092857 by Ian Smith-Heisters

flavicon
face
Lee Jones wrote:
 > Again, depends on the processor you have selected in MPASM.  And
> it depends on what is on the "line" -- one 18-series line could
> translate into 2-bytes, 4-bytes, or (if it's a macro) many bytes.
>
> You are confusing the datasheet description of the bit meanings
> inside the PIC CPU and the interpretation of symbols in MPASM.  The
> 18-series PIC hardware, as with other PIC familes, treat offsets
> and absolute locations in terms of words.
>
> MPASM, on the other hand, treats operand values in terms of words
> for 12-bit and 14-bit parts but treats operand values in terms of
> bytes for 16-bit parts.  MPASM has to convert all those byte values
> into words when building the instruction bit patterns.
>

Thanks, this makes it crystal clear. Now I see why I don't really /need/
to know this, since I should use labels and ignore the details. But it
satisfies my desire to know the details anyway.

>
> On 18-series parts, BRA <label> is a single-word instruction with
> the target label having to be within 1024 words (either direction).
> GOTO <label> is a double-word instruction where the target label
> can be located anywhere in program memory.
>

Ahh, english. It says this in the datasheet, but I didn't understand it
there. Again, crystal clear.

Thanks for clarifying.

-Ian

>                                                Lee Jones
>

2005\03\04@093345 by Ian Smith-Heisters

flavicon
face
Russell McMahon wrote:
{Quote hidden}

That actually sounds kind of fun.. The winter nights /are/ almost cold
and ugly enough to make me want to figure it out, but deadlines are
king. Now that I am using the tools more correctly, and Lee Jones
explained the details, I can see why the tools are there. It's important
for me to see that asm, despite its reputation for being as nitty-gritty
as one can get, is still a level above machine code.

Thanks,
Ian

>
>
>
>        RM
>
>
>

2005\03\04@105334 by Ian Smith-Heisters

flavicon
face
I've now exhausted my new resources ;) Using debug statements I've
figured out that the acknowledge bit never clears, as though the SRF08
never gets the transmission. Are there any recommendations anyone can
make for debugging this further? How can I figure out if the problem is
my code, the wiring, or the SRF08?

The code is below. The problem first arises in the sub I2C_WriteW, it
hangs while waiting for the acknowledge bit to clear.

Thanks much,
Ian

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; srf08.asm
;        Controls an array of 8 SRF08 ultrasonic rangefinders
;
;        by Ian Smith-Heisters
;                February 26th, 2005:        Started
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

       title "SRF08 Control"
       List p=18f452,f=inhx32
       #include <p18f452.inc>

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Configuration

;The config aliases are already defined in the 18f452 header file.
       __CONFIG    _CONFIG1H, _OSCS_ON_1H & _XT_OSC_1H ; External Clock on
OSC1 & OSC2
       __CONFIG    _CONFIG2L, _BOR_ON_2L & _BORV_20_2L & _PWRT_OFF_2L ; Brown
out reset on at 2.0V, no power-up timer
       __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H ; watchdog off,
postscaler count to 128
       __CONFIG    _CONFIG3H, _CCP2MX_ON_3H ; CCP2 pin Mux enabled. What is this?
       __CONFIG    _CONFIG4L, _STVR_ON_4L & _LVP_ON_4L & _DEBUG_OFF_4L ; Stack
under/overflow reset on, LVP on, debug off
       __CONFIG    _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L &
_CP3_OFF_5L ; all protection off
       __CONFIG    _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
       __CONFIG    _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L &
_WRT3_OFF_6L
       __CONFIG    _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
       __CONFIG    _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L &
_EBTR3_OFF_7L
       __CONFIG    _CONFIG7H, _EBTRB_OFF_7H

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Variable Definitions

; Define Constants
#define DELIMETER        ' '
#define EOL                        '\n'

; Define variables
       cblock 0x000
               count1                ; count variables. Useful for loops etc.
               count2
               count3
               char                ; a holder for a single character
               NumH                ; digit variables for sending 10 bit hex
               NumL                ;                numbers as decimal
               TenK
               Thou
               Hund
               Tens
               Ones
       endc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Macro Definitions

mov                MACRO litval, file                ; move a literal directly to a register
               movlw        litval
               movwf        file
       endm

_encda MACRO x                                        ; encode in ASCII
               movlw        0x30
               addwf        x, F
       endm

_puts MACRO s                                        ; output a NUL-terminated inline string
               call        putstrpc
               dw                s
       endm

_i2c_write MACRO x                                ; write x on the I2C bus
               movlw        x
               call        I2C_WriteW
       endm

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Vectors

       org        0x0000                                        ; reset vector

Start
       goto        Init

       org                0x0008                                ; high priority interrupt vector
Interrupt1
       goto        HighInterrupt

       org                0x0018                                ; low priority interrupt vector
Interrupt2
       goto        LowInterrupt

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Initialize

Init
       bsf                RCON, IPEN                        ; enable interrupt priorities
       clrf        TRISD                                ; Set port D to all output for LED
       call        UART_Init                        ; call initialization subs
       call        I2C_Init

       goto        Main

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Main loop

Main
               _puts                "beginning...\n\r\0"
       ;; Start ranging
               call                I2C_Start
               _i2c_write        0xE0                ; slave's address
               _i2c_write        0x00                ; command register
               _i2c_write        0x50                ; start ranging in inches
               call                I2C_Stop
               call                del_5msec

               _puts                "reached debug point 1\n\r"

       ;; Read results
               call                I2C_Start
               _i2c_write        0xE0                ; slave's address
               _i2c_write        0x02                ; first read address
               call                I2C_Restart
               _i2c_write        0xE1                ; slave's read address

               _puts                "reached debug 2\n\r\0"

               call                I2C_Receive

               _puts                "reached debug 3\n\r\0"

               call                I2C_Stop

               _puts                "reached debug 4\n\r\0"

               call                I2C_Print

               goto        Main

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Interrupt Handling

;; High Interrupt
HighInterrupt
       _puts        "High priority interrupt triggered.\n\r\0"
       retfie        0
       goto        Start
;; Low Interrupt
LowInterrupt
       _puts        "Low priority interrupt triggered.\n\r\0"
       retfie        0
       goto        Start

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;   Subroutine Definitions

               #include <UART.inc>

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  I2C

;; Initialize the PIC I2C
I2C_Init
               mov                b'00011000', TRISC                ; SDA and SCL to I2C
               mov                b'00101000', SSPCON1        ; I2C on, set to master
               mov                b'10000000', SSPSTAT        ; slew disabled: standard speed control
               mov                0x09, SSPADD                        ; 100kHz @ 4MHz
               bsf                TRISC, SCL                                ; I2C SCL pin is input
               bsf                PORTC, SCL                                ; (will be controlled by SSP)
               bsf                TRISC, SDA                                ; I2C SDA pin is input
               bsf                PORTC, SDA                                ; (will be controlled by SSP)
       return

;; Send an I2C start sequence
I2C_Start
                       bsf                SSPCON2, SEN                ; start sequence
i2cstart        btfsc        SSPCON2, SEN
                       bra                i2cstart
       return

;; Repeat an I2C start sequence
I2C_Restart
                       bsf                SSPCON2, RSEN                ; repeated start sequence
i2crestart        btfsc        SSPCON2, RSEN
                       bra                i2crestart
       return

;; Send an I2C stop sequence
I2C_Stop
                       bsf                SSPCON2, PEN                ; stop bit
i2cstop                btfsc        SSPCON2, PEN
                       bra                i2cstop
       return

;; Write the WREG to the I2C bus
I2C_WriteW
                       bcf                PIR1, SSPIF                        ; clear interrupt flag

                       movwf        SSPBUF                                ; load byte and send
i2cwritew1        btfss        PIR1, SSPIF                        ; send complete?
                       bra                i2cwritew1

i2cwritew2        btfsc        SSPCON2, ACKSTAT        ; acknowledge received?
                       bra                i2cwritew2
       return

;; Receive a byte over I2C
I2C_Receive
                       bcf                PIR1, SSPIF                        ; clear interrupt flag

                       bsf                SSPCON2, RCEN                ; enable reception
i2creceive1        btfss        PIR1, SSPIF                        ; byte received
                       bra                i2creceive1

                       bsf                SSPCON2, ACKDT
                       bsf                SSPCON2, ACKEN                ; send acknowledge
i2creceive2        btfsc        SSPCON2, ACKEN                ; sent?
                       bra                i2creceive2
       return

;; Print a value from the I2C via UART
I2C_Print
               _puts        "sensor value: \0"
               movff        SSPBUF, Ones
               _encda        Ones
               movff        Ones, W
               call        UART_Put
               _puts        "\n\r"
       return

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  Delays
;; A 1 millisecond delay @ 4MHz
del_1msec
               mov                d'16', count2
loop1        mov                d'250', count1
               decfsz        count1, F
               bra                loop1
               decfsz        count2, F
               bra                loop1
       return

;; A 5 msec (+~ .5 msec) delay based on del_1msec
del_5msec
               mov                d'5', count3
               call        del_1msec
               decfsz        count3, F
               bra                $-2
       return

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  Strings

;; print NUL-terminated string at TBLPTR
;;                from http://forum.microchip.com/tm.asp?m=69235
putstrtail:
loop:          tblrd        *+
               movf        TABLAT,w
               bz                done
           rcall        UART_Put
           bra        loop
done:return

;; print NUL-terminated string at PC
putstrpc:
               movff        TOSU,TBLPTRU
               movff        TOSH,TBLPTRH
               movff        TOSL,TBLPTRL
putstr2:rcall        putstrtail
       ; adjust return address to after end of string
fixuppc:btfsc        TBLPTRL,0        ; is ptr odd?
               tblrd        *+                        ; yes, bump it by one
               movf        TBLPTRU,w        ; copy to return PC
               movwf        TOSU                ; ** cannot use movff **
               movf        TBLPTRH,w
               movwf        TOSH
               movf        TBLPTRL,w
               movwf        TOSL
       return

; Binary (16-bit) to BCD. From Microchip PICDEM 2 PLUS DEMO BOARD
; xxx = highest possible result
bin16_bcd:
               ; Takes number in NumH:NumL
               ; Returns decimal in TenK:Thou:Hund:Tens:Ones
               swapf        NumH,W
               andlw        0x0F
               addlw        0xF0
               movwf        Thou
               addwf        Thou,F
               addlw        0xE2
               movwf        Hund
               addlw        0x32
               movwf        Ones
               movf        NumH,W
               andlw        0x0F
               addwf        Hund,F
               addwf        Hund,F
               addwf        Ones,F
               addlw        0xE9
               movwf        Tens
               addwf        Tens,F
               addwf        Tens,F
               swapf        NumL,W
               andlw        0x0F
               addwf        Tens,F
               addwf        Ones,F
               rlcf        Tens,F
               rlcf        Ones,F
               comf        Ones,F
               rlcf        Ones,F
               movf        NumL,W
               andlw        0x0F
               addwf        Ones,F
               rlcf        Thou,F
               movlw        0x07
               movwf        TenK
               movlw        0x0A ; Ten
Lb1:
               decf        Tens,F
               addwf        Ones,F
               btfss        STATUS,C
               bra        Lb1
Lb2:
               decf        Hund,F
               addwf        Tens,F
               btfss        STATUS,C
               bra        Lb2
Lb3:
               decf        Thou,F
               addwf        Hund,F
               btfss        STATUS,C
               bra        Lb3
Lb4:
               decf        TenK,F
               addwf        Thou,F
               btfss        STATUS,C
               bra        Lb4
       return

       end

2005\03\04@111648 by Bruce

flavicon
face
;; Send an I2C start sequence
I2C_Start
bsf SSPCON2, SEN ; start sequence
i2cstart btfsc SSPCON2, SEN
bra i2cstart <-------------------?????
return


-Bruce
http://www.rentron.com

2005\03\04@112909 by Alan B. Pearce

face picon face
>I've now exhausted my new resources ;) Using debug statements
>I've figured out that the acknowledge bit never clears, as
>though the SRF08 never gets the transmission. Are there any
>recommendations anyone can make for debugging this further?
>How can I figure out if the problem is my code, the wiring,
>or the SRF08?

Right, easiest way is to use a 'scope, a digital storage scope is ideal, but
even an ordinary analogue scope in triggered mode will allow you to make
useful observations.

>From the debug, do you know if it receives the address OK, or is the address
acknowledgement where it gets stuck?

If the address is not where it gets stuck, how far down the message does it
bomb out? Are you trying to send too many bytes? This is where the scope
will be a help. Set it up to trigger on the I2C line, and look to see how
many bytes go past. You will get a feel for this with an analogue scope,
especially if you put a shade around it to make it easier to see the trace.
Another trick here is to slow the transfer rate - you are using it within
the spec for the SRF08 I take it?

2005\03\04@113526 by Ian Smith-Heisters

flavicon
face
Bruce wrote:
> ;; Send an I2C start sequence
> I2C_Start
> bsf SSPCON2, SEN ; start sequence
> i2cstart btfsc SSPCON2, SEN
> bra i2cstart <-------------------?????
> return
>

Does this not loop to the line just before it with the label "i2cstart"?

I've seen two notations for labels: one with a colon, one without, is
there a difference? Is this the problem? eg.

label: btfsc SSPCON2, SEN

or

label btfsc SSPCON2, SEN

-Ian

>
> -Bruce
> http://www.rentron.com

2005\03\04@113916 by Ian Smith-Heisters

flavicon
face
Alan B. Pearce wrote:
>>I've now exhausted my new resources ;) Using debug statements
>>I've figured out that the acknowledge bit never clears, as
>>though the SRF08 never gets the transmission. Are there any
>>recommendations anyone can make for debugging this further?
>>How can I figure out if the problem is my code, the wiring,
>>or the SRF08?
>
>
> Right, easiest way is to use a 'scope, a digital storage scope is ideal, but
> even an ordinary analogue scope in triggered mode will allow you to make
> useful observations.

Yum, something else to learn. There actually is one around, so I'll take
a look.

>
>>From the debug, do you know if it receives the address OK, or is the address
> acknowledgement where it gets stuck?

It's in the address acknowledgement.

>
> If the address is not where it gets stuck, how far down the message does it
> bomb out? Are you trying to send too many bytes? This is where the scope
> will be a help. Set it up to trigger on the I2C line, and look to see how
> many bytes go past. You will get a feel for this with an analogue scope,
> especially if you put a shade around it to make it easier to see the trace.
> Another trick here is to slow the transfer rate - you are using it within
> the spec for the SRF08 I take it?
>
Yes to the last question.

Thanks for the advice, I'll take a whack with the scope asap.
-Ian

2005\03\04@115754 by Bruce

flavicon
face

> Does this not loop to the line just before it with the label "i2cstart"?
>
> I've seen two notations for labels: one with a colon, one without, is
> there a difference? Is this the problem? eg.
>
> label: btfsc SSPCON2, SEN
>
> or
>
> label btfsc SSPCON2, SEN

My bad. Thought it was one of your macros.

-Bruce
http://www.rentron.com

2005\03\04@122911 by Bob Ammerman

picon face
>
> I've seen two notations for labels: one with a colon, one without, is
> there a difference? Is this the problem? eg.
>
> label: btfsc SSPCON2, SEN
>
> or
>
> label btfsc SSPCON2, SEN
>
> -Ian

No, it is not the problem. The two syntaxes have identical semantics.

I prefer using the colon because it is easy to find the code by searching
for 'label:'

I also have a habit of placing the label on a line by itself, which allows
me to use nice long descriptive labels without messing up the formatting of
the code.

Bob Ammerman
RAm Systems


2005\03\04@124514 by Jan-Erik Soderholm

face picon face
Ian Smith-Heisters wrote :

> Jan-Erik Soderholm wrote:
>
> > Now, this doesn't say that EQU dosn't work, but it's a bit
> > of Yesterdays way of coding...
> >
>
> So what I've tried now is to just use a cblock. This is better, but
> since I'm not looking for relocatabitility, is it necessary to go
> further?...

I don't think so. It has probably nothing to do with your
actual problem anyway. If you later would like to write
clean, reusable code, you could read up on the linker and
relocatable code then. But don't bother right now.

> If so, can you point me towards a resource? Google
> has not been helpful in finding PIC18 asm tutorials/howtos.

That *is* a problem. Some member on the piclist made one
turorial on the linker, I think. I'm currently re-designing
my own site, and have plans to write some short hands-ons
on some topics that often are seen here...

I'll leave this thread here since I can't say I know that
much about I2C. My main concern was some coding
methods I thought worth commenting on...

> > Goto can "jump" longer. BRA is faster.
> > You *have* read the data sheet, right ?
> >
>
> Reading and understanding fully are *totally* different things.

Yep, agree.
You saw the link to the more complet descriptions of
the instruction set ?

> So now I've got some code that uses lots of labels,
> subroutines, macros,  and has interrupt vectors...

After just a quick glance, it *looks* better :-) And Iäm sure it's
easier fro anyone to follow it.

I've no idea why it doesn't do what you want (which
isn't the same thing as that it doesn't "work"... :-) :-) )

Good luck !
Jan-Erik.


More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...