#include <pic.h>
/*
R/W eeprom on PIC16F87x
example:
main()
{
my_eeprom_write(addr,data);
if (my_eeprom_read(EEPROM_FORMAT_IN_PROGRESS)==TRUE) etc;
}
*/
void my_eeprom_write(unsigned char addr, unsigned char value)
{
//see 'writing to eeprom memory' in PIC16F876 manual
static bit gie_temp;
EEIF=0; //this is necessary in case this EEPROM write
//was preceded by a program memory write
EEADR=(unsigned char)(addr);
EEDATA=(unsigned char)(value);
EEPGD=0; //write to EEPROM, not data memory
gie_temp=GIE; //save the status of GIE
WREN=1; //enable writes
GIE=0;
EECON2=0x55;
EECON2=0xAA;
WR=1;
while (!EEIF)
{
//do nothing - wait WR to be cleared in hardware
}
EEIF=0; //so it wont trigger false interrupts
WREN=0; //disable writes
GIE=gie_temp; //restore GIE to previous value
}
#define MY_EEPROM_READ(addr) \
\
( (EEADR=((unsigned char)(addr))), \
(EEPGD=0), \
(RD=1), \
((unsigned char)EEDATA) )
unsigned char my_eeprom_read(unsigned char addr)
{
EEADR=(unsigned char)addr;
EEPGD=0;
RD=1;
return (unsigned char)EEDATA;
}
unsigned int my_eeprom_read_int(unsigned char addr)
{
return ((unsigned int)(eeprom_read(addr)) | ((unsigned int)((unsigned int)(eeprom_read((unsigned char)(addr+1)))<<8)));
}
void my_eeprom_write_int(unsigned char addr, unsigned int data)
{
eeprom_write(addr,(unsigned char)(data & 0xFF));
eeprom_write((unsigned char)(addr+1),(unsigned char)(data>>8));
}
- Board index
- Search
-
- It is currently Mon Oct 27, 2025 9:46 am
- All times are UTC+05:30
C Code for interafaing EPROM in PIC 16F87X
Microcontroller Topics
Jump to
- Programmable Electronics
- ↳ Arduino
- ↳ Raspberry Pi
- ↳ Microcontrollers
- ↳ FPGA
- ↳ Digital Signal Processors
- ↳ Other
- Programming
- ↳ Web programming
- ↳ PHP & MySQL
- ↳ ASP & ASP.Net
- ↳ .Net & Other Programming
- ↳ .NET Programming
- ↳ Visual Basic Programming
- ↳ Java Programming
- ↳ C/C++ Programming
- Engineering
- ↳ Electronics & Electrical Engineering
- ↳ Embedded Systems
- ↳ Computer Science
- ↳ Software Engineering
- ↳ Data Structures & Algorithms
- ↳ Programming Languages & Compiler Theory
- ↳ Operating Systems
- ↳ Cryptography
- ↳ Computer Networks
- ↳ SQL & Database
- ↳ Computer Architecture
- ↳ Graphics & Vision
- ↳ Artificial Intelligence
- ↳ Neural Networks
- ↳ Multimedia
- ↳ Mathematics
- ↳ Other
- ↳ Control Systems & Robotics
- ↳ Mechanical
- ↳ Thermodynamics
- ↳ Fluid Dynamics
- ↳ Aerodynamics
- ↳ Manufacturing
- ↳ Energy
- ↳ Dynamics
- ↳ Statics
- ↳ Automobile
- ↳ Other
- ↳ Other
- Operating Systems
- ↳ Windows
- ↳ Linux
- ↳ Mac OS
- ↳ Android
- ????? ????
- ↳ ???????? ?????
- ↳ ??????? ???? ?????
- ↳ ????? ?????? ???? (Buy Guide)
- ↳ ??????? ???? ??????? (Where to buy)
- ↳ ????????? ???????? (Recommend - Complain - Review)
- General
- ↳ News & Announcements
- ↳ General Discussions
- ↳ Viruses, Trojans, Spyware and Adware
- ↳ Computer & Network Security
- ↳ Web Related
- Members Zone
- ↳ Project Assistance
- ↳ Advertising
- ↳ Jobs & Investment Opportunities
- ↳ Introductions
- ↳ Presents & Donations
- ↳ Entertainment
- ↳ Music & Albums
- ↳ Movies
- ↳ Games

