Hello Thomas & PIC.ers, I can give you the end result of my own head-bangin on this one. Following other's advice, I now reserve things this way: Page0 for unavoidable things like TMR0 isr, main loop code and state table. Page1... Page2... Page3 for subroutines of a 'like kind', that is they group naturally together in function and often want to call each other. [ starts with org .] ;************ START OF PAGE3 ROUTINES org 0x1800 ;page3 code 0x1800 >> 0x1FFF .. .. ---------------------------------------- Page1 & Page2 also have kindred subroutines in them, you *could* have macros for travelling around any which way you wanted but so far I've been able to write all my code using Page0 as `master' and other pages as `slaves'. The important thing is that you don't allow your ever-expanding code to just roll-over into the next page. When you get near that point start looking for ways to encapsulate functions and emigrate them to an appropriate subroutines page. You *do* know (of course..) that isr (running in Page0) must have comprehensive context-push-pop to keep you out of cuckoo-land. Calls and gotos within a page are invoked normally, that is by using,, well,,.... CALL, GOTO :) Since the mainline code resides in Page0, it will often want to run subroutines sitting in Page3. These are called EVERY TIME by using a macro --- gosub_p0_3 MACRO subrtn ;Perform a "call subroutine" to page3 rom &return pclath to page0 int_off ;macro to turn off isr, to prevent page ;tangling during next two instructions bsf pclath,4 bsf pclath,3 int_on ;enable ints again call subrtn ; keep ints enabled during the sub. int_off bcf pclath,4 bcf pclath,3 ;return to original page (Page0) int_on ENDM So, to call a page3 routine (eg BCDtoBIN) from within page0:- gosub_p0_3 BCDtoBIN ;routine BCDtoBIN lives in page3 Sometimes you'll want to call a routine in page0, when the pc is in a subroutine in page3 (it's untidy, but what *is* tidy in this context..?) You just need a macro, gosub_p3_0 to do the opposite of the first example. (writing it is left as an exercise for the student) Sticking to this kind of military drill, you won't go wrong as long as you don't try to cut corners. There might be a way to do all this `globally' with a single call type, but I seem to remember attempting it with abject failure >> gave up in disgust muttering dark curses upon uchip. >Date: Thu, 5 Jul 2001 19:38:10 -0000 >From: Thomas N >Subject: [PIC]: Please help! Global Calls and Global Gotos > >Hello everyone! > >I am coding the PIC16F877 and my code has grown more than 2K. Now I have >some problems with CALLs and GOTOs instructions when the code is not on Page >0. I read the "Paging and PCLATH " section on the PlCList archive, but I am >still not sure how to write the code for long call or long goto. The >"sample code" there is in psedocode form. :( > >Is there any codes out there that can do Global Call? Global Goto? >(Meaning I can use the same call or goto instruction from any page) If any >of you have them, please send me a copy. It will be greatly appreciated! > >Thank you in advance! >Sincerely, >Thomas best regards, John e-mail from the desk of John Sanderson, JS Controls. Snailmail: PO Box 1887, Boksburg 1460, Rep. of South Africa. Tel/fax: Johannesburg 893 4154 Cellphone no: 082 741 6275 email: jsand@pixie.co.za Manufacturer & purveyor of laboratory force testing apparatus, and related products and services. -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads