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.

Help cannot compile in MPLAB

Status
Not open for further replies.

fengshao

New Member
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.
 
this is a example code from microchip about stepper motor ,i just cut a routine ,try to calling assembly from C
 
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:
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....
 
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"
 
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
 
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
 
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.
 
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:
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.
 
Just write ,4 after each test of sw

btfsc SW2,4
btfss SW2,4
btfss SW2,4
The misssing argument is the bit to be tested.
LOL I ope I am right
Later you will be learning more of this.
 
Just write ,4 after each test of sw

btfsc SW2,4
btfss SW2,4
btfss SW2,4
The misssing argument is the bit to be tested.
LOL I ope I am right
Later you will be learning more of this.

ya.thank you , you are right ,bt the new problem:
Error - could not find definition of symbol 'SW2' in file './ButtonPress.o'
and i already check no C file has the same name as an assembly file
 
_asm

try this, just change adress of port where sw is.
and do not write switch , just btfss 0xf81, x , where oxf81 is your port address, and x is bit 4
if none of this works, please read data sheet to see commands.
its very easy.

i hope this helps.


_asm
CLRF 0xf81,ACCESS // Initialize PORTB by
// clearing output
// data latches
CLRF 0xf8a,ACCESS // Alternate method
// to clear output
// data latches
MOVLW 0xFF // Value used to
// initialize data
// direction
MOVWF TRISB,ACCESS // Set RB<7:4> as inputs
MOVWF 0xf78,ACCESS // Set pull ups PORTB WPUB REG
BCF 0XFF1,7,ACCESS // INTCON2,7 = 0, ALL PULLUPS ENABLED PORTA and PORTB

_endasm
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top