Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

[SOLVED] Pic16f887 eeprom read/write

Status
Not open for further replies.

tahir4awan

Full Member level 4
Joined
Nov 29, 2010
Messages
202
Helped
16
Reputation
32
Reaction score
16
Trophy points
1,308
Location
Germany
Activity points
3,032
I wrote a simple code to write and read data from EEPROM. The code is working
for all ports except PORTB. What is the problem?
----------------------------------------------------------------------------
void main(){

ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;



TRISB = 0x00;
PORTB = 0x00;




EEPROM_Write(0x50,0xAA);

Delay_ms(1000);

PORTB = EEPROM_Read(0x50);




}
----------------------------------------------------------------------------

Secondly MikroC uses its own built in functions
EEPROM_Write(0x50,0xAA);
EEPROM_Read(0x50);

and PIC microcontroller has EECON1 and EECON2 registers. What is the difference?
 

arbj

Full Member level 4
Joined
Oct 5, 2008
Messages
238
Helped
31
Reputation
62
Reaction score
20
Trophy points
1,298
Activity points
2,601
you need to prevent the mcu from going into sleep state, add an infinite loop at the main procedure, something like this.

void main()
{
procedure1();
do{

} While(TRUE);

}

When the MCU goes into sleep, the program execution stops, so to keep the mcu busy you need to give it work.
 

bjuric

Advanced Member level 4
Joined
May 4, 2011
Messages
115
Helped
32
Reputation
64
Reaction score
30
Trophy points
1,308
Location
Serbia
Activity points
1,980
Check the datasheet.
EECON1 contains EEPROM contol bits
EECON2 does not exist physically. That's a virtual register in which you need to write 0x55 and 0xAA (one after the other) before initiating EEPROM write. It serves as a protection from accidental writing into EEPROM. EEPROM_Write() does that for you.
 

tahir4awan

Full Member level 4
Joined
Nov 29, 2010
Messages
202
Helped
16
Reputation
32
Reaction score
16
Trophy points
1,308
Location
Germany
Activity points
3,032
My point is the same code is working for all ports but not for PORTB. It means code is correct.
 

thunderboympm

Full Member level 5
Joined
Sep 17, 2007
Messages
244
Helped
32
Reputation
64
Reaction score
29
Trophy points
1,308
Location
Malappuram, India
Activity points
2,468
assign the eeprom value to a variable and then to portb. I got same error, i solved like this. Don't ask me the theory behind this i don't know
 

tahir4awan

Full Member level 4
Joined
Nov 29, 2010
Messages
202
Helped
16
Reputation
32
Reaction score
16
Trophy points
1,308
Location
Germany
Activity points
3,032
thunderboympm I think you have become angry but Thanks for your help.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top