1. quantumlab

    Thread Starter Member

    Dec 4, 2008
    19
    0
    Hi I would like to store a set of numbers on the eeprom and then send them to the PC and view them on the USART terminal. I have this much working. I am storing values from 4 to 23. However i would like to run the code a second time and view the values on the eeprom again (just to see if they are being stored). However when i reprogram the PIC to to read the EEPROM each address of the eeprom just reads 255. Are the values being erased when i reprogram the PIC? Or are they even being stored in the first place? any help would be great. The code is shown below.

    int i;
    int k ;

    unsigned short temp_res, temp_res2;

    void main() {
    ANSEL = 0; // Configure AN pins as digital I/O
    ANSELH = 0;
    // PORTB = 0; // Initial PORTB value
    TRISB = 0; // Set PORTB as output
    // PORTD = 0;
    TRISD = 0;

    j = 4;
    for (i = 0; i < 21; i++) // Write some data to EEPROM
    EEprom_Write(i, j++);

    for (i = 0; i < 21; i+=2) {
    USART_Init(19200); // Initalize USART (19200 baud rate, 1 stop bit, no parity...)

    temp_res = PORTD; // Read 10-bit ADC from AN2 and discard 2 LS bits
    temp_res2 = PORTB ;
    Delay_ms(100);
    PORTD = EEPROM_Read(i); // Read data and display it on PORTB
    PORTB = EEPROM_Read(i+1) ;
    USART_Write(temp_res); // Send ADC reading as byte
    USART_Write(temp_res2);
    Delay_ms(500);
    }

    }
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Some programmers erase the EEPROM during programming. Check the programmers software settings.
     
  3. quantumlab

    Thread Starter Member

    Dec 4, 2008
    19
    0
    Hi thanks for the help however after taking our advice i disabled the 'master clear' function in the settings. this however still hasnt solved the problem. The following have been switched off: watch dog timer, power up timer, master clear, low voltage program, in-circuit debugger. The following have been enabled: brown out detect, data ee protect, int-ext switchover, fail-safe clock monitor.

    We are using PIC flash v7.11 with the easypic5 development board along with a 16f887.

    please help...
     
  4. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    If the addresses are coming up 255 each time, then you are either not writing to the EEPROM, or your interface is incorrect. Are you sending the correct signals to read and write to the EEPROM? That information will be in the data sheet for the device.
     
  5. quantumlab

    Thread Starter Member

    Dec 4, 2008
    19
    0
    From our code you can see that we have written to the EEprom. (EEprom_Write(i, j++); command used from example mikroC code). When we run the code it works and the stored values are sent to the PC however when we would like to view it a second time i.e. eliminating lines:

    j = 4;
    for (i = 0; i < 21; i++) // Write some data to EEPROM
    EEprom_Write(i, j++);

    it will not work and only 255 values are displayed
     
  6. quantumlab

    Thread Starter Member

    Dec 4, 2008
    19
    0
    Just to check if i was writing to the EEPROm i ran the simple example eeprom code shown in bold. then i re-ran it excluding the writing commands. And the result was 255 on portb. Therefore it is definetly something to do with the settings. please help

    char i, j;
    void main() {
    ANSEL = 0; // Configure AN pins as digital I/O
    ANSELH = 0;
    PORTB = 0; // Initial PORTB value
    TRISB = 0; // Set PORTB as output

    //j = 4;
    //for (i = 0; i < 20u; i++) // Write some data to EEPROM
    //EEprom_Write(i, j++); // at addresses 0..19

    Delay_ms(50);

    for (i = 0; i < 20u; i++) {
    PORTB = EEPROM_Read(i); // Read data and display it on PORTB
    Delay_ms(500);
    }
    }
     
  7. rajbex

    New Member

    Nov 2, 2009
    22
    0
Loading...