Connect with us

How to read and write the EEPROM of a PIC 18F442?

Discussion in '8bit Microcontrollers' started by Alexander, Jan 16, 2005.

Scroll to continue with content
  1. Alexander

    Alexander Guest

    I want to read and write the EEPROM of my PIC.
    Unfortunatly, this doesn't work the way it's intended.
    I want to call these functions to be called from an ISR and/or during normal
    code execution.
    I've added some code to restore the previous GIE state for this.
    Could someone help me???

    ThanX,

    Alexander


    WriteEE
    MOVLW DATA_EE_ADDR ;
    MOVWF EEADR ; Data Memory Address to read
    MOVLW DATA_EE_DATA ;
    MOVWF EEDATA ; Data Memory Value to write
    BCF EECON1, EEPGD ; Point to DATA memory
    BCF EECON1, CFGS ; Access program FLASH or Data EEPROM memory

    BCF GIETEST ; Save current GIE state
    BTFSC INTCON,GIE
    BSF INTTEST,GIET
    BCF INTCON, GIE ; Disable INTs.
    BSF EECON1, WREN ; Enable Write
    MOVLW 0x55 ;
    MOVWF EECON2 ; 55h must be written to EECON2
    MOVLW AAh ; to start write sequence
    MOVWF EECON2 ; Write AAh
    BSF EECON1,WR ; Set WR bit begin write
    BTFSC GIETEST ; Restore GIE state
    BSF INTCON,GIE ;

    ReadEE ; Adress already in W returns
    data in EEDATA
    MOVWF EEADR ; Data Memory Address to read
    BCF EECON1, EEPGD ; Point to DATA memory
    BCF EECON1, CFGS ; Access program FLASH or Data EEPROM memory
    BSF EECON1, RD ; EEPROM Read
     
  2. NewsGroup

    NewsGroup Guest

    I assume that somewhere you have the line

    #define GIETEST INTTEST,GIET

    Other than that it looks fine. - I assume that there is no banking with the
    18 series as your code has no BSF STATUS,RP0 type instructions.

    Mike.
     
  3. Alexander

    Alexander Guest

    Het volgende bericht werd op ons ingehakt door NewsGroup
    Yes, I do have that line included or something like that
    I assume the same especially since MPLAB gives me no warning (normally it
    does) about this.
    ThanX I will take a look at it later with a clear head and add some debug
    settings in the code to check everything out.
     
  4. Alexander

    Alexander Guest

    Found the (at least one) problem.
    How stupid can one be ;)
    I called the code and forgot the return :(


    Het volgende bericht werd op ons ingehakt door Alexander
     
  5. Alexander

    Alexander Guest

    The code was not completly correct :(
    It seemed that only 50% of the writes worked.

    So I added a check/wait to see if the previous write sequence was finished
    (a W bit somewhere in the intcom register).
    After that it worked fine but the following question(s) hit me (not very
    hard though):

    How long does it take for a write to complete???
    Is this (external) oscillator dependend???
    Does each write take about the same time???

    ThanX,

    Alexander


    Het volgende bericht werd op ons ingehakt door Alexander
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-