Table Program Example
The following example shows how the table pointer and table data is defined and retrieved from the
microcontroller. This example uses raw table data located in the Program Memory which is stored
there using the ORG statement. The value at this ORG statement is
²
700H
²
which refers to the start
address of the last page within the 2K words Program Memory of the device. The table pointer is setup
here to have an initial value of
²
06H
²
. This will ensure that the first data read from the data table will be
at the Program Memory address
²
706H
²
or 6 locations after the start of the last page. Note that the
value for the table pointer is referenced to the first address of the present page if the
²
TABRD [m]
²
instruction is being used. The high byte of the table data which in this case is equal to zero will be
transferred to the TBLH register automatically when the
²
TABRD [m]
²
instruction is executed.
Because the TBLH register is a read-only register and cannot be restored, care should be taken to
ensure its protection if both the main routine and Interrupt Service Routine use table read instructions.
If using the table read instructions, the Interrupt Service Routines may change the value of the TBLH
and subsequently cause errors if used again by the main routine. As a rule it is recommended that
simultaneous use of the table read instructions should be avoided. However, in situations where
simultaneous use cannot be avoided, the interrupts should be disabled prior to the execution of any
main routine table-read instructions. Note that all table related instructions require two instruction
cycles to complete their operation.
Tempreg1
db ?
; temporary register #1
tempreg2
db ?
; temporary register #2
:
:
mov a,06h
; initialise low table pointer - note that this address
mov tblp,a
; is referenced
mov a,07h
; initialise high table pointer
mov tbhp,a
:
:
tabrd tempreg1
; transfers value in table referenced by table pointer data at
; program memory address
²
706H
²
transferred to tempreg1 and TBLH
dec tblp
; reduce value of table pointer by one
tabrd tempreg2
; transfers value in table referenced by table pointer data at
; program memory address
²
705H
²
transferred to tempreg2 and TBLH in
; this example the data
²
1AH
²
is transferred to tempreg1 and data
;
²
0FH
²
to register tempreg2
:
:
org 700h
; sets initial address of program memory
dc 00Ah, 00Bh, 00Ch, 00Dh, 00Eh, 00Fh, 01Ah, 01Bh
:
:
Rev. 1.50
22
April 28, 2020
BS83B08-3/B12-3/B16-3/B16G-3/C24-3
8-Bit Touch Key Flash MCU