PIC dt directive

Feb 11, 2007 5 Replies

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

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)

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.

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 ?

  1. This seems to make no sense

movwf 0x00

move w into f, to where ? 0x00 ?

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

  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.

  1. 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"

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required