0
votes

I am programming 16F886 and here is a sample of inline asm:

#asm
psect TxtData,class=CODE,delta=2
global _text1,_text2
_text1:   dw    'T','E','X','T','1',0
_text2:   dw    'T','E','X','T','2',0
#endasm

I need to point EEADR and EEADRH to each of the labels to read the flash memory. In pure asm, I would just use the Low/High operands to get the address of each label e.g. movlw low Text1. In C, I need something like a "const pointer" for each of the labels but I can't make it to work. I am using the Hitech C compiler for PIC 10/12/16.

2
My first guess would be extern const char *text1;. What have you tried? And what error messages are you getting?user3386109
What @user3386109 said is the correct way to do this. Also, you may want to use the db directive, not the dw directive. The former will treat each character as a byte (as you want), the latter will treat them as 16-bit words, which is incorrect for C. You can also use plain strings in single quotes after a db directive, e.g. _text1: db 'TEXT1'slugonamission
when I write EEADR=&text1 i get "67.14 illegal conversion of pointer to integer". The code produced seems to pass the low byte correct though.tcop
I think that you need to post the relevant portions of the C code, see we can see what you're trying to do.user3386109
Have you tried EEADR= Text1 ?Weather Vane

2 Answers

1
votes

Thanks everyone for your kind support. I posted the question in Microchip forum and several guys tried it out.It turned out that there is somekind of bug in the compiler for 10/12/16 mcus. In C18 compiler or Hitech C18, when set for an 18F mcu, the above proposed solutions worrked flawlessly. The only workaround that I've managed to find, is to use inline assembly to get the high byte of an asm address label and set the proper registers this way.

asm 
    EEADRH EQU  0x10F
    movlw high _text1
    banksel EEADRH
    movwf EEADRH
endasm
0
votes

A string label is a pointer - you don't have to specify its address with &. You have to write the MS part of the address first

unsigned short address = text;
EEADRH = (address >> 8) & 0xF;
EEADR = address & 0xFF;