Searching \ for '[PIC]: Spot the Bug! AKA table reads' 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/memory.htm?key=table
Search entire site for: 'Spot the Bug! AKA table reads'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Spot the Bug! AKA table reads'
2000\10\12@181227 by Paul Reilly

picon face
Hi,

I'm building a project with the 16F877 chip interfaced to a Hitachi type
LCD. I have plenty of LCD screens to display (much more than 256
chars) and so I want to implement them all at the top of the program
memory.

However when I do that I run in to table read errors, and my program
crashes. I've read the Microchip app notes on implementing a safe table
read in high memory, and used the method they say, but it still crashes!
I just can't figure it out.

The text table is at ORG 1800h and just has 4 RETLW instructions, to
print out the letters A, B, C, D as a test. At the start of the
troublesome routine I print a ">" to indicate I'm in the display_message
routine, and a "<" at the end to show I'm finished. The program prints the
">" on the LCD and then crashes.

Here's extracts of my code. Can anyone spot the bug?



TABLE_ADDR      EQU 0x1800

;-----------------------------------------------------------------------;
;   display_welcome                                                     ;
;-----------------------------------------------------------------------;


display_message
               movlw   0
               movf    offset

               movlw   ">"
               call    send_ascii

               movlw   LOW TABLE
               addwf   offset
               movlw   HIGH TABLE
               btfsc   status,c
               addlw   1
               movwf   PCLATH
               movf    offset,w

               call    TABLE
               call    send_ascii

               movlw   "<"
               call    send_ascii

               return


;-----------------------------------------------------------------------;
;  Messages                                                             ;
;-----------------------------------------------------------------------;

ORG TABLE_ADDR

TABLE
               movwf   PCL     ; called with displacement in W
               retlw   "A"
               retlw   "B"
               retlw   "C"
               retlw   "D"




Any help appreciated!

Paul

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use spam_OUTlistservTakeThisOuTspammitvma.mit.edu?body=SET%20PICList%20DIGEST




2000\10\12@190507 by Paul Reilly

picon face
Hi,

[ Apologies if this has been sent twice! ]

I'm building a project with the 16F877 chip interfaced to a Hitachi type
LCD. I have plenty of LCD screens to display (much more than 256
chars) and so I want to implement them all at the top of the program
memory.

However when I do that I run in to table read errors, and my program
crashes. I've read the Microchip app notes on implementing a safe table
read in high memory, and used the method they say, but it still crashes!
I just can't figure it out.

The text table is at ORG 1800h and just has 4 RETLW instructions, to
print out the letters A, B, C, D as a test. At the start of the
troublesome routine I print a ">" to indicate I'm in the display_message
routine, and a "<" at the end to show I'm finished. The program prints the
">" on the LCD and then crashes.

Can anyone spot the bug?

Here's extracts of my code. The routines for setting up the ports, and
initialising the LCD are not shown.



TABLE_ADDR      EQU 0x1800

;-----------------------------------------------------------------------;
;   display_welcome                                                     ;
;-----------------------------------------------------------------------;


display_message
               movlw   0
               movf    offset

               movlw   ">"
               call    send_ascii

               movlw   LOW TABLE
               addwf   offset
               movlw   HIGH TABLE
               btfsc   status,c
               addlw   1
               movwf   PCLATH
               movf    offset,w

               call    TABLE
               call    send_ascii

               movlw   "<"
               call    send_ascii

               return


;-----------------------------------------------------------------------;
;  Messages                                                             ;
;-----------------------------------------------------------------------;

ORG TABLE_ADDR

TABLE
               movwf   PCL     ; called with displacement in W
               retlw   "A"
               retlw   "B"
               retlw   "C"
               retlw   "D"




Any help appreciated!

Paul

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use .....listservKILLspamspam@spam@mitvma.mit.edu?body=SET%20PICList%20DIGEST




2000\10\12@191803 by hard Prosser

flavicon
face
Just possibly,


with your:-
display_message
               movlw   0
               movf    offset

the       movf offset
should be
         movf offset,w ?
Otherwise you're just moving offset to itself and possibly running out the
top end of the table when you do the lookup?

I've found that it pays before you call the table lookup routine to make
sure the w reg is within allowable limits.

Hope this helps

Richard P




Hi,

I'm building a project with the 16F877 chip interfaced to a Hitachi type
LCD. I have plenty of LCD screens to display (much more than 256
chars) and so I want to implement them all at the top of the program
memory.

However when I do that I run in to table read errors, and my program
crashes. I've read the Microchip app notes on implementing a safe table
read in high memory, and used the method they say, but it still crashes!
I just can't figure it out.

The text table is at ORG 1800h and just has 4 RETLW instructions, to
print out the letters A, B, C, D as a test. At the start of the
troublesome routine I print a ">" to indicate I'm in the display_message
routine, and a "<" at the end to show I'm finished. The program prints the
">" on the LCD and then crashes.

Here's extracts of my code. Can anyone spot the bug?



TABLE_ADDR      EQU 0x1800

;-----------------------------------------------------------------------;
;   display_welcome                                                     ;
;-----------------------------------------------------------------------;


display_message
               movlw   0
               movf    offset

               movlw   ">"
               call    send_ascii

               movlw   LOW TABLE
               addwf   offset
               movlw   HIGH TABLE
               btfsc   status,c
               addlw   1
               movwf   PCLATH
               movf    offset,w

               call    TABLE
               call    send_ascii

               movlw   "<"
               call    send_ascii

               return


;-----------------------------------------------------------------------;
;  Messages                                                             ;
;-----------------------------------------------------------------------;

ORG TABLE_ADDR

TABLE
               movwf   PCL     ; called with displacement in W
               retlw   "A"
               retlw   "B"
               retlw   "C"
               retlw   "D"




Any help appreciated!

Paul

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use listservspamKILLspammitvma.mit.edu?body=SET%20PICList%20DIGEST

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use .....listservKILLspamspam.....mitvma.mit.edu?body=SET%20PICList%20DIGEST




2000\10\12@195956 by adastra

flavicon
face
Paul:

I do this a little differently:

First, get the offset into w, then call the table, then add the offset.
(Be sure to include the destination (f) in the addwf instruction.)


TABLE
>                 addwf   PCL,f     ; called with displacement in W
>                 retlw   "A"
>                 retlw   "B"
>                 retlw   "C"
>                 retlw   "D"


The thing to remember is that when you do the "addwf    PCL,f", the computed
address will include the PCLATH, which in your case, will have to be 0x18.
(The contents of w can only range to FF, so the rest of the address has to
come from PCLATH.  I have done a very similar thing as you describe (lots of
text messages to a Hitatchi LCD), and sometimes have found it useful to have
a separate table just to return the appropriate PCLATH value prior to
calling the message table.

Hope this helps.

       Foster





> {Original Message removed}

2000\10\12@200413 by Thomas C. Sefranek

face picon face
Paul Reilly wrote:

{Quote hidden}

--
 *
 |  __O    Thomas C. Sefranek   tcsspamspam_OUTcmcorp.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#nomail Going offline? Don't AutoReply us!
use @spam@listservKILLspamspammitvma.mit.edu?body=SET%20PICList%20DIGEST




2000\10\13@080542 by Olin Lathrop

flavicon
face
> Here's extracts of my code. Can anyone spot the bug?

Yes, I can.  However I don't believe in helping those who haven't even done
the simple little things to help themselves.  There is not a single comment
in the first section of code below.  Go back and force yourself to explain
what you think each instruction is doing, and there's a reasonable chance
you'll figure out the problem on your own.  Another suggestion is to look
over the instruction set again.  You are doing some things the hard way.

{Quote hidden}

*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, KILLspamolinKILLspamspamcognivis.com, http://www.cognivis.com

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu




2000\10\13@110326 by jamesnewton

face picon face
Olin's personality doesn't always rub me the right way, BUT...

...he IS right, I think, in that commenting code helps to find bugs.

Now, that doesn't mean that other people can't help out and point out the
obvious bug, I just wanted to try to get past the... personality issues...
and point out that going over this code and commenting it would be a good
way to find the problem.

Especially if you did the commenting by looking up the instructions and
reading their function.

---
James Newton (PICList Admin #3)
spamBeGonejamesnewtonspamBeGonespampiclist.com 1-619-652-0593
PIC/PICList FAQ: http://www.piclist.com or .org

{Original Message removed}

2000\10\13@133049 by Scott Dattalo

face
flavicon
face
On Thu, 12 Oct 2000, Paul Reilly wrote:

>
> Here's extracts of my code. Can anyone spot the bug?

I see three.

{Quote hidden}

   clrf offset

>
>                 movlw   ">"
>                 call    send_ascii
>
>                 movlw   LOW TABLE
>                 addwf   offset

;since offset may've changed in send_ascii, it's safer to do this:

     movf   offset,w
     andlw  3            ;There are only 4 entries
                         ;so make sure the upper bits are cleared
     addlw  LOW(TABLE)
     movwf  offset

{Quote hidden}

but I'd probably just implement this so:


fetchchar:
   movwf  offset
   movlw  HIGH(TABLE)
   movwf  PCLATH          ;okay now, this get's used only at the branch

   movf   offset,w
   andlw  3               ;only 4 table entries
   addlw  LOW(TABLE)      ;add the base of the table
   skpc
    incf  PCLATH,F        ;oops, crossing 256 byte boundary

   movwf  PCL

TABLE:
   dt "A"
   dt "B"
   dt "C"
   dt "D"

and then in the main code:

   movlw  ">"
   call   send_ascii   ;display a ">"

   movlw  0            ;get first character in the table
   call   fetchchar
   call   send_ascii   ; display it

   movlw  1            ;get second character in the table
   call   fetchchar
   call   send_ascii


   movlw  "<"
   call   send_ascii


I think it makes more sense to place the table offset calculation along with the
table.

Scott

PS. look at the archives for even better ways to display strings.

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu




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