Writing to EEPROM on PIC

Posted by JB on Stack Overflow See other posts from Stack Overflow or by JB
Published on 2010-04-18T10:04:27Z Indexed on 2010/04/18 10:13 UTC
Read the original article Hit count: 435

Filed under:
|

Are there any PIC microcontroller programmers here?

I'm learning some PIC microcontroller programming using a pickit2 and the 16F690 chip that came with it. I'm working through trying out the various facilities at the moment. I can sucessfully read a byte from the EEPROM in code if I set the EEPROM vaklue in MPLAB but I don't seem to be able to modify the value using the PIC itsself. Simply nothing happens and I don't read back the modified value, I always get the original which implies to me that the write isn't working?

This is my code for that section, am I missing something? I know I'm doing a lot of unnecessary bank switches, I added most of them to ensure that being on the wrong bank wasn't the issue.

        ; ------------------------------------------------------
        ; Now SET the EEPROM location ZERO to 0x08
        ; ------------------------------------------------------

        BANKSEL EEADR
        CLRF    EEADR           ; Set EE Address to zero

        BANKSEL EEDAT
        MOVLW   0x08            ; Store the value 0x08 in the EEPROM
        MOVWF   EEDAT

        BANKSEL EECON1
        BSF     EECON1, WREN    ; Enable writes to the EEPROM

        BANKSEL EECON2
        MOVLW   0x55            ; Do the thing we have to do so
        MOVWF   EECON2          ; that writes can work
        MOVLW   0xAA
        MOVWF   EECON2

        BANKSEL EECON1      
        BSF     EECON1, WR      ; And finally perform the write

WAIT
        BTFSC   EECON1, WR      ; Wait for write to finish
        GOTO    WAIT

        BANKSEL PORTC           ; Just to make sure we are on the right bank

© Stack Overflow or respective owner

Related posts about microcontroller

Related posts about assembly