⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eeprom.asm

📁 VCP201_CODE is a FPGA source code.
💻 ASM
字号:
;==========================================================================
; File Name : 
;
; Rev:   Date:    Author:     Reason:
; 1.00   dd-mm-yy nnnnnnnnnnn rrrrrrrrrrrrrrrrrr
;==========================================================================


;------------------------------------------------------------
; Name : 
; Parm : nil
; Retn : f_eeexist
; Desc : 
;------------------------------------------------------------
;ee_detect:
;        bsf     STATUS,RP0      ; BANK 1
;        movlw   DIR_EEDET_E     ; CS pin to input mode
;        movwf   TRISE
;        bcf     STATUS,RP0      ; BANK 0
;        nop
;        nop
;        nop
;        bcf     f_eeexist
;        btfss   eecs_pin        ; cs pin high -> config as no EE
;        bsf     f_eeexist
;        bsf     STATUS,RP0      ; bank 1
;        movlw   DIR_HIZ_E       ; 
;        movwf   TRISE
;        bcf     STATUS,RP0      ; bank 0
;        return

;------------------------------------------------------------
; Name : 
; Parm : ee_addr
; Retn : ee_buf0,ee_buf1
; Desc : 
;------------------------------------------------------------
ee_read:
        call    ee_access

        movlw   b'11000000'     ; 110:read command
        movwf   ee_io_buf
        movlw   3
        call    ee_io           ; out 3bits command

        rlf     ee_addr,W
        movwf   ee_io_buf
        rlf     ee_io_buf,F
        movlw   6
        call    ee_io           ; out 6 bits address

        clrf    ee_io_buf
        movlw   8               ; read hi 8bits
        call    ee_io
        movf    ee_io_buf,W
        movwf   ee_buf1

        clrf    ee_io_buf
        movlw   8               ; read lo 8bits
        call    ee_io
        movf    ee_io_buf,W
        movwf   ee_buf0

        goto    ee_finish

;------------------------------------------------------------
; Name : 
; Parm :
; Retn : 
; Desc : 
;------------------------------------------------------------
ee_write:
        call    ee_access

        movlw   b'10100000'     ; 101:write command
        movwf   ee_io_buf
        movlw   3
        call    ee_io           ; out 3bits command

        rlf     ee_addr,W
        movwf   ee_io_buf
        rlf     ee_io_buf,F
        movlw   6
        call    ee_io           ; out 6 bits address

        movf    ee_buf1,W
        movwf   ee_io_buf
        movlw   8
        call    ee_io           ; out hi 8bits data

        movf    ee_buf0,W
        movwf   ee_io_buf
        movlw   8
        call    ee_io           ; out lo 8bits data

        call    ee_ready        ; wait self-programming finish

        goto    ee_finish

;------------------------------------------------------------
; Name : 
; Parm :
; Retn : 
; Desc : 
;------------------------------------------------------------
ee_erase:
        call    ee_access

        movlw   b'11100000'     ; 111:erase command
        movwf   ee_io_buf
        movlw   3
        call    ee_io           ; out 3bits command

        rlf     ee_addr,W
        movwf   ee_io_buf
        rlf     ee_io_buf,F
        movlw   6
        call    ee_io           ; out 6 bits address

        call    ee_ready        ; wait self-programming finish

        goto    ee_finish

;------------------------------------------------------------
; Name : 
; Parm : STATUS,C:1-write protect, 0-unprotect
; Retn : 
; Desc : 
;------------------------------------------------------------
ee_wprot:
        call    ee_access

        movlw   b'10000000'     ; 100:write enable/disable command
        movwf   ee_io_buf
        movlw   3
        call    ee_io           ; out 3bits command

        movlw   b'11000000'     ; enable
        btfsc   STATUS,C
        movlw   b'00000000'     ; disable if C set
        movwf   ee_io_buf
        movlw   6
        call    ee_io           ; out 6bits address

        goto    ee_finish

;------------------------------------------------------------
; Name : 
; Parm : nil
; Retn : nil
; Desc : assume CS is already low.
;------------------------------------------------------------
ee_access:
        bcf     INTCON,GIE      ; e2prom access is timing critical
        btfsc   INTCON,GIE
        goto    ee_access

        clrf    PORTE

        bsf     STATUS,RP0
        movlw   DIR_HIZ_B        ; change DO pin to input before CS
        movwf   TRISB
        bcf     STATUS,RP0

        bsf     eecs_pin        ; select E2PROM
        return

;------------------------------------------------------------
; Name : 
; Parm : nil
; Retn : nil
; Desc : assume CS is already low.
;------------------------------------------------------------
ee_finish:
        bcf     eecs_pin        ; deselect E2PROM

        bsf     STATUS,RP0
        movlw   DIR_HIZ_B
        movwf   TRISB
        bcf     STATUS,RP0

        bcf     eesk_pin        ; clear changed pins to Low
        bcf     eedi_pin
        bcf     eedo_pin

;       bsf     INTCON,GIE      ; do not forget to do this!
        return

;------------------------------------------------------------
; Name : 
; Parm : nil
; Retn : nil
; Desc :
;------------------------------------------------------------
ee_ready:
        bcf     eecs_pin
        nop
        nop
        nop
        goto    $+1
        nop
        bsf     eecs_pin        ; >1us from cs low
ee_ready_lp:
        btfss   eedo_pin
        goto    ee_ready_lp
        bcf     eecs_pin
        return
        
;------------------------------------------------------------
; Name : 
; Parm : ee_io_buf: data to eeprom
;        W: number of bits to out, number of bits to in + 1
; Retn : ee_io_buf: data from eeprom;
; Desc : 
;------------------------------------------------------------
ee_io:                          ; sk  di  do
        movwf   ee_io_cnt       ; | |  X   |
        bcf     eesk_pin        ; |_|  X   |
        nop
        bcf     eedi_pin        ; |   |    |
        btfsc   ee_io_buf,7     ; |   |    |
        bsf     eedi_pin        ; |   |_   |
        nop                     ; |   | |  |
        bcf     STATUS,C        ; |   | |  |
ee_io_lp:
        bsf     eesk_pin        ; |_  | |  X
        rlf     ee_io_buf,F     ;   | | |  X
        btfss   ee_io_buf,7     ;   | | |  X
        bcf     eedi_pin        ;   | | |  X
        btfsc   ee_io_buf,7     ;   |  X   X
        bsf     eedi_pin        ;   |  X  | |
        nop                     ;
        bcf     eesk_pin        ;  _| | | | |
        bcf     STATUS,C        ; |   | | | |
        btfsc   eedo_pin        ; |   | | | |
        bsf     STATUS,C        ; |   | | | |
        decfsz  ee_io_cnt,F     ; |   | | | |
        goto    ee_io_lp        ; |   | | | |
        rlf     ee_io_buf,F     ; |   | | | |
        return



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -