Hello,
I am currently trying to use some assembler code snippets described in this thread (http://www.midibox.org/forum/index.php?topic=4140.0) to access an SRAM chip connected to J15 of the core module within my C application. Basically I know how to use assembler code in C, but it seems like I do not fully understand how variables names are used in the assembler to C mechanism.
Here come the errors I get when I try to compile my code.
Assembling MIOS SDCC wrapper
==========================================================================
Compiling pic18f452.c
Processor: 18F452
==========================================================================
Compiling main.c
Processor: 18F452
In file included from main.c:17:
sram.c:83:3: warning: "/*" within comment
sram.c:123:3: warning: "/*" within comment
sram.c:185:3: warning: "/*" within comment
_output\main.asm:506:Error [113] Symbol not previously defined (TRISA).
_output\main.asm:506:Error [113] Symbol not previously defined (TRISA).
_output\main.asm:507:Error [113] Symbol not previously defined (TRISA).
_output\main.asm:507:Error [113] Symbol not previously defined (TRISA).
_output\main.asm:508:Error [113] Symbol not previously defined (TRISA).
_output\main.asm:508:Error [113] Symbol not previously defined (TRISA).
_output\main.asm:509:Error [113] Symbol not previously defined (TRISA).
_output\main.asm:509:Error [113] Symbol not previously defined (TRISA).
_output\main.asm:510:Error [113] Symbol not previously defined (TRISA).
_output\main.asm:510:Error [113] Symbol not previously defined (TRISA).
_output\main.asm:512:Error [113] Symbol not previously defined (PORTA).
_output\main.asm:512:Error [113] Symbol not previously defined (PORTA).
_output\main.asm:513:Error [113] Symbol not previously defined (PORTA).
_output\main.asm:513:Error [113] Symbol not previously defined (PORTA).
_output\main.asm:514:Error [113] Symbol not previously defined (PORTA).
_output\main.asm:514:Error [113] Symbol not previously defined (PORTA).
_output\main.asm:515:Error [113] Symbol not previously defined (PORTA).
_output\main.asm:515:Error [113] Symbol not previously defined (PORTA).
_output\main.asm:516:Error [113] Symbol not previously defined (PORTA).
_output\main.asm:516:Error [113] Symbol not previously defined (PORTA).
ERROR!
Now, this is the section that the errors originally refer to:
void SRAM_Init(void) __wparam
{
__asm
;; disable the ADC which allocates the analog pins
;; only needed if controls pins are connected to port A
movlw 0x07
movwf _ADCON1
; put PortA in output mode
bcf SRAM_TRIS_LATCH1_LE, SRAM_PIN_LATCH1_LE
bcf SRAM_TRIS_LATCH2_LE, SRAM_PIN_LATCH2_LE
bcf SRAM_TRIS_CS, SRAM_PIN_CS
bcf SRAM_TRIS_WE, SRAM_PIN_WE
bcf SRAM_TRIS_OE, SRAM_PIN_OE
; set control lines
bsf SRAM_PORT_OE, SRAM_PIN_OE
bsf SRAM_PORT_WE, SRAM_PIN_WE
bsf SRAM_PORT_CS, SRAM_PIN_CS
bcf SRAM_PORT_LATCH1_LE, SRAM_PIN_LATCH1_LE
bcf SRAM_PORT_LATCH2_LE, SRAM_PIN_LATCH2_LE
; put PortE in output mode
bcf _TRISE, 0
bcf _TRISE, 1
bcf _TRISE, 2
__endasm;
return;
}
I know this because before adding an underscore in front of [tt]ADCON1[/tt], I got the same ‘_output\main.asm:506:Error [113] Symbol not previously defined (ADCON1)’ error message as I get them for the TRISA now. The problem is that there is a macro
#define SRAM_TRIS_LATCH1_LE TRISA
in a header file included from the main.c that defines TRISA, but if I add the underscore in front of TRISA there I still get the same error message. When I look at the main.asm file in the \output folder, I can see that the macro gets translated to
; ; Starting pCode block
S_main__SRAM_Init code
_SRAM_Init:
;; disable the ADC which allocates the analog pins
;; only needed if controls pins are connected to port A
movlw 0x07
movwf _ADCON1
; put PortA in output mode
bcf TRISA, 0
;bcf TRISA, 1
;bcf TRISA, 2
;bcf TRISA, 3
;bcf TRISA, 5
; set control lines
bsf PORTA, 5
bsf PORTA, 3
bsf PORTA, 2
bcf PORTA, 0
bcf PORTA, 1
; put PortE in output mode
bcf _TRISE, 0
bcf _TRISE, 1
bcf _TRISE, 2
So how does that underscore thing work and what do I need to do in order to make it work in macros, too? Or how do I need to modify my code for direct access to the TRISA register from C ? ??? :-[
Thanks for reading, ilmenator