Searching \ for '[PIC]: PCLATH is overwritten for no reason' 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=pic
Search entire site for: 'PCLATH is overwritten for no reason'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: PCLATH is overwritten for no reason'
2001\03\24@133827 by Thomas N

picon face
Hi everyone,

Below is a common LCD display code you often see.  Anyway, I have a small
problem with it.

When I trace through the code, it goes from line 00082 to line 00085 then
jump to line 00097 and 00098.  At location 00098, you can see that the
program counter is 0x0285 (PCL displays 0x85) and W contains value 0.  After
line 00098 is executed, PCL becomes 0x86.  Next, the program jump to
location 0x0086 (not 0x0286), which is somewhere else in the code.  WHY?  I
suspect that the content of PCLATH is overwritten for some reason.  Please
help!
Thomas

027B   3000    00082         MOVLW   0; Table address
027C           00083 DISPMSG
027C   00AF    00084         MOVWF   TABLE_TEMP  ;start of message
027D   2285    00085         CALL    TABLE
027E   39FF    00086         ANDLW   0FFH
027F   1903    00087         BTFSC   STATUS,Z

0280   2A84    00088         GOTO    OUT
              00089         call    Send_Char       ; Display character
0281   082F    00090         MOVF    TABLE_TEMP,W
0282   3E01    00091         ADDLW   1
0283   2A7C    00092         GOTO    DISPMSG
0284           00093 OUT:
              00094
0284   0008    00095         RETURN
              00096
0285           00097 TABLE:
0285   0782    00098         ADDWF   PCL,F           ; Jump to character
0286   3454 3468 3469 00099  DT      "This is a test!" ;
      3473 3420 3469
      3473 3420 3461
      3420 3474 3465
      3473 3474 3421
0295           00100 TABLE_END:
0295   3400    00101         RETLW   0
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\03\24@135528 by Thomas C. Sefranek

face picon face
Thomas N wrote:

> Hi everyone,
>
> Below is a common LCD display code you often see.  Anyway, I have a small
> problem with it.
>
> When I trace through the code, it goes from line 00082 to line 00085 then
> jump to line 00097 and 00098.  At location 00098, you can see that the
> program counter is 0x0285 (PCL displays 0x85) and W contains value 0.  After
> line 00098 is executed, PCL becomes 0x86.  Next, the program jump to
> location 0x0086 (not 0x0286), which is somewhere else in the code.  WHY?  I
> suspect that the content of PCLATH is overwritten for some reason.  Please
> help!
> Thomas
>
> 027B   3000    00082         MOVLW   0; Table address
> 027C           00083 DISPMSG
> 027C   00AF    00084         MOVWF   TABLE_TEMP  ;start of message
> 027D   2285    00085         CALL    TABLE

O.K. You called TABLE which did a ADDWF to the Program counter,
which pointer the program counter to... TABLE and it tried to execute the
text as code.  I think you want a RETLW for EACH character in the table!


>
> 027E   39FF    00086         ANDLW   0FFH

You don't need to do this when the RETLW is working,
it affects the ZERO bit flag as it fetches the text value.

{Quote hidden}

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

hamradio.cmcorp.com/inventory/Inventory.html
http://www.harvardrepeater.org

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\03\24@142032 by Dave Mumert

flavicon
face
Hi Thomas

Try setting PCLATH before you call TABLE

PCLATH is not set by a call and return so you have to set them yourself.

Try inserting
       movlw  high(TABLE)
       movwf  PCLATH
before CALL   TABLE


Also it may be a bit easier to understand if you define your string with a
trailing 0 instead of using a RETLW 0
   DT      "This is a test!",0

Good Luck

Dave Mumert

{Original Message removed}

2001\03\24@192245 by Kelly Kohls

picon face
Thomas,

Try the following code:

Define your table like this:

Preamble_Line1              MOVWF    PCL                ;
                           DT "Test message",0         ;



The following code displays the string:


                      CLRF    LCD_Index                        ; Start with
first character

Preamble_Loop1

                      MOVLW   HIGH Preamble_Line1              ; Load
PCLATH with the
                      MOVWF   PCLATH                           ;   high
address of our table
                      MOVLW   LOW Preamble_Line1 + 1           ; Load W
with the low address of our table
                      ADDWF   LCD_Index,W                      ; Add in the
offset
                      BTFSC   STATUS,C                         ; Do we have
a carry?
                      INCF    PCLATH,F                         ; Yes,
adjust PCLATH
                      CALL    Preamble_Line1                   ; Call our
table
                      MOVWF   LCD_Data                         ; Save data
for our LCD writing routine
                      PAGESEL $                                ; Reset
PCLATH to point to this bank
                      MOVF    LCD_Data,F                       ; Check to
see if
                      BTFSC   STATUS,Z                         ;   our data
is zero
                      GOTO    Preamble_Finished1               ; Yes, we
are done
                      PAGESEL LCD_Send_Data                    ; Change to
the bank with our LCD write routine
                      CALL    LCD_Send_Data                    ; Call our
LCD write routine
                      PAGESEL $                                ; Change
back to this bank
                      INCF    LCD_Index,F                      ; Move to
the next character
                      GOTO    Preamble_Loop1                   ; Run the
loop again

Preamble_Finished1


Hope this helps.


Kelly Kohls, N5TLE
Dallas, Texas
Homepage: http://www.qsl.net/n5tle/
There's never enough time to do it right, but plenty of time to do it over.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\03\24@210612 by Olin Lathrop

face picon face
> O.K. You called TABLE which did a ADDWF to the Program counter,
> which pointer the program counter to... TABLE and it tried to execute the
> text as code.  I think you want a RETLW for EACH character in the table!

He does.  That's what the DT directive does.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, .....olinKILLspamspam@spam@embedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


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