Ricardo D. Medina wrote : > I am trying my hand at relocatable code (using assembler for > 16F628 and 16F877 parts), but I fell into a bit of a blind hole... > > The code is structured in three files: > delay.o -> contains various delay subs, which are totally > independent from the main program > lcd.o -> contains the LCD subs > main.o -> contains the main program flow, what I want to > display, etc. OK. so those are pre-assembled files then. The problem here is that any assemply-time calculations or ifdef's/endif's have already been "done", so you are more or less stuck with whatever is in those .o files. This is *the* reason why many don't use object libs with PIC development, you loses all assembly time calculations and pre-processing. Note, that using "libraries" of ASM files, isn't any problem at all vis-a-vis relocatioble code... > > At first I statically set the port and bits to control the > LCD inside lcd.o, > but afterwards I decided that the whole point of using > relocatable code is to be able to port it to other projects as > easily as possible... Yes, but keeping the "common" routines in ASM format, makes things easier and more flexible. > So, from > then on, I used six variables in the lcd.o object file which would be > defined in the main.o file. (the idea behind this is to be > able to change the ports and bits used by the LCD, depending on the > complexity or needs of the project.) > > So I defined: > LCTRL -> The port which has the LCD control lines (RS, RW, EN) > LBUS -> The port which holds the LCD data/address > LBUST -> LBUS direction control (LBUS's TRIS register) > RS -> Bit n: for the RS line > RW -> Bit n: for the RW line > EN -> Bit n: for the EN line. > > The problem is that I can assign the registers in main.o, but > not the bits!! You can't assign anything in an .O file. You do that in the ASM file, right ? > For example: > LPORTS UDATA 0x05 > LCTRL RES 1 ; Set LCTRL as PORTA > LBUS RES 1 ; Set LBUS as PORTB > > LTRIS UDATA 0x86 > LBUST RES 1 ; Set LBUST as TRISB And that must be in an ASM file, not an .O file... > > and afterwards I set them global.... no problem there.... but I still > haven't found a way to specify the three control bits in the > main file, and getting them to be global! > > Can anyone give me a clue, or is the only way to do it to use > a mask (like, > if I want EN to be bit 2, I set a register as EN and I set > it's 2nd bit, so > if I want to " bsf LCTRL,EN " instead I do: If you use assembler symbols to keep your bit number it works, and you save a GPR also. > I'm very sorry to take up your time, He he, you are not, if I don't let you :-) :-) > If anyone can shed > some light, I'd greatly appreciate it. I think that if you look at it again, and think about having your "library" routines as ASM files, you'll see that things will work out a bit easier. You can take full advantage of the assembly time calculations, symbols and pre-processing. Jan-Erik. -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body