View previous topic :: View next topic |
Author |
Message |
julien lochen
Joined: 16 May 2008 Posts: 14
|
"Expecting an opcode mnemonic banksel" |
Posted: Fri May 16, 2008 7:51 am |
|
|
Hello,
I work with MPLAB and CCS V4.
in my C program, I inserted a function in ASM between the keywords "#ASM" and "#ENDASM".
It works but when I use the opcode "banksel" I have "Expecting an opcode mnemonic banksel".
source files: main.c
header files: 16F877A.h
object files: none
other files: main.SYM, main.TRE
main.c:
////////////////////////////////////////////////////////
#include <16F877A.h>
#define duree 1000000000
void tempo(unsigned int count);
void main(void)
{
#ASM
banksel PORTB
MOVLW 0xFF
MOVWF PORTB
banksel TRISB
MOVLW 0x00
MOVWF TRISB
#ENDASM
}
void tempo(unsigned int compte)
{
while(compte--);
}
////////////////////////////////////////////////////////
thanks, julien lochen |
|
|
Ttelmah Guest
|
|
Posted: Fri May 16, 2008 7:59 am |
|
|
You don't need to use banksel.
The CCS 'assembler', doesn't work like a full/normal assembler. Instead it is quite smart. If you tell it:
#ASM
MOVLW 0xFF
MOVWF PORTB
MOVLW 0x00
MOVWF TRISB
#ENDASM
It will _automatically_ perform the bank selection operation as needed.
In fact though, you don't even need to use assembler at all. The single line:
output_b(0xFF);
will automatically output 0xFF, on portB, and change the TRIS for you as well, without using any assembler.
Best Wishes |
|
|
julien lochen
Joined: 16 May 2008 Posts: 14
|
|
Posted: Fri May 16, 2008 8:11 am |
|
|
I stared coding in assembleur, I will continue using the C functions of CCS like output_b(X) ...
I just want to reuse the assembleur allready written.
I removed the line bankdel, now I have:
"Error 12 "main.c" Line 22(1,6): Undefined identifier PORTB"
/////////////////////////////////////////
#include <16F877A.h>
#define duree 1000000000
void tempo(unsigned int count);
void main(void)
{
#ASM
//banksel PORTB
MOVLW 0xFF
MOVWF PORTB
//banksel TRISB
MOVLW 0x00
MOVWF TRISB
#ENDASM
}
void tempo(unsigned int compte)
{
while(compte--);
}
/////////////////////////
thanks, julien |
|
|
Ttelmah Guest
|
|
Posted: Fri May 16, 2008 8:21 am |
|
|
You have to define things like PORTB, the assembler has no implicit 'knowledge' of things like this. Use the #byte directive to tell it where this register is (and the same for the TRIS).
The normal assembler also doesn't have this knowledge, but there is normally a header file that defines all the standard registers etc., for you.
Best Wishes |
|
|
Guest
|
|
Posted: Fri May 16, 2008 9:22 am |
|
|
ok, I declared PORTB and TRISB as byte, but they are not assigned as long as I do not use the opcode "banksel":
#include <16F877A.h>
#define duree 1000000000
#byte PORTB = 0xFF
#byte TRISB = 0xFF
void tempo(unsigned int count);
void main(void)
{
#ASM
//banksel PORTB
MOVLW 0xFF
MOVWF PORTB
banksel PORTB
//banksel TRISB
MOVLW 0x00
MOVWF TRISB
#ENDASM
}
void tempo(unsigned int compte)
{
while(compte--);
} |
|
|
Ttelmah Guest
|
|
Posted: Fri May 16, 2008 9:42 am |
|
|
AArgh!.....
You have to declare them at their proper addresses. You have declared them at the _same_ (wrong) address. TRISB, is at 0x86, and PORTB is at 06.
So:
Code: |
#byte PORTB = 0x6
#byte TRISB = 0x86
|
Best Wishes |
|
|
Ttelmah Guest
|
|
Posted: Fri May 16, 2008 9:57 am |
|
|
As a comment, how is the code ever going to get to 'tempo'?...
Just as a demo, of what you should have if you want to use the assembler:
Code: |
#byte PORTB = 0x6
#byte TRISB = 0x86
#ASM
MOVLW 0xFF
MOVWF PORTB
MOVLW 0x00
MOVWF TRISB
#ENDASM
|
Which if included in a program, and compiled, generates (in the .LST file):
Code: |
.................... MOVLW 0xFF
000C: MOVLW FF
.................... MOVWF PORTB
000D: BCF 03.5
000E: MOVWF 06
.................... MOVLW 0x00
000F: MOVLW 00
.................... MOVWF TRISB
0010: BSF 03.5
0011: MOVWF 06
|
Note the BCF 03.5, and the BSF 03.5, which are the bank selection operations.
Best Wishes |
|
|
julien lochen
Joined: 16 May 2008 Posts: 14
|
|
Posted: Fri May 16, 2008 11:06 am |
|
|
works fine, thank u veru much |
|
|
|