Trouble with linking ASM and C

Discussion in 'Embedded Systems and Microcontrollers' started by corsair, Apr 1, 2010.

  1. corsair

    Thread Starter Member

    Mar 6, 2010
    51
    1
    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:
    Code ( (Unknown Language)):
    1. ...
    2. VOLTS_2 res 1 ; My "display" variables
    3. VOLTS_3 res 1
    4. VOLTS_4 res 1
    5. ...
    6.  extern ad_to_volts
    7. ....
    8. temp:
    9.    ...
    10.    call ad_to_volts ; converts ADRESH/ADRESL into volts, puts data into
    11.                          ; "VOLTS" variables
    12.    ...
    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.
     
  2. corsair

    Thread Starter Member

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

    Here it is though, temperature.c:
    Code ( (Unknown Language)):
    1. #include "P18F4550.h"
    2.  
    3. // Import VOLTS variables      
    4. extern unsigned char VOLTS_2;
    5. extern unsigned char VOLTS_3;
    6. extern unsigned char VOLTS_4;
    7.  
    8. // Combine ADRESH and ADRESL
    9.  
    10. /* TEST VARIABLES */
    11. //unsigned char ADRESH_test = 0x3;
    12. //unsigned char ADRESL_test = 0xff;
    13. //unsigned char VOLTS_2 = 0;
    14. //unsigned char VOLTS_3 = 0;
    15. //unsigned char VOLTS_4 = 0;
    16.  
    17. unsigned short int get_adres() {
    18.     int temp;
    19.  
    20.     temp = ADRESH;
    21.     temp = temp << 8;
    22.     temp = ADRESL+temp;
    23.    
    24.     return temp;
    25. }
    26.  
    27. // Convert the AD Result into a counter and place
    28. // digits (in dec) into VOLTS_3,VOLTS_2,and VOLTS_1
    29. void ad_to_volts() {
    30.     unsigned short int temp;
    31.  
    32.     temp = get_adres(ADRESH,ADRESL);
    33.     temp = (temp/.31)*.10; //temp = counter
    34.  
    35.     while (temp != 0) {
    36.         VOLTS_4 += 1;
    37.         if (VOLTS_4 == 10) {
    38.             VOLTS_3 += 1;
    39.             VOLTS_4 = 0;
    40.             if (VOLTS_3 == 10) {
    41.                 VOLTS_2 += 1;
    42.                 VOLTS_3 = 0;
    43.             }
    44.         }
    45.         temp--;
    46.     }
    47. }
    48.  
    49. void main(void) {
    50.  
    51. }
     
  3. corsair

    Thread Starter Member

    Mar 6, 2010
    51
    1
    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
     
Loading...