Jump to content
Sign in to follow this  
tibe

eeprom data

Recommended Posts

software mplab 5.30 with c2c puls compiler 3.28.03e

// write/read eeprom data for PIC 16F876

 

#pragma CLOCK_FREQ 4000000

asm __config 0x3D39

 

Write_eeprom(char addrw,char dataw)

{

set_bit(STATUS, RP0);    

set_tris_a(0);

clear_bit(STATUS, RP0);

 

//Write eeprom

set_bit( STATUS, RP1 );

clear_bit( STATUS, RP0 );

EEADR = addrw;

EEDATA = dataw;

set_bit( STATUS, RP0 );

clear_bit( EECON1, EEPGD );

set_bit( EECON1, WREN );

EECON2 = 0x55;

EECON2 = 0xAA;

set_bit( EECON1, WR );

// while(EECON1);

nop();

nop();

nop();

nop();

clear_bit( EECON1, WREN );

clear_bit( STATUS, RP0 );

delay_ms(100);

//return 0;

clear_bit( STATUS, RP1 );

}

 

main()

{

char dat1;

 

set_bit(STATUS, RP0);    

set_tris_b(255);

set_tris_c(128);

//asm movlw 07h  

//asm movwf ADCON1

clear_bit(STATUS, RP0);

output_port_b(0);

output_port_c(0);

 

delay_ms(100);

 

Write_eeprom(0,3);

 

delay_ms(100);

 

//read from eeprom

set_bit(STATUS, RP1);

clear_bit(STATUS, RP0);

EEADR = 0x00;

set_bit(STATUS, RP0);

clear_bit(EECON1, EEPGD);

set_bit(EECON1, RD);

delay_ms(100);

clear_bit(STATUS, RP0);

dat1 = EEDATA;

 

delay_ms(100);

 

//write to eeprom data

Write_eeprom(2,dat1);

Write_eeprom(3,5);

 

while(1);

}

 

output eeprom data:

address 00h = 03

address 02h = 00

address 03h = 05

the address 02H must be = 03. Why is it = 00 ???

Where is the error ?

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