Searching \ for '[PIC]: 18f Indirect Addressing' 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/devices.htm?key=18F
Search entire site for: '18f Indirect Addressing'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: 18f Indirect Addressing'
2002\12\23@030352 by Josh Koffman

flavicon
face
Hi all. Working on indirect addressing for the first time in the 18f
series. And (of course) I've got a few questions. I realize that I have
two FSR registers per main FSR register (ie FSR0L and FSR0H for FSR0).
If I'm only using the registers in the first access bank though, can I
just leave FSRxH as 0x00? If that's the case, will code like this work:
       movf    (PWM0VAL+CHANCNT),w
       movwf   FSR0
       movff   PWMTEMP, INDF0
PWM0VAL would be a register location, and CHANCNT would be the offset
from that for the write. I know this isn't likely to work, as I want to
take the location of PWM0VAL, but the contents of CHANCNT. Even if the
instruction is valid (I don't know about the use of the + and the
brackets there), there is no differentiation between what I want from
which label. So, is there any way to tell MPASM what I want to do?
Alternatively, if I set it up so PWM0VAL is at 0x0000, then just moving
the contents to CHANCNT to the FSR should allow me to read properly
correct? It's kind of a hack that I'd rather avoid, but it can be
accomplished fairly easily.

One last question...does anyone know anything about the LFSR operand on
the 18f chips? I know there was a serious silicon bug on the 18c chips
and Microchip basically said not to use the instruction. Does it work on
the 18F chips? Is it possible to use anything other than a constant in
that operand? For example something like LFSR 2, CHANCNT?

Thanks!

Josh
--
A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
       -Douglas Adams

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2002\12\23@053139 by cdb

flavicon
face
This is something from the Embedded Design book by Prof John Peatman.

I'm probably wrong but in your code shouldn't you be copying the
address of the variable to FSR0?

I have heard that 'B' series silicon can  have  temperature stability
problem at room temperature on the 18F series.

Colin

POINT  macro stringname
          movlw    high stringname
        movwf    TBLPTRH
          movlw   low stringname
        movwf   TBLPTRL
          endm

ByteDisplay
  POINT Byte_1           ;Display BYTE=
  rcall DisplayConst     ;send to display
  lfsr 0,BYTESTR+8       ;byte = 8 elements set lfsr0 to point to
element 8 of BYTESTR
  REPEAT_
    clrf WREG            ;Make sure W is empty
    rrcf BYTE,F          ;Move contents of bit0 into carry
    rlcf WREG,F          ;Move into W
    iorlw 0x30           ;Add 30h to contents to make ASCII number
    movwf POSTDEC0       ;Move into BYTESTR and move back one
position
    movf FSR0L,W         ;Have we finished
    sublw low BYTESTR
  UNTIL_ .Z.

  lfsr 0,BYTESTR        ;Going to add position to element0 and EOF
to position 9 so pointer = beginning of file
  MOVLF 0xC0,BYTESTR    ;0xC0 = line 2 for cursor
  clrf BYTESTR+9        ;EOF indicator at element 9
  rcall DisplayStrng    ;Call string display
  return


--
cdb, spam_OUTbodgy1TakeThisOuTspamoptusnet.com.au on 23/12/2002

Light travels faster than sound. That's why some people appear bright
until they speak!

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2002\12\23@092328 by Olin Lathrop

face picon face
> Hi all. Working on indirect addressing for the first time in the 18f
> series. And (of course) I've got a few questions. I realize that I have
> two FSR registers per main FSR register (ie FSR0L and FSR0H for FSR0).
> If I'm only using the registers in the first access bank

There is only one access bank.  That's its purpose.  It makes no sense to
talk about the "first" access bank.  I'll assume you meant the first bank,
meaning bank 0, which contains the absolue RAM addresses 0 - FFh.

> though, can I
> just leave FSRxH as 0x00?

It has to be 0 if you want to access RAM in the 0 - FFh range.  The two
byte FSR register contains the full address (no banking).

> If that's the case, will code like this work:
>         movf    (PWM0VAL+CHANCNT),w
>         movwf   FSR0
>         movff   PWMTEMP, INDF0

Please add comments so we know what you intended this to do.

> PWM0VAL would be a register location, and CHANCNT would be the offset
> from that for the write. I know this isn't likely to work, as I want to
> take the location of PWM0VAL, but the contents of CHANCNT.

Huh?

> Even if the
> instruction is valid (I don't know about the use of the + and the
> brackets there),

Should be fine.

> there is no differentiation between what I want from
> which label. So, is there any way to tell MPASM what I want to do?

I don't know.  What do you want to do?

> One last question...does anyone know anything about the LFSR operand on
> the 18f chips? I know there was a serious silicon bug on the 18c chips
> and Microchip basically said not to use the instruction. Does it work on
> the 18F chips? Is it possible to use anything other than a constant in
> that operand? For example something like LFSR 2, CHANCNT?

You can look this up yourself in the errata sheet.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2002\12\23@095619 by tcs

face picon face
Hi Olin!  Happy Christmas!

Hey gang, I wonder if they FIXED the LFSR command in the 18F series.
Does any one know?  All I ever heard was promises...

I showed Olin the problem I was having with the LFSR command in the 18C
series...
(Early adopter problems...)
THEN, they came out with an eratta....

 *
 |  __O    Thomas C. Sefranek  .....tcsKILLspamspam@spam@cmcorp.com
 |_-\<,_   Amateur Radio Operator: WA1RHP
 (*)/ (*)  Bicycle mobile on 145.41, 448.625 MHz

ARRL Instructor, Technical Specialist, VE Contact.
hamradio.cmcorp.com/inventory/Inventory.html
http://www.harvardrepeater.org

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2002\12\23@115721 by Josh Koffman

flavicon
face
Comments within.


Olin Lathrop wrote:
> There is only one access bank.  That's its purpose.  It makes no sense to
> talk about the "first" access bank.  I'll assume you meant the first bank,
> meaning bank 0, which contains the absolue RAM addresses 0 - FFh.

Correct. My bad using the wrong terminology.

> > though, can I
> > just leave FSRxH as 0x00?
>
> It has to be 0 if you want to access RAM in the 0 - FFh range.  The two
> byte FSR register contains the full address (no banking).

So then if I set FSRxH to 0x00, all I have to load each time is FSHxL
correct? Will FSRxH ever be changed by the chip somehow? I will make
sure I don't change it in my code, but can it be affected by any other
operations?

> > If that's the case, will code like this work:
> >         movf    (PWM0VAL+CHANCNT),w ;Take the location of PWM0VAL                                   ;(start location), add the value                                        ;in CHANCNT (offset)
> >         movwf   FSR0L               ;Put it in FSR0L (FSR0H will                                    ;already be 0x00
> >         movff   PWMTEMP, INDF0      ;Move value from PWMTEMP to the                                         ;proper location in memory
>

Comments added

> > PWM0VAL would be a register location, and CHANCNT would be the offset
> > from that for the write. I know this isn't likely to work, as I want to
> > take the location of PWM0VAL, but the contents of CHANCNT.
>
> Huh?

Admittedly, I was somewhat unclear here. Basically what I am trying to
do is use the location of PWM0VAL as the start of a table of data. The
value of CHANCNT would act as the offset. I realize my instructions
above shouldn't work right because I am trying to take two different
things from these variables (one I want the location in memory, one I
want the value in the memory location). I think a better way to do it
might be this:

        movf    PWM0VAL,w      ;Take the location of PWM0VAL                                           ;(start
location)
        movwf   FSR0L          ;Put it in FSR0L (FSR0H will                                            ;already be
0x00
       movf    CHANCNT, w      ;Take the value of CHANCNT (offset)
       addwf   FSR0L, f        ;Add to FSR0L
       movff   PWMTEMP, INDF0  ;Move value from PWMTEMP to the
;proper location in memory

However, again I am stuck trying to get the location in memory of
PWM0VAL. By doing the MOVF, won't I just be taking the value stored in
PWM0VAL, not the location of the actual register? Is there any way to
actually specify that I want the location of the register, not the value
in the register? I could hard specify where the register is to be
located in my def's, but then the code isn't as portable. Any ideas?

I hope I'm being a bit clearer this time.

Josh
--
A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
       -Douglas Adams

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2002\12\23@123102 by Bob Ammerman

picon face
; This should do what you need (assume FSR0H is kept = 0)

movlw    PWM0VAL        ; get address of start of array
addwf    CHANCNT,w    ; point to desired entry
movwf    FSR0L              ; put in index register
movff     PWMTEMP,INDF0

; This will also work if FSR0H and FSR0L are both kept 0

movlw    PWM0VAL
addwf    CHANCNT,w
movff     PWMTEMP,PLUSW0

Bob Ammerman
RAm Systems


{Original Message removed}

2002\12\23@123806 by Josh Koffman

flavicon
face
Bingo! Thank you Bob, that's what I needed...the movlw operand!

Thanks,

Josh
--
A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
       -Douglas Adams

Bob Ammerman wrote:
{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2002\12\23@130127 by Olin Lathrop

face picon face
> So then if I set FSRxH to 0x00, all I have to load each time is FSHxL
> correct?

As long as you stay within the 0 - FFh address range.

> Will FSRxH ever be changed by the chip somehow?

Yes, on auto increment and auto decrement.  If you auto increment from
FFh, then the address will become 100h, which sets the high byte of the
FSR to 1.

> Admittedly, I was somewhat unclear here. Basically what I am trying to
> do is use the location of PWM0VAL as the start of a table of data. The
> value of CHANCNT would act as the offset.

Ah, then you have to compute the address at run time, something like:

     movf    chancnt, w   ;get the offset
     addlw   pwm0val      ;add in the base address

> I realize my instructions
> above shouldn't work right because I am trying to take two different
> things from these variables (one I want the location in memory, one I
> want the value in the memory location).

Right.

> I think a better way to do it
> might be this:
>
>          movf    PWM0VAL,w      ;Take the location of PWM0VAL
;(start
> location)

This will get the contents of PWM0VAL into W, not its address.  It looks
like you meant to use MOVLW.

>          movwf   FSR0L          ;Put it in FSR0L (FSR0H will
;already be
> 0x00
>         movf    CHANCNT, w      ;Take the value of CHANCNT (offset)
>         addwf   FSR0L, f        ;Add to FSR0L

Note that this assumes all the PWMnVAL variables are in the same bank
because you ignore the carry from this instruction.

>         movff   PWMTEMP, INDF0  ;Move value from PWMTEMP to the
> ;proper location in memory
>
> However, again I am stuck trying to get the location in memory of
> PWM0VAL.

   movlw  pwm0val

> By doing the MOVF, won't I just be taking the value stored in
> PWM0VAL, not the location of the actual register?

Yes.

> Is there any way to
> actually specify that I want the location of the register, not the value
> in the register?

Yes, see above.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

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