Trouble with linking ASM and C

Thread Starter

corsair

Joined Mar 6, 2010
51
I was originally going to write my program in ASM, but after a suggestion, I wrote a function in C that I want to use in my ASM code since it was supposed to make things a little easier.

However, I am having trouble linking the two together, and I'd like a little help. First of all, I am using MPLAB. First I tried to put the two source codes together, but MPLAB won't allow me. So I tried to compile the C code separately (using the default C linker file) then I added the object file to my main project. So far, I've been trying to compile this, but I am still having problems.

This is one error I cannot figure out. "Error - could not find definition of symbol 'FSR2L' in file 'C:\Program Files\Microchip\MPASM Suite\440\project1\Test\temperature.o'."

The funny thing is, I don't even use this variable. I even do an #include P18F4450.h" at the top of the .c file, so I'm not really sure what the problem is.

Anyways, attached is my C code, and below is how I call it in my .asm file:
Rich (BB code):
...
VOLTS_2 res 1 ; My "display" variables
VOLTS_3 res 1 
VOLTS_4 res 1
...
 extern ad_to_volts
....
temp:
   ...
   call ad_to_volts ; converts ADRESH/ADRESL into volts, puts data into 
                         ; "VOLTS" variables
   ...
Let me know if there's any other information I can give while I bang my head against my desk trying to figure this out.
 

Thread Starter

corsair

Joined Mar 6, 2010
51
Hmm it wouldn't let me attach the file. I swear, things are not going well today.

Here it is though, temperature.c:
Rich (BB code):
#include "P18F4550.h" 

// Import VOLTS variables		
extern unsigned char VOLTS_2;
extern unsigned char VOLTS_3;
extern unsigned char VOLTS_4;

// Combine ADRESH and ADRESL

/* TEST VARIABLES */
//unsigned char ADRESH_test = 0x3;
//unsigned char ADRESL_test = 0xff;
//unsigned char VOLTS_2 = 0;
//unsigned char VOLTS_3 = 0;
//unsigned char VOLTS_4 = 0;

unsigned short int get_adres() {
    int temp;

	temp = ADRESH;
	temp = temp << 8;
	temp = ADRESL+temp;
	
	return temp;
}

// Convert the AD Result into a counter and place 
// digits (in dec) into VOLTS_3,VOLTS_2,and VOLTS_1
void ad_to_volts() {
	unsigned short int temp;

	temp = get_adres(ADRESH,ADRESL);
	temp = (temp/.31)*.10; //temp = counter

	while (temp != 0) {
		VOLTS_4 += 1;
		if (VOLTS_4 == 10) {
			VOLTS_3 += 1;
			VOLTS_4 = 0;
			if (VOLTS_3 == 10) {
				VOLTS_2 += 1;
				VOLTS_3 = 0;
			}
		}
		temp--;
	}
}

void main(void) {

}
 

Thread Starter

corsair

Joined Mar 6, 2010
51
omg i finally got it to work. i ended up having to use a different linker than the one i originally was working with since i was using c code. in addition, i need to use the same linker when compiling the c code. thank god this is over
 
Top