+ Reply to Thread
Page 1 of 2
1 2 Last
Results 1 to 15 of 19

Thread: Help cannot compile in MPLAB

  1. #1
    fengshao Newbie
    Join Date
    Apr 2009
    Posts
    12

    Default Help cannot compile in MPLAB

    Hi All

    I'm just starting out with PIC programming and try calling assembly from c,here is some error i dont know how to solve ,can someone help me, one is asm file ,another is c file

    Code:
    INCLUDE "p18f4620.inc"
    
    
    EXTERN SW2,ButtonState
    CODE
    
    
    asm_ButtonPress
    ButtonPress
    	movlw	high DebounceStates
    	movwf	PCLATH
    	movf	ButtonState,w
    	andlw	0x03
    	addlw	low DebounceStates
    	btfsc	STATUS,C	
    	incf	PCLATH,f
    	movwf	PCL	
    DebounceStates
    	goto	DebounceState0
    	goto	DebounceState1
    	goto	DebounceState2
    	goto	DebounceState1	
    
    DebounceState0	; Wait for a Button Press
    	bcf		STATUS,C
    	btfsc	SW2
    	goto	EndDebounceState0
    	incf	ButtonState,f
    	bsf		STATUS,C
    EndDebounceState0
    	return
    
    DebounceState1
    	btfss	SW2
    	goto	EndDebounceState1
    	incf	ButtonState,f
    	clrf	TMR1L
    	clrf	TMR1H
    	bcf		PIR1,TMR1IF
    EndDebounceState1
    	bcf		STATUS,C
    	return
    
    DebounceState2
    	btfss	SW2
    	decf	ButtonState,f
    	btfsc	PIR1,TMR1IF
    	clrf	ButtonState
    	bcf		STATUS,C
    	return
    GLOBAL asm_ButtonPress
    END
    

    Code:
    #include <p18f4620.h>
    #include"define.h"
    #define	SW2 	PORTAbits.RA4
    #pragma config OSC=INTIO67
    #pragma config WDT=OFF
    #pragma config LVP=OFF
    #pragma config DEBUG=ON
    #pragma config FCMEN=OFF
    #pragma config IESO=OFF
    #pragma config PWRT=OFF
    #pragma config BOREN=OFF
    #pragma config BORV=3
    #pragma config WDTPS=1
    #pragma config MCLRE=ON
    #pragma config LPT1OSC=OFF
    #pragma config PBADEN=OFF
    #pragma config CCP2MX=PORTC
    unsigned char State,Index,Mode,StepModeScaler, 
     Counter, Speed,ButtonState ;
    void ButtonPress(void);
    
    void InitializeBoardConfig(void)
    {
    TRISCbits.TRISC2=0;                    	 //make rc2 ccp1 output
    TRISD=0xB;                  	 //make RD2 RD4-RD7 output
    OSCCONbits.IRCF0=1;        
    OSCCONbits.IRCF1=1;
    OSCCONbits.IRCF2=1;      		 //SET internal oscillator to 8 MHZ
    
    ADCON1=0b01010000;	   			 //Fosc/16
                                        		 //enable AN0
    
    PR2=0x3F;						 //31.2 kHz PWM
    T0CON=0;				 //1:2 prescaler for TMR0
    
    
    TRISD=0b00000000;
    TRISC=0;						 //turn off windings
    ADCON0=0b00000001;     			 // left justified, AN0 selected, module
    CMCON=7;						 //turn off comparators
    CCPR1L=0;
    CCPR2L=0;
    CCP1CON=0b00001100;				 //pwm mode	
    CCP2CON=0b00001100;
    T2CONbits.TMR2ON=1;				 //turn on Timer 2
    T1CONbits.TMR1ON=1;				 //turn on Timer 1char
    
    State=0;	         //initialize motor state pointer and duty cycle
    Index =	0;		     //index pointer
    Mode =  0;
    ADRESH =0;	
    StepModeScaler =1;
    Counter  = 1;
    Speed= 0;					
    ButtonState =0;
    }
     // Main - Choose motor mode//
    void T0Delay()
    {
    T0CON=0x0;
    TMR0H=0xF3;
    TMR0L=0xC8;
    T0CONbits.TMR0ON=1; 
      while (INTCONbits.TMR0IF==0);
    T0CONbits.TMR0ON=0;
    INTCONbits.TMR0IF=0;
    }
    extern void asm_timed_delay (unsigned char);
    extern void  asm_ButtonPress();
    void main(void)
    {
    InitializeBoardConfig();
    
    if( INTCONbits.TMR0IF==1)
        INTCONbits.TMR0IF=0;
    else 
    asm_ButtonPress();
    Mode++;
    asm_timed_delay (0x80);
    }
    



    Executing: "D:\MCC18\mpasm\MPASMWIN.exe" /q /p18F4620 "asm.asm" /l"asm.lst" /e"asm.err" /o"asm.o" /d__DEBUG=1 /d__MPLAB_DEBUGGER_ICD2=1
    Warning[205] D:\STEPPERMOTOR\ASM.ASM 1 : Found directive in column 1. (INCLUDE)
    Warning[205] D:\STEPPERMOTOR\ASM.ASM 2 : Found directive in column 1. (CODE)
    Warning[203] D:\STEPPERMOTOR\ASM.ASM 9 : Found opcode in column 1. (MOVLW)
    Warning[203] D:\STEPPERMOTOR\ASM.ASM 10 : Found opcode in column 1. (DECF)
    Warning[203] D:\STEPPERMOTOR\ASM.ASM 11 : Found opcode in column 1. (BNZ)
    Warning[203] D:\STEPPERMOTOR\ASM.ASM 13 : Found opcode in column 1. (RETURN)
    Warning[205] D:\STEPPERMOTOR\ASM.ASM 15 : Found directive in column 1. (GLOBAL)
    Warning[205] D:\STEPPERMOTOR\ASM.ASM 16 : Found directive in column 1. (END)
    Executing: "D:\MCC18\mpasm\MPASMWIN.exe" /q /p18F4620 "D:\WSC\steppermotor\ButtonPress.asm" /l"ButtonPress.lst" /e"ButtonPress.err" /o"ButtonPress.o" /d__DEBUG=1 /d__MPLAB_DEBUGGER_ICD2=1
    Error[124] D:\WSC\STEPPERMOTOR\BUTTONPRESS.ASM 2 : Illegal argument (expected 0, 1, 2, or +|-<message number>)
    Warning[205] D:\WSC\STEPPERMOTOR\BUTTONPRESS.ASM 6 : Found directive in column 1. (INCLUDE)
    Warning[205] D:\WSC\STEPPERMOTOR\BUTTONPRESS.ASM 9 : Found directive in column 1. (EXTERN)
    Warning[205] D:\WSC\STEPPERMOTOR\BUTTONPRESS.ASM 10 : Found directive in column 1. (CODE)
    Error[128] D:\WSC\STEPPERMOTOR\BUTTONPRESS.ASM 31 : Missing argument(s)
    Error[128] D:\WSC\STEPPERMOTOR\BUTTONPRESS.ASM 39 : Missing argument(s)
    Error[128] D:\WSC\STEPPERMOTOR\BUTTONPRESS.ASM 50 : Missing argument(s)
    Warning[205] D:\WSC\STEPPERMOTOR\BUTTONPRESS.ASM 56 : Found directive in column 1. (GLOBAL)
    Warning[205] D:\WSC\STEPPERMOTOR\BUTTONPRESS.ASM 57 : Found directive in column 1. (END)
    Halting build on first failure as requested.


  2. #2
    Hayato Excellent Hayato Excellent Hayato Excellent Hayato Excellent Hayato Excellent
    Join Date
    Jun 2006
    Location
    Brasilia, Brazil
    Posts
    655
    Blog Entries
    1

    Default

    movlw high DebounceStates
    addlw low DebounceStates

    "DebouceStates" is a Label, not a numeric value.

  3. #3
    fengshao Newbie
    Join Date
    Apr 2009
    Posts
    12

    Default

    hi Hayato , how should i change ,

  4. #4
    Hayato Excellent Hayato Excellent Hayato Excellent Hayato Excellent Hayato Excellent
    Join Date
    Jun 2006
    Location
    Brasilia, Brazil
    Posts
    655
    Blog Entries
    1

    Default

    What do you want to do with this?

    movlw high DebounceStates
    addlw low DebounceStates

  5. #5
    fengshao Newbie
    Join Date
    Apr 2009
    Posts
    12

    Default

    this is a example code from microchip about stepper motor ,i just cut a routine ,try to calling assembly from C

  6. #6
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,776

    Default

    Quote Originally Posted by Hayato View Post
    movlw high DebounceStates
    addlw low DebounceStates

    "DebouceStates" is a Label, not a numeric value.
    That code is correct. It is calculating the address to jump to in the table.

    Mike.

  7. #7
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,776

    Default

    fengshao,

    What are you trying to do?

    Whatever it is I suggest you do it in C and only use asm when absolutely necessary. Mixing them adds a whole new layer of complexity.

    Mike.
    Last edited by Pommie; 24th April 2009 at 05:18 AM.

  8. #8
    fengshao Newbie
    Join Date
    Apr 2009
    Posts
    12

    Default

    Quote Originally Posted by Pommie View Post
    fengshao,

    What are you trying to do?

    Whatever it is I suggest you do it in C and only use asm when absolutely necessary. Mixing them adds a whole new layer of complexity.

    Mike.
    hi Mike
    i have to say i'm newbie on PIC ,because i need to do a project in C or mixing ,refer to assembly code (demo board funtion everything write in assembly ), i want to try whether can calling from c ,so cometime i copy whole routine then try to call it ,bt los of error come out....

  9. #9
    Hayato Excellent Hayato Excellent Hayato Excellent Hayato Excellent Hayato Excellent
    Join Date
    Jun 2006
    Location
    Brasilia, Brazil
    Posts
    655
    Blog Entries
    1

    Default

    Quote Originally Posted by Pommie View Post
    That code is correct. It is calculating the address to jump to in the table.

    Mike.
    Thanks!
    I suspected that was right when I saw he moving the address to PCLATH.

    @fengshao
    Try to change, in the first line of the assembly:
    From:
    INCLUDE "p18f4620.inc"
    To:
    #INCLUDE "p18f4620.inc"

  10. #10
    Hayato Excellent Hayato Excellent Hayato Excellent Hayato Excellent Hayato Excellent
    Join Date
    Jun 2006
    Location
    Brasilia, Brazil
    Posts
    655
    Blog Entries
    1

    Default

    Your Line 2 has an error. But the code you posted starts at line 6.

    Have you declared SW2 before? If SW2 is a registrer, then you need to specify the bit to be tested.

    The errors are thrown due those lines:
    Line 31: btfsc SW2
    Line 39: btfss SW2
    Line 50: btfss SW2

  11. #11
    fengshao Newbie
    Join Date
    Apr 2009
    Posts
    12

    Default

    Quote Originally Posted by Hayato View Post
    Your Line 2 has an error. But the code you posted starts at line 6.

    Have you declared SW2 before? If SW2 is a registrer, then you need to specify the bit to be tested.

    The errors are thrown due those lines:
    Line 31: btfsc SW2
    Line 39: btfss SW2
    Line 50: btfss SW2
    thanks
    i define SW2 in a DEfine file , just
    Code:
    #define  	SW2 	PORTAbits.RA4
    

  12. #12
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,776

    Default

    None of the c code you posted makes sense. I suggest you start with flashing an LED and then go on to reading a key and lighting an LED.

    Mike.

  13. #13
    Hayato Excellent Hayato Excellent Hayato Excellent Hayato Excellent Hayato Excellent
    Join Date
    Jun 2006
    Location
    Brasilia, Brazil
    Posts
    655
    Blog Entries
    1

    Default

    Quote Originally Posted by fengshao View Post
    thanks
    i define SW2 in a DEfine file , just
    Code:
    #define  	SW2 	PORTAbits.RA4
    
    And what is in line 2 of your assembly?

    Your C code don't use SW2, why not move it to the assembly code?

    Comment that EXTERNAL statement and on the top of your asm code add:
    #DEFINE SW2 PORTA,4

    Or try to change yout C code:
    #DEFINE SW2 RA4
    Last edited by Hayato; 24th April 2009 at 12:55 PM.

  14. #14
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,776

    Default

    Quote Originally Posted by Hayato View Post
    And what is in line 2 of your assembly?

    Your C code don't use SW2, why not move it to the assembly code?

    Comment that EXTERNAL statement and on the top of your asm code add:
    #DEFINE SW2 PORTA,4

    Or try to change yout C code:
    #DEFINE SW2 RA4
    Who cares, the code is nonsense, stop trying to make sense of it.

    Mike.

  15. #15
    Hayato Excellent Hayato Excellent Hayato Excellent Hayato Excellent Hayato Excellent
    Join Date
    Jun 2006
    Location
    Brasilia, Brazil
    Posts
    655
    Blog Entries
    1

    Default

    Quote Originally Posted by Pommie View Post
    Who cares, the code is nonsense, stop trying to make sense of it.

    Mike.
    Don't be angry with me...

+ Reply to Thread
Page 1 of 2
1 2 Last

Similar Threads

  1. Newbie question, cannot compile in MPLAB
    By Dunccc in forum Micro Controllers
    Replies: 15
    Latest: 5th February 2009, 12:33 PM
  2. MPLABs C18 Compile Error
    By yngndrw in forum Micro Controllers
    Replies: 7
    Latest: 18th March 2008, 11:44 AM
  3. Z80 C Compiler (compile as a intel hex?)
    By Marks256 in forum Chit-Chat
    Replies: 8
    Latest: 16th January 2007, 09:30 PM
  4. help~ how to use C languge to compile FFT . thanks
    By wontall in forum Electronic Projects Design/Ideas/Reviews
    Replies: 4
    Latest: 31st May 2004, 06:08 AM
  5. Can anybody compile this for me?
    By jair_ie in forum Micro Controllers
    Replies: 5
    Latest: 21st October 2003, 02:15 PM

Tags for this Thread