Jump to content
Sign in to follow this  
Prefekt

Bug With Eeprom?

Recommended Posts

Hello,

I'm using a 16F876 and the internal eeprom. The write and read at the eeprom works fine. But if I'm using more than three variables like this:

char cDigit1=0x00;

char cDigit2=0x00;

char cDigit3=0x00;

char cDigit3=0x00;

the value was not written in the eeprom?

If I wrote this in my code:

char cDigit1=0x00;

char cDigit2=0x00;

char cDigit3=0x00;

//char cDigit3=0x00;

 

it works?

 

 

my eeprom code is:

 

void write_eeprom(char adresa,char data)

{

char addr = adresa;

char dat = data;

 

asm{

BSF STATUS, RP1 ;

BSF STATUS, RP0 ;Bank 3

BTFSC EECON1, WR ;Wait for

GOTO $-1 ;write to finish

BCF STATUS, RP0 ;Bank 2

MOVF _addr_write_eeprom , W ;Address to

MOVWF EEADR ;write to

MOVF _dat_write_eeprom, W ;Data to

MOVWF EEDATA ;write

BSF STATUS, RP0 ;Bank 3

BCF EECON1, EEPGD ;Point to Data memory

BSF EECON1, WREN ;Enable writes

;Only disable interrupts

BCF INTCON, GIE ;if already enabled,

;otherwise discard

MOVLW 0x55 ;Write 55h to

MOVWF EECON2 ;EECON2

MOVLW 0xAA ;Write AAh to

MOVWF EECON2 ;EECON2

BSF EECON1, WR ;Start write operation

;Only enable interrupts

BSF INTCON, GIE ;if using interrupts,

;otherwise discard

BCF EECON1, WREN ;Disable writes

}

return;

}

 

 

 

Is this a bug in the compiler?

Thanks

 

Volker

Edited by Prefekt

Share this post


Link to post
Share on other sites

Volker,

 

Sounds like a memory allocation type issue.

 

Which compiler are you using C2C or the BoostC ?

 

I complete program that demonstrates the problem would be useful.

 

Regards

Dave

Share this post


Link to post
Share on other sites

This probably has nothing to do with your problem however this processor used to have a bug in the silicon associated with disabling interrtupts. The work around was to disable interrupts and then test to see if interrupts were disabled.

 

; force global interrupts to be disabled
WWEE1	bcf	Intcon,GIE; disable global interrupts
btfsc	Intcon,GIE; are global interrupts disabled?
goto	WWEE1

 

Regards, Andrew

Edited by asmallri

Share this post


Link to post
Share on other sites

Hello,

I'm thinking also, that is as memory problem.

Sample Variable definition:

it work's:

char a;

char b;

char c;

or

int i;

or

int i;

char a;

 

it dosen't works:

char a:

char b:

char c:

char d;

or

int i;

int j;

or

int i;

char a;

char b;

 

Here is a sample Code, that work. If you delete the comment and use the two integer variable it doesen't work....

 

#include <system.h>

 

void erase_eeprom();

void write_eeprom(char adresa,char data);

char read_eeprom(char adresa);

 

void main(void)

{

char c=0x00;

char d=0x00;

char a=0x00;

char e=0x00;

char b=0x00;

char f=0x00;

char g=0x00;

char j=0x00;

/*int i;

int k;*/

trisb=00000000b;

portb=00000000b;

 

d=read_eeprom(0x0000);

write_eeprom(0x0001,10101010b);

d=read_eeprom(0x0001);

 

if(d==00001111b){

c=11110000b;

portb=11110000b;}

else{

c=00001111b;

portb=00001111b;}

write_eeprom(0x0000,c);

while(1);

}

 

void write_eeprom(char adresa,char data)

{

char addr = adresa;

char dat = data;

 

asm{

BSF STATUS, RP1 ;

BSF STATUS, RP0 ;Bank 3

BTFSC EECON1, WR ;Wait for

GOTO $-1 ;write to finish

BCF STATUS, RP0 ;Bank 2

MOVF _addr_write_eeprom , W ;Address to

MOVWF EEADR ;write to

MOVF _dat_write_eeprom, W ;Data to

MOVWF EEDATA ;write

BSF STATUS, RP0 ;Bank 3

BCF EECON1, EEPGD ;Point to Data memory

BSF EECON1, WREN ;Enable writes

;Only disable interrupts

BCF INTCON, GIE ;if already enabled,

;otherwise discard

MOVLW 0x55 ;Write 55h to

MOVWF EECON2 ;EECON2

MOVLW 0xAA ;Write AAh to

MOVWF EECON2 ;EECON2

BSF EECON1, WR ;Start write operation

;Only enable interrupts

BSF INTCON, GIE ;if using interrupts,

;otherwise discard

BCF EECON1, WREN ;Disable writes

}

return;

}

char read_eeprom(char adresa)

{

char addr = adresa;

 

asm{

BSF STATUS, RP1 ;

BCF STATUS, RP0 ;Bank 2

MOVF _addr_read_eeprom, W ;Write address

MOVWF EEADR ;to read from

BSF STATUS, RP0 ;Bank 3

BCF EECON1, EEPGD ;Point to Data memory

BSF EECON1, RD ;Start read operation

BCF STATUS, RP0 ;Bank 2

MOVF EEDATA, W ;W = EEDATA

}

return EEDATA;

}

void erase_eeprom()

{

EEADR=0;

while(EEADR<=63){

EEDATA=0;

write_eeprom(EEADR,EEDATA);

}

}

 

@asmallri

I will test to disable the interrupts.

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...