Simulator and EECON1,WR

Status
Not open for further replies.

ibwev

Member
I am troubleshooting a program using MPLAB Simulator. In the code, I am learning to work with EEPROM by writting data to it and then trying to read from it. When writting data to EEPROM, the write control bit of EECON1 correctly sets. However, it does not clear after the information is written. The 16F690 datasheet says it is cleared by hardware. Can a set Write Control Bit of EECON1 clear while using the MPLAB Simulator. If so, how?
 
In simulator it does not clear.Never tried.

But in modern PIC's like 16F886 it still does not clear.You have to poll the EEIF bit for a write complete.
 
Great help. Polling the EEIF bit works in the MPLAB Simulator. I can now troubleshoot writes and reads in EEPROM.
 
But in modern PIC's like 16F886 it still does not clear.You have to poll the EEIF bit for a write complete.

Not according to the data sheet.



Mike.
 

Attachments

  • eeprom.png
    65.8 KB · Views: 260
Last edited:
Mike I tried that WR bit in real life.But it never gets clear.So I poll the EEIF bit as shown in the 886 data sheet.
 
I think this shed some light in here

Interrupt flag bit EEIF
The user can either
enable this interrupt or poll this bit. EEIF must be
cleared by software.
 
Last edited:
Just tried this and the WR bit does get cleared in the simulator.

Code (BoostC format) for any one to try,
Code:
#include <system.h>

#pragma DATA _CONFIG, _DEBUG_OFF & _MCLRE_ON
                    & _CP_OFF & _PWRTE_OFF
                    & _WDT_OFF & _INTOSCIO
                    & _LVP_OFF

#pragma CLOCK_FREQ 8000000


void main(void){
    osccon=0x71;            //8 meg
    ansel=0;
    anselh=0;

    eedata=0x23;
    eeadr=0;
    eecon1=0b0000100;

    eecon2=0x55;
    eecon2=0xaa;
    eecon1.WR=1;

    while(eecon1.WR);

    while(1){

    }//end while
}//end main

Edit, it will not work if you single step through the code as the required sequence doesn't get followed.

Mike.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…