ok here is my code below.
its a simple EEPROM write and read test program.
Im using the following...
40MHz HSPLL (10MHz ceramic resonator)
PIC18F4220
C18 compiler
the result of this program should be a simple LED flash twice which it does after a successful read from the EEPROM.
However upon verifying this result in the MPLAB PM3 programmer, when reading the EEPROM, the result comes out completely blank in the EEPROM window. The data byte 0xEA is never written in the EEPROM location 0x00.
The same happens with 10MHz or 20Mhz clock speed. HOWEVER, the same program and EEPROM verification via PM3 programmer results perfectly only when I use a 4MHz ceramic resonator.
I have also tried changing the PIC to one of serveral PIC18F4220 that I have....but all give the same results as above.
From the above test results of my program i assume (plz correct me) that when i place the PIC on to the MPLAB PM3 programmer to read the the EEPROM, then during power down the PIC loses the EEPROM content. This is strange. I have a clean 7805 stable 5V output for the PIC. Before i take the PIC out from my board, the power supply is shut off for a moment and then I take out the PIC.
Please can someone help me out that for any clock speed above 4MHz, why does the EEPROM is not able to retain its contents after the power down.
thankyou
Haseeb
Code:
#include <p18f4220.h>
#include <delays.h>
#pragma config OSC = HSPLL
#pragma config WDT = OFF
#pragma config LVP = OFF
#define LED LATCbits.LATC3
unsigned char
HighByte = 0;
void main(void)
{
ADCON1 = 0x0F; //SET ALL PORTS as DIGITAL I/O
//initiallize all PORTs
PORTA = 0;
PORTB = 0;
PORTC = 0;
TRISCbits.TRISC3 = 0; //LED output
PORTD = 0;
PORTE = 0;
INTCON = 0; //disable all INTs
//byte write
EECON1bits.EEPGD = 0; //Ensure EEPGD is clear for EEDATA access
EECON1bits.WREN = 1; // //Ensure WREN is set to enable for no EEDATA writes
EEADR = 0x00; //Write address to EEADR at the respective location
EEDATA = 0xEA; //Set EEDATA to the value to write
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1; //Initiate write cycle by setting the WR bit
while (!PIR2bits.EEIF); //Wait for the EEIF flag to be set
PIR2bits.EEIF = 0; //Clear the EEIF flag
EECON1bits.WREN = 0; // //Ensure WREN is set to dissable for no EEDATA writes
//byte read
EECON1bits.EEPGD = 0; //Ensure EEPGD is clear for EEDATA access
EEADR = 0x00; //Store the address to EEADR
EECON1bits.RD = 1; //Trigger a read by setting the RD bit
HighByte = EEDATA;
if(HighByte == 0xEA) //are u the same byte read back from EEPROM?
{
//confirm correct byte read via LED flashing
LED = 1;
Delay10KTCYx(250); //250ms delay
LED = 0;
Delay10KTCYx(250); //250ms delay
LED = 1;
Delay10KTCYx(250); //250ms delay
LED = 0;
}
while(1); //loopforever (STOP)
} //end of main()