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] Internal EEPROM for PIC16F876A using HI tech compiler

Status
Not open for further replies.

Nikunj Tanna

Advanced Member level 4
Joined
Dec 8, 2009
Messages
115
Helped
23
Reputation
46
Reaction score
15
Trophy points
1,298
Location
Ahmedabad, Gujarat, India
Activity points
1,985
Hello,

I am trying to save some bytes of data into the internal EEPROM of PIC16F876A, but i am not getting the things done. I am using Hi- Tech C compiler and it has example code for EEPROM in pic.h.. I am using that, i write single byte in EEPROM and read the same and compares it but i am not getting right values. Then I tried to make my own functions but those are also not working. I am pasting my testing code and my functions. Kindly check it out and help me..

// Testing code-------------------------------------------------

#include <pic.h>
#include <htc.h>
#include <stdio.h>
#include <eeprom_routines.h>
#include "delay.h"
#include "always.h"
//void eeprom_write(unsigned char, unsigned char);
//unsigned char eeprom_read(unsigned char);
void main (void)
{
unsigned char u;
TRISC0 = 0;
TRISC1 = 0;
TRISC2 = 0;
PORTC = 0x00;
RC0 = 0;
RC1 = 0;
RC2 = 0;
eeprom_write(0x10,0x34);
DelayS(5);
u = eeprom_read(0x10);
while(1)
{
if(u == 0x34)
{
RC0 = 1;RC1 = 0;RC2 = 1;
DelayS(1);
RC0 = 0;RC1 = 1;RC2 = 0;
DelayS(1);
}
RC0 = 1;RC1 = 1;RC2 = 1;
DelayS(1);
RC0 = 0;RC1 = 0;RC2 = 0;
DelayS(1);
}
}

///////////// my functions to use with same above testing code../////////

void eeprom_write(unsigned char add, unsigned char data)
{
GIE = 0;
EEPGD = 0;
WREN = 1;
EEADR = add;
EEDATA = data;
EECON2 = 0X55;
EECON2 = 0XAA;
WR = 1;
while(WR) continue;
WREN = 0;
}

unsigned char eeprom_read(unsigned char add)
{
EEPGD = 0;
EEADR = add;
RD = 1;
while(RD)continue;
return EEDATA;
}


What can be the reason for not working in any of the two ways ? please tell me..

NIKS
 

Hey,

No one to reply..!!!!

My read function works ok and reads 0xff on every location but when i try to call write function, the WREER bit gets high and the write operation gets interrupted...

Atleast answer me now, I am stopped...

NIKS
 

#pragma config OSC = HS // 20MHz Crystal, (HS oscillator)
#pragma config WDT = OFF // watch dog timer off
#pragma config LVP = OFF // Low voltage program off

Please post your initial configurations like i have told above
 

I have already configuration bits like this.
I am using 16MHz crystal so I already use HS oscillator, Watchdog timer off, Low voltage programming off..
Still I am writing the same in code now and testing again, I have set those in configuration bits...

Thank you and please tell me if any other changes...

NIKS

---------- Post added at 17:59 ---------- Previous post was at 17:46 ----------

Sorry, I misunderstood the reply of yours..

my initial configuration bits are 1F7A..
it means
HS oscillator
WDT disabled
PWRT disabled
RB3 is digital i/o, HV on MCLR must be used for programming
DATA EEPROM code protection off
Flash program write protection off
Code protect on

NIKS
 

Hi
HiTech has nice special feature to define a variable into EEPROM - when doing reading and writing to this variable the compiler will take care for the EEPROM. Because I didn't work for long time with HiTech as I remember it was something like __eeprom uchar myVar @ MyAddress;
I would suggest you check the HiTech manual for more information
 

Hi,

Yes, I heard about that.. It's something called HI Tech eeprom qualifier.. But i don't know how to use it and if my current version is supporting it or not ? If any one knows that way to write in EEPROM, it will also be helpful to me.. I have evaluation version of Hi tech PRO 9.60PL5.

Thank you
NIKS
 

But sir,

It doesn't get run as you can see in my first post. I blinked three pins of Port C on successful write and read of single byte.
which doesn't happen.. when I read it, it gives 0xff..

Can you tell me where i made mistake in my code ?
or any fuse bit problems ?
Is it necessary to monitor WREER bit? I checked it just after calling write function and it's high.
Where it should be checked ?
is it the problem with my code ?

Thank you
NIKS
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top