Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC 8-bit-boundary macro?

Status
Not open for further replies.

Mike - K8LH

Well-Known Member
Has anyone come up with a macro that could test a table to see if it straddles a 256-byte boundary and then insert the 'short' or 'long' code as necessary?

Code:
;
        addwf   PCL,W           ;
;
tbl
Code:
;
        movwf   Temp            ; save index
        movlw   high (tbl)      ;
        movwf   PCLATH          ;
        movf    Temp,W          ;
        addlw   low (tbl)       ;
        skpnc                   ;
        incf    PCLATH,F        ;
        movwf   PCL             ;
;
tbl
 
This is what I use to use a long time ago before the readable flash chips. It's not exactly what you want but may give you an idea. Turning it into a macro would be a lot easier if there was a length command. I wrote a little macro in excel (VBA) that produced a .asm file from a list of strings. As MPLAB always includes from disk, I could treat the xls file as just another source file.

Mike.

Code:
JumpMessage	addwf	PCL,F
StartMessage
Mess_E.0	equ	$-StartMessage
		goto	Message00
Mess_E.1	equ	$-StartMessage
		goto	Message01
Mess_E.2	equ	$-StartMessage
		goto	Message02
Mess_E.3	equ	$-StartMessage
		goto	Message03
Mess_E.4	equ	$-StartMessage
		goto	Message04
Mess_E.5	equ	$-StartMessage
		goto	Message05
Mess_E.6	equ	$-StartMessage
		goto	Message06
Mess_E.7	equ	$-StartMessage
		goto	Message07
Mess_E.8	equ	$-StartMessage
		goto	Message08

		if	high($+1) != high($+4+15)
		org	(high($)+1) * 256 -3
		endif
Message00	movlw	high($+5)
		movwf	PCLATH
		movfw	MessageCount
		addwf	PCL,F
		dt	"Critical Error",0

		if	high($+1) != high($+4+14)
		org	(high($)+1) * 256 -3
		endif
Message01	movlw	high($+5)
		movwf	PCLATH
		movfw	MessageCount
		addwf	PCL,F
		dt	"Error Number_",0
 
hi,
Example, not coded by me, author unknown.

Code:
 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).
;
   
  LIST p=16f877,f=inhX32
  #include <p16f877.inc>
  __CONFIG _CP_OFF & _WDT_OFF & _RC_OSC

;  Registers
 CBLOCK 0x20
TableOff:2
Temp  
 ENDC

;  PAGE
;  Mainline of ArbTable

  org 0
loop:
  movlw 9			;  Get the 10th Message
  call   GetMSG

	MOVF 0X20,W
	MOVWF PCLATH
	MOVF 0X22,W
 


	NOP
  nop
  goto   loop


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  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 #1", 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
 
Thank you for the examples Gentlemen. Always a help to look at a problem from others perspective and you've given me plenty of ideas to start coding and simulating.

Have a great day. Mike
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top