[SOLVED] EEPROM read and WRITE program, pls check it.

Status
Not open for further replies.

vinodstanur

Advanced Member level 3
Joined
Oct 31, 2009
Messages
751
Helped
114
Reputation
234
Reaction score
114
Trophy points
1,333
Location
Kerala (INDIA)
Activity points
7,054
#include <htc.h>
#define _XTAL_FREQ 4e6 // 4MHz
__CONFIG(0x3F3A);
void write(int k)
{
EEADR=1;
EEDATA=k;
EEPGD=0;
WREN=1;
EECON2=0x55;
EECON2=0xAA;
WR=1;
WREN=0;EEDATA=0;
}

void main()
{int d;
TRISB=0;TRISD=0xFF;
EEADR=1;
EEPGD=0;
RD=1;d=EEDATA;
if(d==0xF0){while(1){PORTB=255;if(RD3==1){write(10);}};}
write(0xF0);write(0xF0);
while(1)
{__delay_ms(10);
EEADR=1;
EEPGD=0;
RD=1;d=EEDATA;
PORTB=d;
}
}

this is my test program ;
here, when the pic is inserted to the circuit, then port b shows F0h.
then if i reset the pic then PORTB becomes FFh.
this much is correct ....
but,
when i give RD3=1 and then I reset the PIC, then PORTB is not becoming F0h.
it shows 00H....
why?
could any one help me?
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…