Jump to content
Sign in to follow this  
dmb

eecon1...not working on pic16f876a

Recommended Posts

when i code for eecon1 the compiler chooses the wrong bank (2 instead of 3 i believe)

 

so i decided to write this part is asm...

and i wrote

asm{

bsf STATUS,RP0

bsf STATUS,RP1

bcssf EECON1,WR

?

after building the lst file gives...

bsf STATUS,RP0

bsf STATUS,RP1

bsf STATUS,RP1

bcf STATUS,RP0

bcssf EECON1,WR

 

so 2 questions:

1, why is compiler adding lines when writing parts in asm?

 

2, why is the wrong bank choosen for eecon1?

 

Thanks in advance

Share this post


Link to post
Share on other sites
Guest Pavel
when i code for eecon1 the compiler chooses the wrong bank (2 instead of 3 i believe)

How do you declare the eecon1 variable in your C code?

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

char eecon1@0x018C;

char eecon2@0x018D;

 

// EECON1 Bits

 

#define EEPGD 0x0007

                                                                                   

#define WRERR 0x0003

                                                                                   

#define WREN 0x0002

                                                                   

#define WR 0x0001

             

#define RD 0x0000

 

code:

void write_eeprom ( unsigned char addr, unsigned char eepdata )

{ while ( EECON1 & 0x02);// was & WR

eeadr = addr;

eedata = eepdata;

clear_bit ( EECON1, EEPGD );

set_bit ( EECON1, WREN );

clear_bit (INTCON, GIE);

EECON2 = 0x55;

EECON2 = 0xAA;

set_bit( EECON1, WR );               // write command

set_bit (INTCON, GIE);  // reenable interupts

clear_bit( EECON1, WREN );           // inhibit further writing

Share this post


Link to post
Share on other sites
Guest yuko

Pavel, my include file is the p16f877.INC , from MPlab, which as the good equivalences of adress for registers, but sometimes, these equivalences are not good, because it doesn't write the good bank in asm after compilation.

 

it's also the case with eecon1.

Let's choose our bank, please .... ;)

 

+ Yuko :o

Share this post


Link to post
Share on other sites
Guest Pavel
char eecon1@0x018C;

char eecon2@0x018D;

...

clear_bit ( EECON1, EEPGD );

set_bit ( EECON1, WREN );

...

EECON2 = 0x55;

You declare the eecon1 & eecon2 variables but don't use them in your C code. Instead you use some constants (like EECON1). Since you don't provide full sources I can only guess what may be wrong there but based on the code fragment that you posted I'm almost sure that this is the cause of the problem. Try to get rid of EECON1 & EECON2 and use eecon1 & eecon2 instead (you may also need to do similar changes for other registers used in the code).

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
Guest Pavel
Pavel, my include file is the p16f877.INC , from MPlab, which as the good equivalences of adress for registers, but sometimes, these equivalences are not good, because it doesn't write the good bank in asm after compilation.

The built-in compiler variables are correct only for some PIC types and can't be used with other types. For the exact addresses please look here. If you declare and use your own variables mapped to registers this will always work. An example how this can be done can be found here though I'd recommend to use lover case letters in the variable names.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

i changed eecon to eeecon in both the declarations and functions and now it is fine..

 

it should not use the standard defeined registers if the target choosen is not using this registers..!

Share this post


Link to post
Share on other sites

the example you give uses _eecon1 etc...

 

if EECON1 would be right defined on each target pic all examples would work fine, even designed for other compilers or from the microchip application nodes...

Share this post


Link to post
Share on other sites
Guest yuko

but, why don't use the *.INC files provided by the PIC manufacturer ?

That's my question in fact ...

 

+ Yuko

???

Share this post


Link to post
Share on other sites
Guest Pavel
but, why don't use the *.INC files provided by the PIC manufacturer ?

Because .INC files are assembly language include files which can't be used by a C compiler.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
Guest yuko

Hello Pavel,

*.INC files are text files (string) which link a register name with an adress, it's possible to import them in the C code before the .asm compilation. I mean that it's possible to convert:

" EECON1                       EQU     H'018C' "

in:

" char EECON1@0x18C "

with basics C functions ( or in all others langages ).

 

I know that I don't like to work too much, but if I had to use C2c often, I would have writen a little soft to translate the asm include file into the C format required, and concatenate it into my C file.

 

And, for example, it could also allow to the decrease the support time .

 

+ yuko  :o

Share this post


Link to post
Share on other sites
Guest Pavel
I know that I don't like to work too much, but if I had to use C2c often, I would have writen a little soft to translate the asm include file into the C format required, and concatenate it into my C file.

Such translation utility already exists. It's called INC2H converter and its download link can be found on the top half of the compiler Examples page.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

i used it but the embedded faulty register have priority so this was not helpfull

 

so far only way was changing is to eeecon1 etc

Share this post


Link to post
Share on other sites
Guest Pavel
i used it but the embedded faulty register have priority so this was not helpfull

 

so far only way was changing is to eeecon1 etc

The name conflict happens only if your variable has the same name as the built-in one. Just use any different name (I recommend to use small letters).

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...