PIC18 cheatsheet

TBLWT*

Detailed reference for the TBLWT* instruction in PIC18 ISA.

Description

Store the 8‑bit contents of WREG into the memory location pointed to by the table pointer (TBLPTR) and the table page register (TBLPAG).

  • The instruction name is TBLWT (Table Write). It has no operands; the destination address is formed from the high byte of TBLPTR and the 8‑bit TBLPAG value.
  • After executing TBLWT, the data in WREG is written to SRAM in the selected table page.
  • The instruction should be used only when the Table Pointer has been correctly initialized by loading TBLPTRL, TBLPTRH (and optionally TBLPTRU for 16‑bit) and setting TBLPAG.
TBLWT

Examples

; Example 1: Write 0x12 to table address 0x0000 (default page 0)
MOVLW 0x12
TBLWT
; Example 2: Set table page to 1 and write 0x22 to address 0x0100
MOVLW 0x22
MOVWF TBLPAG
MOVLW 0x00
MOVWF TBLPTRL
MOVLW 0x01
MOVWF TBLPTRH
TBLWT
; Example 3: Write 0x44, then read back with TBLRD
MOVLW 0x44
TBLWT
MOVLW 0x00
TBLRD