Write to EEPROM on PIC

Are there any PIC microcontroller programmers here?

I am learning PIC microcontroller programming using pickit2 and 16F690 chip that comes with it. I am currently working on various objects. I can successfully read the byte from the EEPROM in the code if I set the EEPROM vaklue to MPLAB, but I can't seem to change the value using the PIC itself. Just nothing happens and I do not read the changed value, do I always get the original, which implies that the recording is not working?

This is my code for this section, am I missing something? I know that I have a lot of unnecessary bank switches, I added most of them to make sure that being in the wrong bank is not a problem.

        ; ------------------------------------------------------
        ; 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
+3
2

122 16F690 datasheet EEPROM:

BANKSEL EEADR                   ;
MOVF    DATA_EE_ADDR, W;
MOVWF   EEADR          ;Data Memory Address to write
MOVF    DATA_EE_DATA, W;
MOVWF   EEDAT                   ;Data Memory Value to write
BANKSEL EECON1                  ;
BCF     EECON1, EEPGD ;Point to DATA memory
BSF     EECON1, WREN   ;Enable writes
BCF     INTCON, GIE             ;Disable INTs.
BTFSC   INTCON, GIE             ;SEE AN576
GOTO    $-2
; BEGIN REQUIRED SEQUENCE
MOVLW   55h            ;       
MOVWF   EECON2         ;Write 55h
MOVLW   AAh                     ;
MOVWF   EECON2                  ;Write AAh
BSF     EECON1, WR              ;Set WR bit to begin write
BSF     INTCON, GIE             ;Enable INTs.
SLEEP                  ;Wait for interrupt to signal write complete
; END REQUIRED SEQUENCE
BCF     EECON1, WREN   ;Disable writes
BANKSEL 0x00           ;Bank 0

, :

 BCF     EECON1, EEPGD ;Point to DATA memory

EEPGD , ( -), , , .

, , . , EECON1.WR . , , , , .

+3

, EEPROM , #include, , EEPROM_WRITE (0, 0x00); EEPROM_WRITE ( , );

, . !

+1

Source: https://habr.com/ru/post/1741652/


All Articles