Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 20th August 2007, 01:30 PM   (permalink)
Default PIC 8-bit-boundary macro?

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
Mike, K8LH is offline  
Reply With Quote
Old 20th August 2007, 02:10 PM   (permalink)
Default

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
Pommie is online now  
Reply With Quote
Old 20th August 2007, 02:17 PM   (permalink)
Default

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
ericgibbs is online now  
Reply With Quote
Old 20th August 2007, 03:52 PM   (permalink)
Default

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
Mike, K8LH is offline  
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Timer0 Prescale lord loh. Micro Controllers 10 8th October 2008 05:13 PM
Sync Problem Marc_Urito Micro Controllers 3 29th April 2007 03:21 PM
Validating Code Without PIC burg Micro Controllers 4 22nd April 2007 04:14 PM
Where to disable the GIE bit on a PIC interrupt? blueroomelectronics Micro Controllers 2 7th February 2007 03:27 AM
Newcomers, please read! (PIC regarded) Upd. 0xD Jay.slovak Micro Controllers 0 17th April 2005 01:04 PM



All times are GMT. The time now is 07:36 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.