Myke's Home Page

Book CD-ROM Home

File Copying/Harddrive Setup

Development Tools

Experiments

Projects

Useful Code Snippets and Macros

Introduction to Electronics

Introduction to Programming

Datasheets

PCBs

Links

McGraw-Hill Professional Publishing

"ArbTable" Experiment

This 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.

"ArbTable" uses the general case table read routine:

MSGTable			;  Place all the Messages Here
  movlw  HIGH TableStart	;   Setup PCLATH for the Table
  addwf  TableOff + 1, w
  movwf  PCLATH
  movlw  TableStart & 0x0FF	;  Figure out the Offset
  addwf  TableOff, w
  btfsc  STATUS, C		;  If Necessary, Increment PCLATH
   incf  PCLATH, f		;   to get the Correct 256 Address Page
  movwf  PCL			;  Update the PC
TableStart			;  Table Data
              
which will allow for tables larger than 256 addresses placed anywhere in the PICmicro's program memory.

The source code listed below can be accessed from the CD-ROM by clicking Here.

 title  "ArbTable - Tables Longer than 256 Entries."
;
;  This Program demonstrates how a table that is longer than
;   than 256 entries (and therefore, jumps over the 256 "addwf PCL"
;   Page boarder).
;
;  99.11.14 - Updated for the Second Edition
;
;  Myke Predko
;  97.02.19
;
  LIST P=16F84, R=DEC
  INCLUDE "P16F84.inc"

 __CONFIG _CP_OFF & _WDT_OFF & _RC_OSC

;  Registers
 CBLOCK 0x020
TableOff:2			;  Offsets into the Table
Temp
 ENDC

  PAGE
;  Mainline of ArbTable

  org 0

  movlw  9			;  Get the 10th Message
  call   GetMSG

  goto   $			


GetMSG				;  Figure Out where the Specified
				;   Message is
  movwf  Temp			;  Save the Message Count

  clrf   TableOff		;  Reset the Table Values
  clrf   TableOff + 1

GM_Loop

  movf   Temp, f		;  If Temp == 0, then Stop Search
  btfsc  STATUS, Z
   goto  GM_End

  call   MSGTable		;  get the Value in the Table

  iorlw  0			;  Are we at the End of a Message?
  btfsc  STATUS, Z
   decf  Temp, f		;   Yes - Decrement Temp

  incf   TableOff, f		;  Point to the Next Table Element
  btfsc  STATUS, Z
   incf  TableOff + 1, f

  goto   GM_Loop

GM_End				;  Tbllo/TblHI Now Point to the
				;   First Character in the Specified
  return			;   Message


MSGTable			;  Place all the Messages Here
  movlw  HIGH TableStart	;   Setup PCLATH for the Table
  addwf  TableOff + 1, w
  movwf  PCLATH
  movlw  TableStart & 0x0FF	;  Figure out the Offset
  addwf  TableOff, w
  btfsc  STATUS, C		;  If Necessary, Increment PCLATH
   incf  PCLATH, f		;   to get the Correct 256 Address Page
  movwf  PCL			;  Update the PC

TableStart			;  Table Data
Msg0
  dt	 "This is the First Message", 0
Msg1
  dt	 "This is the Second Message", 0
Msg2
  dt	 "This is the Third Message", 0
Msg3
  dt	 "This is the Forth Message", 0
Msg4
  dt	 "This is the Fifth Message", 0
Msg5
  dt	 "This is the Sixth Message", 0
Msg6
  dt	 "This is the Seventh Message", 0
Msg7
  dt	 "This is the Eigth Message", 0
Msg8
  dt	 "This is the Nineth Message", 0
Msg9
  dt	 "This is the Tenth Message", 0


  end
              

Click Here to look at the sixteenth experiment - SmallTbl