Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.electronics.design > #381603

Re: OT: Reformatted update on table call problem

From Martin Brown <|||newspam|||@nezumi.demon.co.uk>
Newsgroups sci.electronics.design
Subject Re: OT: Reformatted update on table call problem
Date 2015-10-15 12:01 +0100
Organization Aioe.org NNTP Server
Message-ID <mvo12b$l30$1@speranza.aioe.org> (permalink)
References (2 earlier) <BLZSx.10$VZ.6@fx05.iad> <mvib6j$1c3$1@speranza.aioe.org> <5IlTx.51971$2s.12040@fx01.iad> <mvktqt$5l2$1@dont-email.me> <2FBTx.1$Bl2.0@fx27.iad>

Show all headers | View raw


On 15/10/2015 00:35, Robert Baer wrote:
> piglet wrote:
>> On 14/10/2015 06:26, Robert Baer wrote:

>>> * I have proven that PCLATH is set by the CALL - in this case to 0x0100
>>> and not the zero that would conveniently explain the apparent reset/cold
>>> start.

Seems unlikely since it can only hold values in the range 0x00 to 0xff.

>> Are you sure? Have you mixed up PCH and PCLATH.
>>
>> What happens during a CALL is 11 bits of PC are loaded from the opcode
>> (all of PCL and 3 low bits of PCH) and two bits from PCLATH go to PCH.
>> During arith on pc then the arith changes 8 bits of PCL and all 5 bits
>> of PCH are loaded from PCLATH. Neither arith nor CALL writes or changes
>> the value in PCLATH. Unless you restrict your table and code using it to
>> the first 255 locations then PCLATH has to be written to by your code
>> before doing the table lookup.
>>
>> It is all in the chip datasheet.
>>
>> piglet
>>
>    Concerning "datasheets, here is a code snippet:
> ; ----------------------------------------------
> ; From AN556 page 3, EXAMPLE 4:
>          org     0x02ff     ;Table located end of page 2
> Table:
>          addwf   PCL,F      ;value in pc will not roll over to page 3
>          retlw   d'65'      ;NOTE assembler doesn't recognize 'A' etc..
>          retlw   d'66'      ;     so assembler will crash.
>          retlw   d'67'      ;     Therefore used decimal equivalent
> ; *Also discovered that PC _CAN_ indeed "rollover" to page 3, I modified
> the
> ;  code to show that fact thus:
> ;Table:   MOVF    PCLATH,W
> ;         CALL    DISPL   ; to show that CALL sets PCLATH (documentation
> ;                                does NOT state this fact).
> ;         MOVLW   0xA5
> ;         CALL    DISPL   ; use unique "marker"
> ;         GOTO    start   ; !!!     See 0x00 0xFF 0x02 0xA5 repeat (!!)

WTF don't you use the software PIC emulator and single step it?

Then you can watch all the registers and understand the thing properly.

You might find this page informative if you are still struggling:
http://pcbheaven.com/picpages/Program_Flow_Instructions/

The problem you are having is because PCL & PCH are both 8 bits wide 
whereas the CALL and GOTO locations are 11 bits and 2bits from PCLATH.

It is quite a nasty gotcha for the unwary. It is good practice to keep 
PCLATH pointed at the page where you intend to execute instructions.

-- 
Regards,
Martin Brown

Back to sci.electronics.design | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-11 23:17 -0700
  Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-12 09:17 +0100
    Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-12 19:11 -0700
      Re: OT: Reformatted update on table call problem Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2015-10-13 08:17 +0100
        Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-13 22:26 -0700
          Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-14 07:50 +0100
            Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-14 16:35 -0700
              Re: OT: Reformatted update on table call problem Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2015-10-15 12:01 +0100
                Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-15 22:41 -0700
                Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-16 07:09 +0100
                Re: OT: Reformatted update on table call problem Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2015-10-16 08:50 +0100
                Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-16 09:31 +0100
                Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-17 21:34 -0700
                Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-18 09:42 +0100
                Re: OT: Reformatted update on table call problem Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2015-10-19 09:12 +0100
                Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-19 23:04 -0700
                Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-17 21:08 -0700
                Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-18 09:45 +0100
                Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-19 23:08 -0700
                Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-17 21:19 -0700
                Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-18 09:50 +0100
                Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-19 23:14 -0700
                Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-17 21:03 -0700
                Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-18 10:14 +0100
                Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-19 23:31 -0700
                Re: Reformatted update on table call problem "P E Schoen" <paul@pstech-inc.com> - 2015-10-20 20:30 -0400
                Re: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-20 22:42 -0700
                Re: Reformatted update on table call problem "P E Schoen" <paul@pstech-inc.com> - 2015-10-21 14:06 -0400
                Re: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-23 21:01 -0700
                Re: Reformatted update on table call problem "P E Schoen" <paul@pstech-inc.com> - 2015-10-24 01:08 -0400
                Re: Reformatted update on table call problem krw <krw@nowhere.com> - 2015-10-24 09:05 -0400
  Re: OT: Reformatted update on table call problem Martin Brown <|||newspam|||@nezumi.demon.co.uk> - 2015-10-12 09:46 +0100
    Re: OT: Reformatted update on table call problem piglet <erichpwagner@hotmail.com> - 2015-10-12 10:39 +0100
      Re: OT: Reformatted update on table call problem Martin Riddle <martin_ridd@verizon.net> - 2015-10-12 08:24 -0400
        Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-12 19:54 -0700
        Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-12 19:55 -0700
      Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-12 19:49 -0700
    Re: OT: Reformatted update on table call problem Robert Baer <robertbaer@localnet.com> - 2015-10-12 19:44 -0700
      Re: OT: Reformatted update on table call problem (OOPS!) Robert Baer <robertbaer@localnet.com> - 2015-10-12 23:52 -0700

csiph-web