I've run across some really strange things with registers that shouldn't ha= ve anything to do with the ports functions, yet they do. But since you hav= e code that works, I'd guess that something isn't set the way you think it = is. I'd pull all of those registers into the watch window, not just the PORT/LA= T but everything, and do a snapshot of the code that's working....and again= same registers with it not working and do a brute force comparison and I b= et that there are some differences. That's how I've found some of those re= ally strange bugs, and I can relate to your frustrations of....it should be= working but its not! -----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of= Dwayne Reid Sent: Tuesday, May 08, 2018 11:45 AM To: pic microcontroller discussion list Subject: [PIC] Troubles implementing relocatable code Good day to all. I've been struggling for the past many weeks trying to get my head around s= tructuring my code around the relocatable paradigm. Thanks to help from pe= ople here as well as the many Internet resources, I think that I've mostly = got a handle on it. In particular, Jan-Eric's web pages about the differen= ces between absolute and relocatable code and Olin Lathrop's PICdev stuff h= ave been invaluable. But - I'm having really strange problems and I can't figure out what I'm do= ing wrong. This particular project is using 16F1782 and I'm currently using a PICkit 3= for debugging. First: I should mention that I'm not using Microchip's include files. Inst= ead, my source code contains every register and bit explicitly defined. Th= is is a carryover from the days when Microchip's include files were riddled= with errors and I just haven't bothered to change my way of doing things. = One advantage is that each bit is described so that I can easily create or= understand what is happening with each byte / configuration register. The= other advantage is that the register address is explicitly embedded into t= he bit name - this means that I call the bit name and the register address = is automatically populated. I find this to be an enormous time saver and e= rror-eliminator. Now to my problem. I have two identical versions of my code: one written t= he way I have been doing all these past many years in absolute mode. The o= ther version has been modified to be relocatable. Both compile (assemble) = without errors and the version written for absolute mode works correctly (s= o far - I'm still debugging). But the version written in relocatable mode = is having issues. Hardware-type issues. Here's a brief description of some of the problems that I'm seeing. All 8 pins of port RA feed the segments of a 4-digit multiplexed common-cat= hode 7-segment display. Pins RC0..RC3 feed the digit select pins of the di= splay. 1) Pin RA7 tris bit appears to be always set. I wasn't sure if my problem = was with the tris bit or the odcon bit but I have verified that the pin app= ears to be an input rather than just open-drain. Symptom: none of the "A" segments (top row) on the display light up for any= of the 4 digits. I set a breakpoint just before that digit gets written a= nd have the following registers in my watch window:=20 WREG, PORTA, LATA, TRISA, ODCONA. As I single-step, I see that W is loaded= with the correct data (numeric digit "3"), that value is written to LATA b= ut PORTA bit7 remains LO. TrisA & ODconA are all at 0x00 (all CMOS outputs). If I inject a small current onto pin RA7, I see t= he segment illuminate. So: that means that either the pin is Open-Drain (c= an't source current) or an input (Tris bit RA7 is HI). While the program i= s still halted, I simply change the value of port RA to 0x00 and try to inj= ect current into each of the port RA pins. All pins except RA7 are outputs= (and LO) but RA7 is an input. Symptom: After playing around with the above for a while, I add all of the = registers for port RC to the watch window. Reset the PIC back to the begin= ning and run to the breakpoint where digit 3 is about to be illuminated. S= ingle-step to the point where digit 3 is illuminated and I observe that the= appropriate digit-select line on port RC is NOT correctly showing the stat= e of that bit: all 4 digit select lines are shown as being HI instead of 3 = bits HI and one bit LO. This is obviously not correct because the digit on= the display is illuminated, which means that the digit select line is LO. = But it is not shown that way in MPLAB. All of the above problems go away if I go back to the version of code writt= en in absolute mode. Why this is important to me (and this project): I want to be able to use th= e Emulation Debug Module for this processor family (AC244064). This gives = the PICkit3 up to 32 available breakpoints (instead of just 1) and if I use= one of my Real-ICE units, gives me pretty much all of the functionality of= the ICE2000 (nested breakpoints, etc). But that AC244064 works only with = MPLAB-X and MPLAB-X now appears to work only with relocatable code. I'm obviously doing something wrong but I just can't see it. Guidance appr= eciated. Many thanks! dwayne --=20 Dwayne Reid Trinity Electronics Systems Ltd Edmonton, AB, CANADA 780-489-3199 voice 780-487-6397 fax 888-489-3199 Toll Free www.trinity-electronics.com Custom Electronics Design and Manufacturing -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/chang= e your membership options at http://mailman.mit.edu/mailman/listinfo/piclis= t --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .