Myke's Home Page
|
"Table0" ExperimentThis experiment demonstrates basic table calls in the mid-range PICmicro® microcontroller. The table can only reside within the first 256 addresses of program memory and PCLATH can never be modified. The problems with going over the first 256 address boundary is demonstrated in this application. Despite these limitations, the basic table read implementation is useful in many applications.
The source code listed below can be accessed from the CD-ROM by clicking Here.
title "Table0 - Mid-Range Page0 Table Calling."
;
; An invalid Table Read is implemented.
;
;
; 99.11.14 - Updated for Second Edition
;
; Myke Predko
; 96.05.17
;
LIST P=16F84, R=DEC
INCLUDE "p16f84.inc"
; Registers
CBLOCK 0x020
i,Dest:4, Temp
ENDC
__CONFIG _CP_OFF & _WDT_OFF & _RC_OSC
PAGE
; Mainline of Table0
org 0
movlw ' ' ; Initialize "Dest" so it can be seen
movwf Dest + 0
movwf Dest + 1
movwf Dest + 2
movwf Dest + 3
; Table Read, Get values in Table until they equal Zero.
clrf i ; Use "i" as the Index
movlw Dest + 3 ; Point to the Destination
movwf FSR
Table1_Loop ; Loop Around Here until finished
movf i, w ; Get the Index into the Table
incf i, f ; Increment the Table Index
call Table1 ; Call the Table
iorlw 0 ; At Table End?
btfsc STATUS, Z
goto Table1_Skip
movwf INDF ; No - Store the Returned Value
decf FSR, f ; Point to Next Position in "Dest" Array
goto Table1_Loop
Table1_Skip
clrf i ; Same as Previous, but Different Page Table
movlw Dest + 3
movwf FSR
Table2_Loop
movf i, w
incf i, f
call Table2
iorlw 0
btfsc STATUS, Z
goto Table2_Skip
movwf INDF
decf FSR, f
goto Table2_Loop
Table2_Skip
clrf i ; Same as Previous, but Table "Straddling" 256 Instruction Boundary
movlw Dest + 3
movwf FSR
Table3_Loop
movf i, w
incf i, f
call Table3
iorlw 0
btfsc STATUS, Z
goto Table3_Skip
movwf INDF
decf FSR, f
goto Table3_Loop
Table3_Skip
goto $ ; All Done, Go to Infinite Loop
Table1
addwf PCL, f ; Get the Table Offset
retlw 't'
retlw 'a'
retlw 'b'
retlw '1'
retlw 0 ; End the String
org 0x0100 ; Second 256 Instruction Jump
Table2
movwf Temp ; Save the Table Offset
movlw HIGH $
movwf PCLATH
movf Temp, w ; Jump to the Table Address
addwf PCL, f
dt "TAB2", 0
org 0x01FA ; This Table goes over a 8 Bit (256 Address) Boundary
Table3
movwf Temp ; Save the Table Offset
movlw HIGH $
movwf PCLATH
movf Temp, w ; Jump to the Table Address
addwf PCL, f
dt "tab3", 0
end
|