+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Full Member level 3
    Points: 1,837, Level: 9
    tahir4awan's Avatar
    Join Date
    Nov 2010
    Posts
    183
    Helped
    15 / 15
    Points
    1,837
    Level
    9

    Pic16f887 eeprom read/write

    I wrote a simple code to write and read data from EEPROM. The code is working
    for all ports except PORTB. What is the problem?
    ----------------------------------------------------------------------------
    void main(){

    ANSEL = 0; // Configure AN pins as digital I/O
    ANSELH = 0;
    C1ON_bit = 0; // Disable comparators
    C2ON_bit = 0;



    TRISB = 0x00;
    PORTB = 0x00;




    EEPROM_Write(0x50,0xAA);

    Delay_ms(1000);

    PORTB = EEPROM_Read(0x50);




    }
    ----------------------------------------------------------------------------

    Secondly MikroC uses its own built in functions
    EEPROM_Write(0x50,0xAA);
    EEPROM_Read(0x50);

    and PIC microcontroller has EECON1 and EECON2 registers. What is the difference?

    •   Alt10th May 2011, 02:19

      advertising

        
       

  2. #2
    Full Member level 4
    Points: 2,455, Level: 11

    Join Date
    Oct 2008
    Posts
    238
    Helped
    32 / 32
    Points
    2,455
    Level
    11

    Re: Pic16f887 eeprom read/write

    you need to prevent the mcu from going into sleep state, add an infinite loop at the main procedure, something like this.

    void main()
    {
    procedure1();
    do{

    } While(TRUE);

    }

    When the MCU goes into sleep, the program execution stops, so to keep the mcu busy you need to give it work.



    •   Alt10th May 2011, 07:13

      advertising

        
       

  3. #3
    Full Member level 1
    Points: 1,075, Level: 7
    bjuric's Avatar
    Join Date
    May 2011
    Location
    Serbia
    Posts
    115
    Helped
    31 / 31
    Points
    1,075
    Level
    7

    Re: Pic16f887 eeprom read/write

    Check the datasheet.
    EECON1 contains EEPROM contol bits
    EECON2 does not exist physically. That's a virtual register in which you need to write 0x55 and 0xAA (one after the other) before initiating EEPROM write. It serves as a protection from accidental writing into EEPROM. EEPROM_Write() does that for you.



    •   Alt10th May 2011, 11:49

      advertising

        
       

  4. #4
    Full Member level 3
    Points: 1,837, Level: 9
    tahir4awan's Avatar
    Join Date
    Nov 2010
    Posts
    183
    Helped
    15 / 15
    Points
    1,837
    Level
    9

    Re: Pic16f887 eeprom read/write

    My point is the same code is working for all ports but not for PORTB. It means code is correct.



  5. #5
    Full Member level 4
    Points: 2,552, Level: 11
    thunderboympm's Avatar
    Join Date
    Sep 2007
    Location
    Malappuram, India
    Posts
    215
    Helped
    31 / 31
    Points
    2,552
    Level
    11

    Re: Pic16f887 eeprom read/write

    assign the eeprom value to a variable and then to portb. I got same error, i solved like this. Don't ask me the theory behind this i don't know



  6. #6
    Full Member level 3
    Points: 1,837, Level: 9
    tahir4awan's Avatar
    Join Date
    Nov 2010
    Posts
    183
    Helped
    15 / 15
    Points
    1,837
    Level
    9

    Re: Pic16f887 eeprom read/write

    thunderboympm I think you have become angry but Thanks for your help.



  7. #7
    Full Member level 4
    Points: 2,552, Level: 11
    thunderboympm's Avatar
    Join Date
    Sep 2007
    Location
    Malappuram, India
    Posts
    215
    Helped
    31 / 31
    Points
    2,552
    Level
    11

    Re: Pic16f887 eeprom read/write

    no, i am not angry my friend. I donot know why is this.



+ Post New Thread
Please login