• AVR Freaks

Hot!PIC18f4620 EEEPROM READ WRITE throw ARRAY :PROBLEM

Author
MOHAEGY
Starting Member
  • Total Posts : 89
  • Reward points : 0
  • Joined: 2020/05/27 11:33:24
  • Location: 0
  • Status: offline
2020/09/17 23:47:51 (permalink)
0

PIC18f4620 EEEPROM READ WRITE throw ARRAY :PROBLEM

HELLO EVERY ONE 
COMILER:/ MPLAB XC8 
TARGET DEVICE:/ PIC18F4620
THIS CODE below IS COMPILED WITH NO PROBLEM and LCD type "EPROM PROGRAMMED OK" BUT NO WRITE HAPPENED TO EEPROM  WHY?
 
////////////////////////// DECLARATION ///////////////////////////////////////////////////////////////
volatile uint8_t PARM = 0X00; // used to store the array element new value
volatile uint8_t *ARRYPTR = 0X00; // ARRRAY POINTER


volatile uint8_t EPROM_VAR[69]= {01,0X08,16,00,02,04,16,00,01,0X08,32,64,03,04,16,64,12,0X08,0X08,03,20,
30,80,01,50,70,04,60,60,98,12,00,0X08,10,32,32,32,32,31,00,32,00,32,32,15,06,05,00,00,90,01,01,01,01,
01,01,01,01,01,01,20,22,26,0X09,00,00,00,05,00};

//////// calls functions ///////

void WRITE_EPROM(void)
{
EEADRH = 0X00;
EEADR = PARM; // writing address
ARRYPTR = &EPROM_VAR[(PARM)];
EEDATA =*ARRYPTR; // data for save
EECON1bits.EEPGD = 0;
EECON1bits.CFGS = 0;
EECON1bits.WREN = 1; // allows writing to Flash/EEPROM
INTCONbits.GIE = 0; // Disable general interrupt
EECON2 = 0X55; // don't modify catalog data
EECON2 = 0X0AA; // don't modify catalog data
EECON1bits.WR = 1; // initialize write cycle
while (EECON1bits.WR){

// wait until write done
}
EECON1bits.WREN = 0; // disable writing to Flash/EEPROM
__delay_ms(20);
//INTCONbits.GIE = 1; // Re-enable general interrupt
}
 
void READ_EPROM(void)
{
EEADRH = 0X00;
EEADR = PARM; // reading address
EECON1bits.EEPGD = 0;
EECON1bits.CFGS = 0;
EECON1bits.RD = 1;
mydata = EEDATA; // result in eeprom location stored data read
EPROM_VAR[(PARM)]= mydata;
__delay_ms(20);
}
////////////////////IN MAIN ROUTINE I USE /////////////////////////////////
PARM = 0X00;
for (a = 0; a < 69; a++) {
WRITE_EPROM();
PARM ++;
__delay_ms(100);
}
Lcd_Init();
__delay_ms(100);
Lcd_Clear();
__delay_ms(100);
Lcd_Set_Cursor(1, 0);
Lcd_Write_String("EPROM Programmed");
Lcd_Set_Cursor(2, 2);
Lcd_Write_String("*** OK ***");
while(1){

}
 
///////////// for read EEPROM content to the array i use ////////////////
uint8_t cou = 0;
for (cou = 0; cou < 69; cou++) {
READ_EPROM();
__delay_ms(5);
PARM ++;
}
 
i program the target with write routine then disable it and program the target again and i see that all array elemnts = 255 
 
Thanks
 
 
 
 
#1

5 Replies Related Threads

    ric
    Super Member
    • Total Posts : 28629
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC18f4620 EEEPROM READ WRITE throw ARRAY :PROBLEM 2020/09/18 01:18:58 (permalink)
    +1 (1)
    That's a bad testing method.
    When you program again it is erasing the eeprom if you don't specifically organise to preserve the eeprom.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    MOHAEGY
    Starting Member
    • Total Posts : 89
    • Reward points : 0
    • Joined: 2020/05/27 11:33:24
    • Location: 0
    • Status: offline
    Re: PIC18f4620 EEEPROM READ WRITE throw ARRAY :PROBLEM 2020/09/18 02:14:02 (permalink)
    0
    SIR/RIC 
    it's ok i don't now that [erase before program] is erase EEPROM also. 
    Now how i can store values in EEPROM just for first time then this values will be changed by user in programming mode routine 
    thanks
    #3
    MOHAEGY
    Starting Member
    • Total Posts : 89
    • Reward points : 0
    • Joined: 2020/05/27 11:33:24
    • Location: 0
    • Status: offline
    Re: PIC18f4620 EEEPROM READ WRITE throw ARRAY :PROBLEM 2020/09/18 06:32:52 (permalink)
    0
    IT'S ok i solve the problem and found many ways to do EEPROM programming just in the first reset after program burn 
    my code work now and EEPROM programmed true 
     
    NOW i noticed that when i build the code there are 00 bytes usage appear in EEPROM SPACE in the Memory Summary 
    why that?
     
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 18961
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC18f4620 EEEPROM READ WRITE throw ARRAY :PROBLEM 2020/09/18 10:58:43 (permalink)
    +2 (2)
    You did not initialize the data.
    How does the compiler know how much memory you’ve used?
    Look at the manual.
    _EEPROM_DATA()
    #5
    MOHAEGY
    Starting Member
    • Total Posts : 89
    • Reward points : 0
    • Joined: 2020/05/27 11:33:24
    • Location: 0
    • Status: offline
    Re: PIC18f4620 EEEPROM READ WRITE throw ARRAY :PROBLEM 2020/10/01 10:51:33 (permalink)
    +1 (1)
    Ok nice SIR/NKURZMAN I USE THIS 
    #include <xc.h>
    __EEPROM_DATA(0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07);
    __EEPROM_DATA(0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F);
    __EEPROM_DATA(0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07);
    __EEPROM_DATA(0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F);
    __EEPROM_DATA(0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07);
    __EEPROM_DATA(0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F);
    __EEPROM_DATA(0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07);
    __EEPROM_DATA(0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F);
    __EEPROM_DATA(0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07);
    __EEPROM_DATA(0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F);
    __EEPROM_DATA(0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07);
    __EEPROM_DATA(0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F);
    __EEPROM_DATA(0x00,0x01,0x02,0x03,0,0,0,0);
    ITS WORK FINE AND THE there are 104 bytes usage appear in EEPROM SPACE in the Memory Summary 
    Thanks
    #6
    Jump to:
    © 2020 APG vNext Commercial Version 4.5