0

我的任务是为 PIC16F84 微控制器编写 eeprom 读/写子程序。我写了这样的代码:

    EEPROM_Read
        clrw
        bsf     STATUS, RP0  ; Bank0
        movlw   DATA_EE_ADDR  ; Any location in Data EEPROM memory space
        movwf   EEADR        ; Address to read
        bsf     EECON1, RD   ; EE Read

        movlw   EEDATA
        bcf     STATUS, RP0  ; Bank0
        return

EEPROM_Write        
        bcf     INTCON,GIE      ;disable interrupts for EEPROM write
            banksel     EEADR           ;bank 2
            movfw       DATA_EE_ADDR        ;load write address to EEPROM address pointer
            movwf       EEADR
            movfw       DATA_EE_DATA        ;load write data to EEPROM data buffer
            movwf       EEDATA
            banksel     EECON1          ;bank 3
            bsf         EECON1,WREN         ;enable EEPROM write
            movlw       0x55 ;unlock codes
            movwf       EECON2
            movlw       0xAA
            movwf       EECON2
            bsf         EECON1,WR       ;enable EEPROM write
            btfsc       EECON1,WR       ;wait here until write completes
            goto        $-1
            bcf         EECON1,WREN     ;write complete, disable write mode
            banksel     0 ;bank 0
            movlw       0 ;are interrupts being used?
            xorwf       INTCON,W
            btfss       STATUS,Z
            bsf     INTCON,GIE      ;yes,enable interrupts
            return

这样对吗?我在使用 EEProm_Read 时遇到问题。似乎它不能正常工作。

4

1 回答 1

0

根据数据表信息,您的 EEPROM 读取代码是错误的,因为 EEADR 寄存器在存储库 0 中,而不是在您的代码案例中的存储库 1 中:

正确的代码是:

BCF    STATUS, RP0    ; Bank 0
MOVLW  DATA_EE_ADDR
MOVWF  EEADR          ; Address to read
BSF    STATUS, RP0    ; Bank 1
BSF    EECON1, RD     ; EE Read
BCF    STATUS, RP0    ; Bank 0
MOVF   EEDATA, W      ; W = EEDATA
于 2012-03-09T10:08:41.377 回答