Jump to content

Problems Writing To Eeprom


Recommended Posts

Hi,

 

I have problems with writing to the EEPROM of the PIC16F628A

 

My Source is this:

 

//EEPROM_Write

//Adres = 0x20

//DATA = 0xAA

 

EEPROM_WRITE(0x20, 0xAA)

 

void EEPROM_WRITE(char adresa, char data) // write to EEPROM

{

asm

{

BSF STATUS, RP0 ; Bank 1

BCF STATUS, RP1

MOVWF param00_EEPROM_WRITE

MOVWF _eeadr ; Address to read

MOVWF param01_EEPROM_WRITE

MOVWF _eedata ; Address to read

BCF INTCON, GIE

BSF EECON1, WREN ; Enable Write

 

MOVLW H'55'

MOVWF EECON2 ; 55h must be written to EECON2

MOVLW H'AA' ; to start write sequence

MOVWF EECON2 ; Write AAh

 

BSF EECON1,WR ; Set WR bit begin write

BSF INTCON, GIE

BCF STATUS, RP0

 

writeee btfss PIR1, EEIF ; poll EEPROM Int. Flag is SET

goto writeee

BCF PIR1, EEIF

 

BSF STATUS, RP0

BCF EECON1, WREN

}

}

 

After writing i looked at the eeprom and see the next problem:

Adres = 0xAA and the witten data = 0xAA

 

That is not correct because the adres wass 0x20.

 

What to do???

Link to comment
Share on other sites

Try this:

unsigned char read_eeprom(unsigned char addr)
{
 eeadr = addr;                 // low byte
 eeadrh = 0;                   // high byte
 clear_bit(eecon1,EEPGD);      // select eeprom memory
 set_bit(eecon1,RD);           // set read bit
 return(eedata);
}

void write_eeprom(unsigned char addr, unsigned char data)
{
 eeadrh = 0;                  // high byte
 eeadr = addr;                // low byte
 eedath = 0;                  // high byte
 eedata = data;               // low byte
 clear_bit(eecon1,EEPGD);     // select eeprom data memory
 set_bit(eecon1,WREN);        // enable write
 clear_bit(intcon,GIE);       // disable interrupts
 eecon2 = 0x55;
 eecon2 = 0xaa;
 set_bit(eecon1,WR);          // write command
 set_bit(intcon,GIE);         // enable interrupts <- remove this line if u don't use interrupts
 while(eecon1&2);             // wait untill writing is ready
 clear_bit(eecon1,WREN);      // disable write
}

Link to comment
Share on other sites

I'll ready tryed this.

This had no result when i'l write to the eeprom

 

I'll ready looked a the sample site off sourceboost.

And there was an example for the PIC16F84 but that was not working on the PIC16F628 or 648

Link to comment
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...
 Share

×
×
  • Create New...