> I've been looking at the table command of the 18F, and am > trying to figure out the syntax. > > On the 16F, it was simply.... > > d_user ;default code > addwf PCL,f > dt "6781234",0D DT generated a series of RETLW instructions in consecutive program memory locations. The ADDWF was using the value in W to offset into your table. (Code does not deal with the possible overflow into the next 256 byte memory segment.) > readit > call d_user ;get table value of user code > movwf gotit ;stick it in > return > > ---------------------- > The 16F to 18F migration example shows.... > > RdStr Upper byte (highest 5 bits) of TBLPTR is not being initialized. You need to have either a CLRF TBLPTRU ; only works with .LE. 64KB of program memory or MOVLW UPPER string MOVWF TBLPTRU, ACCESS ; works on any size program memory > movlw HIGH(string) > movwf TBLPTRH ; load high byte of pointer (0x12) > movlw LOW(string) > movwf TBLPTRL ; load low byte of pointer (0x34) > > read tblrd*+ ; read byte from program memory, > ; and increment pointer one byte > movff TABLAT,PORTB ; move byte from table latch to output port B > tstfsz TABLAT ; was retrieved byte a null? > goto read ; no, do loop again > return GOTO READ is overkill since target of the jump is obviously within 1000 bytes; I'd use a BRA READ which only takes 2 bytes. > ORG 0x1234 > String DW "This is a test.",0x00 ; text string > > _________________ > > > So do I simply write; > > d_user ;default code > dw "6781234",0D I'd use a DB since that defines bytes. DW is documented as being equivalent to a DB on the 18 series, but I think DB is clearer. > readit > movlw HIGH(d_user) > movwf TBLPTRH ; load high byte of pointer > movlw LOW(d_user) > movwf TBLPTRL ; load low byte of pointer > ; > tblrd* ; read byte from program memory, > movff TABLAT,gotit ; move byte from table This code will always loads the first byte from the table into gotit. Your original code loaded the Nth byte, where N was stored in W upon entry to the routine. This version also only works if program memory is 64KB or smaller. I'd write it as (and I believe that the textual description of routine's functionality is not optional): ; readit - function to return Nth octet from a d_user table in ; program memory, where N is an unsigned 8-bit offest contained in ; WREG on entry. On return, 8-bit value retrieved has been stored ; in gotit variable. ; ; routine trashes WREG, STATUS, TBLPTR, & TABLAT ; readit MOVLW UPPER d_user MOVWF TBLPTRU, ACCESS ; load upper byte of pointer MOVLW HIGH d_user MOVWF TBLPTRH ; load high byte of pointer MOVLW LOW d_user MOVWF TBLPTRL ; load low byte of pointer ; ADDWF TBLPTRL, F, ACCESS CLRF WREG, ACCESS ADDWFC TBLPTRH, F, ACCESS ADDWFC TBLPTRU, F, ACCESS ; adjust pointer to Nth element (N in WREG) ; tblrd* ; read byte from program memory into TABLAT ; movff TABLAT, gotit ; store byte into specified destination ; RETURN This should have the same functionality as your original 16F code. And work in any size memory version 18 series PIC. Lee Jones -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist