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