futz
Active Member
Am I using MPLAB's View EEPROM command wrong? I have written code for 16F876 to write a byte to EEPROM. After running it I refresh the View EEPROM window and nothing has changed. Am I using the tool wrong?
Or is there something wrong with my code? I've written it the hard way as well as the easy way, using BoostC's EEPROM lib.
The (not so) hard way:
The easy way with the lib:
and the header file:
Or is there something wrong with my code? I've written it the hard way as well as the easy way, using BoostC's EEPROM lib.
The (not so) hard way:
Code:
#include "eep.h"
void main(void)
{
while(eecon1.WR){} //wait for write to finish
eeadr=5; //set address to write to
eedata=0x56; //set data to write
eecon1.EEPGD=0; //clear EEPGD - point to EEPROM data memory
eecon1.WREN=1; //enable writes
eecon2=0x55;
eecon2=0xaa;
eecon1.WR=1;
eecon1.WREN=0; //disable writes
while(1){}
}
The easy way with the lib:
Code:
#include "eep.h"
#include <eeprom.h>
void main(void)
{
eeprom_write(5,0x56);
while(1){}
}
and the header file:
Code:
#include <system.h>
#include <stdio.h>
#pragma CLOCK_FREQ 18432000
#pragma DATA _CONFIG, _WDT_OFF & _HS_OSC & _LVP_OFF
Last edited: