Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

[SOLVED] Pic16f887 eeprom read/write

Status
Not open for further replies.

tahir4awan

Full Member level 4
Joined
Nov 29, 2010
Messages
208
Helped
16
Reputation
32
Reaction score
17
Trophy points
1,308
Location
Germany
Activity points
3,084
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?
 

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.
 

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.
 

My point is the same code is working for all ports but not for PORTB. It means code is correct.
 

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
 

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

Back
Top