David, 1) Your label "times1.5", although it's only defined once (as a label in TEST.ASM), appears in TEST.INC in an EXTERN statement. You have #included TEST.INC proper in TEST.ASM, but you also #include it in MAIN.ASM. There is no label "times1.5" that appears in MAIN.ASM. I think you misunderstand the purpose for using an #include file. Typically, EXTERN statement should be in the file where the label appears and no where else. 2) For the label ACC0, see above. Douglas Wood Software Engineer dbwood@kc.rr.com Home of the EPICIS Development System for the PIC and SX http://www.piclist.com/techref/member/DW--RA4 ----- Original Message ----- From: "David Cary" To: Sent: Thursday, April 05, 2001 5:44 PM Subject: [PIC]: MPASM include files > Dear Pic'ers, > > I've found lots of very clever little PIC assembler fragments on > http://piclist.org/ . Now I'm looking for advice on how to structure an entire > project. > I'm getting unexpected errors from MPASM now that I've split up my project into > several files. Maybe I just need to learn the ``Assembly Way'' of doing things. > > I'm used to the ``C Way'' of breaking up a program into several files, as > explained in the C FAQ: > http://www.faqs.org/faqs/C-faq/faq/ >
> 1.7: What's the best way to declare and define global variables > and functions? > > A: First, though there can be many "declarations" (and in many > translation units) of a single "global" (strictly speaking, > "external") variable or function, there must be exactly one > "definition". (The definition is the declaration that actually > allocates space, and provides an initialization value, if any.) > The best arrangement is to place each definition in some > relevant .c file, with an external declaration in a header > (".h") file, which is #included wherever the declaration is > needed. The .c file containing the definition should also > #include the same header file, so that the compiler can check > that the definition matches the declarations. >
> > Unfortunately, I seem to get a lot of errors like > Error[115] C:\DAVID\GRAPHI~1\LCD_CO~1\TEST.ASM 4 : Duplicate label > ("times1.5" or redefining symbol that cannot be redefined) > Error[115] C:\DAVID\GRAPHI~1\LCD_CO~1\TEST.ASM 5 : Duplicate label ("ACC0" > or redefining symbol that cannot be redefined) > The odd thing is, MPASM claims there is a "duplicate", yet it only shows an > error in one place. When I accidentally make ``real'' duplicates, MPASM usually > shows me both places. Is this a bug in MPASM ? > > I seem to get some kind of error no matter how I tweak my ``test.inc'' file. If > I replace ``EXTERN'' with ``GLOBAL'' in that file, I get > Error[113] C:\DAVID\GRAPHI~1\LCD_CO~1\MAIN.ASM 38 : Symbol not previously > defined (times1.5) > Error[113] C:\DAVID\GRAPHI~1\LCD_CO~1\TEST.INC 17 : Symbol not previously > defined (ACC0) > . > > Here's my 3 test files: test.inc, test.asm, main.asm > > ; test.inc > > ; subroutines > EXTERN times1.5 > ; parameters for subroutines (registers) > EXTERN ACC0 > EXTERN ACC1 > EXTERN TEMP0 > EXTERN TEMP1 > > ; end file test.inc > > > ; test.asm > INCLUDE test.inc ; module definition file > > shared_math_stuff UDATA_shr > ACC0 res 1 > ACC1 res 1 > TEMP0 res 1 > TEMP1 res 1 > > > test_subs CODE > > > > times1.5: > ; ACC = ACC * 1.5 > ; Temp = TEMP > ; ACC size = 8 bits > ; Error = 0.5 % > ; Bytes order = little endian > ; Round = yes > ; > ; ALGORITHM: > ; Clear accumulator > ; Add input * 2 to accumulator > ; Add input * 1 to accumulator > ; Shift accumulator right (LSb to carry) > ; If carry set, increment accumulator > ; Move accumulator to result > ; Approximated constant: 1.5, Error: 0 % > ; Input: ACC0, 8 bits > ; Output: ACC0 .. ACC1, 9 bits > ; Code size: 20 instructions > ; > ;copy accumulator to temporary > movf ACC0, w > movwf TEMP0 > > ;shift temporary left 1 times > clrc > rlf TEMP0, f > clrf TEMP1 > rlf TEMP1, f > > ;add temporary to accumulator > clrf ACC1 > movf TEMP0, w > addwf ACC0, f > movf TEMP1, w > skpnc > incfsz TEMP1, w > addwf ACC1, f > > ;shift accumulator right once and > ;increment if carry set > rrf ACC1, f > rrf ACC0, f > skpc > goto no_inc > incf ACC0, f > skpnz > incf ACC1, f > no_inc > > ; Generated by www.piclist.com/cgi-bin/constdivmul.exe (November 17, 2000 > version) > ; Thu Apr 05 17:18:58 2001 GMT > > > > > > END > ; end file test.asm > > > > > ; main.asm > LIST P=PIC16F877 > INCLUDE P16F877.INC ;INCLUDE REGISTER DEFINITION FILE > INCLUDE test.inc ; module definition file > > > > ; ================ > ; Reset vector > STARTUP CODE 0x0000 > RESET: > NOP ;REQUIRED BY ICD > PAGESEL beginning > GOTO beginning ;INITIALIZE PROCESSOR AFTER RESET > > shared_stuff UDATA_shr ; Let linker allocate space for these. > ISR_W res 1 ; must be in a ``global'' register or in every page at > the same offset. > idle_count res 4 > > endtime res 2 > > ; 16 bit return value from read_timer1(). > TMPH res 1 > TMPL res 1 > > > beginning CODE > > beginning: > BCF INTCON,7 ;GLOBALLY DISABLE INTERRUPTS > BTFSC INTCON,7 ;BRANCH IF INTERRUPTS ARE DISABLED > GOTO RESET ;ELSE, TRY TO DISABLE AGAIN > > MAINLP: > > ; [FIXME: do something useful here] > CALL times1.5 > > GOTO MAINLP > END > ; end file main.asm > > -- > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads