Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Symbol definition error in MPLAB IDE (for pic16f84)

Status
Not open for further replies.

trailrider

New Member
Hi

I'm really really new to PIC programming and am trying to get a motor control program running but MPLAB IDE v6.61 doesn't want to compile the code (copied below)


list p=16F84A ; list directive to define processor
#include <p16F84.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC

; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.




;***** VARIABLE DEFINITIONS (examples)

; example of using Uninitialized Data Section
INT_VAR UDATA 0x0C
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving

; example of using Overlayed Uninitialized Data Section
; in this example both variables are assigned the same GPR location by linker
G_DATA UDATA_OVR ; explicit address can be specified
flag RES 2 ; temporary variable (shared locations - G_DATA)

G_DATA UDATA_OVR
count RES 2 ; temporary variable (shared locations - G_DATA)


HF equ 00001000
LF equ 00000100
FLAG_LO equ 00000010
FLAG_HI equ 00000100

;**********************************************************************
RESET_VECTOR CODE 0x000 ; processor reset vector
goto start ; go to beginning of program

MAIN CODE
start
;set PORTA to input

CLRF PORTA ; Initialize PORTA by
; setting output
; data latches
BSF STATUS, RP0 ; Select Bank 1
MOVLW 0x0F ; Value used to
; initialize data
; direction
MOVWF TRISA ; Set RA<3:0> as inputs
; RA4 as outputs
; TRISA<7:5> are always
; read as ’0’.

;set PORTB to output

CLRF PORTB ; Initialize PORTB by
; setting output
; data latches
BSF STATUS, RP0 ; Select Bank 1
MOVLW 0x8F ; Value used to
; initialize data
; direction
MOVWF TRISB ; Set RB<3:0> as inputs
; RB<6:4> as outputs
; RB7 as input

movf PORTA,w ;Get input
subwf HF,w ;HF is RA3 high -> upshift
btfss STATUS,Z ;if hf-output=equality, shift up
goto ChkDwn ; else shift down
subwf LF,w
btfss STATUS,Z
goto ChkUp

ChkUp:
movf PORTB,w
subwf FLAG_HI,w
btfss STATUS,Z
return
goto Up

Up:
movlw 00100000
movwf PORTB
goto Wait movlw 00000000
movwf PORTB
end

ChkDwn:
movf PORTB,w
subwf FLAG_LO,w
btfss STATUS,Z
return
goto Down

Down:
movlw 00010000
movwf PORTB
goto Wait
movlw 00000000
movwf PORTB
end

The stuff in blue was part of the template (ie i didn't write it). Wait is a little counter routine to ensure the outputs stay high for long enough.

The problem is as follows. When I go to Project>Quickbuild, I get the following error message (among others, but the rest are more to do with the fact that I'm not building it as a project):

Error[113] C:\DOCUMENTS AND SETTINGS\ZAC\MY DOCUMENTS\UNI\2004\SEM 1\EEB889\EEB889_DERAILLEUR.ASM 115 : Symbol not previously defined (ChkDwn)

the line it refers to is in green.

I also get a similar message for the wait routine which refers to the red line:

Error[113] C:\DOCUMENTS AND SETTINGS\ZAC\MY DOCUMENTS\UNI\2004\SEM 1\EEB889\EEB889_DERAILLEUR.ASM 130 : Symbol not previously defined (Wait)

Does anyone have any idea as to what is going on here?

I added the colons in after looking through a few textbooks but nothing changes.

Any help would be much appreciated.
 
Not only is the compiler not seeing your Wait procedure code, I'm not seeing it either. :p I'm getting directive errors and invalid ram location errors when I try to compile the program as submitted above. Why don't you ditch that template and re-write the offending sections? Its variable definitions and code start are horrible.
 
First off all, you're using UDATA, CODE (the blue part) statements so the compiler will compile this into object code, not absolute code, as a result you'll need a linker script. The linker script should be modified to suit your needs (and pic device) and use the same names for sections as your code.

then, 'goto wait'. There is no label called 'wait' so what is the compiler supposed to do?

'goto ChkDwn' fails because the code below subroutine 'Up' has an 'end' statement. The compiler will think the source file stops at the 'end' and ignore what's below.
 
there is code for wait, i just didn't put it in:

Wait
movlw 10001110111011
incf COUNT,1
subwf COUNT,w
btfss STATUS,Z
return
goto Wait

i realise that that probably won't work as it is cause f is only between 0 and 127, but i can handle that.

i really don't know about that udata stuff, i only left it in cause it was part of the template.

ok thanks for that. i'll try replacing 'end' with 'return' everywhere except for at the end of the code. if i understand correctly, it should work after that?
 
trailrider said:
i really don't know about that udata stuff, i only left it in cause it was part of the template.

ok thanks for that. i'll try replacing 'end' with 'return' everywhere except for at the end of the code. if i understand correctly, it should work after that?

No, it won't. You don't seem to have much of an idea of what you're doing...

The 'udata stuff' is important, you need a matching linker script or it won't work. Eighter that or port to absolute code.
As for replacing the end with a return, this will solve your compiler errors, but it won't work...
if you CALL a label, you RETURN from it, but if you GOTO it you can't return - code should just continue where you've gone to...
 
would the matching linker script be something like 16f84a.lkr? i only ask because when i selected the processor in mplab i used the wizard to create a new project and followed the instructions to associate it with the project.
 
Yes, it is a .lkr file, there are templates delivered with mplab but you'll need to adjust the file. The standard linker file hasn't got section names for data, your code does...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top