PIC dt directive

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View


Gudday

How does this work and how do you call it in assembly ?

 TAB       addwf     PCL,F            ; Move offset to PC lower

   DT        "PROGRAM TEST RS232 PORT ON CPU PIC16F877 RUN FREQ
10MHz",0X0A,0X0D



Re: PIC dt directive


DT will produce a series of RETLW kk instructions.  For example the
code you supplied is the equivalent of:


TAB     addwf   PCL,f           ; Move offset to PC lower

        retlw   0x50            ; ASCII "P"
        retlw   0x52            ; ASCII "R"
        retlw   0x4F            ; ASCII "O"
        retlw   0x47            ; ASCII "G"
        retlw   0x52            ; ASCII "R"
        retlw   0x41            ; ASCII "A"
        .
        .
        .
        .
        retlw   0x0A
        retlw   0x0D


To call it in assembly load an offset into W then "call TAB", for
example:

        movwf   0x00
        call    TAB             ; after this 0x50 (or "P") should now
be in the W register

        movwf   0x03
        call    TAB             ; after this 0x47 (or "G") should now
be in the W register


Normally in a situation like the above, you'd have some variable
acting as an up-counter (0,1,2,3,4,5,etc) and you copy this variable
to W register before "call TAB".  After which the W register now
carries the item in the table, which you can now send elsewhere
(probably to the serial port)



Quoted text here. Click to load it



Re: PIC dt directive


Ta - I get that dt is the same as retlw,

Have some more questions

1. What is this doing ? addwf   PCL,f

Thats says to me add what is in W to PCL.

But PCL is the program counter ?

2. This seems to make no sense

 movwf   0x00

move w into f, to where ? 0x00 ?



Quoted text here. Click to load it



Re: PIC dt directive


1.  Yes you're correct.  You are adding an offset (which is in W) to
the program counter.  This allows you to select which particular
"retlw" you want to use.

2.  Yes you're correct.  It makes no sense because I made a
mistake :-)  They should be (as you've worked out) "movlw 0x00" and
"movlw 0x03" in my examples, NOT "movwf"

Quoted text here. Click to load it



Re: PIC dt directive


Ok I did it in MPLAB and all is good

         movlw 0x00  ; set start of table
         movwf offset  ; set this for the TAB function

here   movfw offset      ; move into W, offset in table
          call      TAB  ; get the character from the table, according to
offset
          movwf TXREG  ; send that character out (ignoring hand shaking)
          incf      offset,f  ; get the next character by inc offset
          goto      here      ; Send again

TAB   addwf     PCL,F            ; Move offset to PC lower
           DT        "PROGRAM TEST RS232 PORT ON CPU PIC16F877 RUN FREQ
10MHz",0X0A,0X0D
           end     ;end progra



Quoted text here. Click to load it



Re: PIC dt directive



DT gets turned into a lot of retlw instructions. Try looking at the
disassembly code in MPLAB.

You need to make sure that it is all contained in the same 256 byte block.
You then call TAB with W containing the offset to the character you want.

Mike.

Quoted text here. Click to load it



Site Timeline