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

📄 fl62xinc.asm

📁 Code for PIC with FLASH EE data memory interface
💻 ASM
📖 第 1 页 / 共 2 页
字号:
        GOTO    $+1       
#endif
#ifdef  TENMHZ
        call    delay6  ; Necessary for EESCL Tlow at low voltage, (4.7us)
#endif
#ifdef  TWENTYMHZ
        call    delay12
#endif

        BSF     EEINTF,EESCL  ; Raise EESCL, EEPROM acknowledge still valid
#ifdef  FOURMHZ
        NOP                   ; Tsu:dat (allow time for ack setup)
#endif
#ifdef  TENMHZ
        call    delay4
#endif
#ifdef  TWENTYMHZ
        call    delay8
#endif
        BTFSC   EEINTF,EESDA  ; Check EESDA for acknowledge (low)
        BCF     PC_OFFSET,EE_OK ; If EESDA not low (no ack), set error flag
#ifdef  TENMHZ
        call    delay4
#endif
#ifdef  TWENTYMHZ
        call    delay8
#endif
        BCF     EEINTF,EESCL    ; Lower EESCL, EEPROM release bus
        BTFSS   PC_OFFSET,EE_OK ; If no error continue, else stop bit
        GOTO    STOP_BIT


;*****  Set up program counter offset, based on EEPROM operating mode  *****
;***************************************************************************
STATEMACHINE

        MOVF    PC_OFFSET,W
        ANDLW   B'00001111'
        ADDWF   PCL, F
	GOTO    INIT_ADDRESS      ;PC offset=0, write control done, send address
	GOTO    INIT_WRITE_DATA   ;PC offset=1, write address done, send data
	GOTO    STOP_BIT          ;PC offset=2, write done, send stop bit
	GOTO    INIT_ADDRESS      ;PC offset=3, write control done, send address
	GOTO    INIT_READ_CONTROL ;PC offset=4, send read control
	GOTO    READ_BIT_COUNTER  ;PC offset=5, set counter and read byte
	GOTO    STOP_BIT          ;PC offset=6, random read done, send stop
	GOTO    INIT_ADDRESS      ;PC offset=7, write control done, send address
	GOTO    INIT_WRITE_PAGE_DATA   ;PC offset=8, write address done, send data
	GOTO    STOP_BIT          ;PC offset=9, write done, send stop bit
	GOTO    INIT_ADDRESS      ;PC offset=A, write control done, send address
	GOTO    INIT_READ_PAGE_CONTROL ;PC offset=B, write address done, send data
	GOTO    READ_PAGE_BIT_COUNTER  ;PC offset=C, set counter and read byte


;**********  Initalize EEPROM data (address, data, or control) bytes  ******
;***************************************************************************
INIT_ADDRESS
	INCF    PC_OFFSET, F ; Increment PC offset to 2 (write) or to 4 (read)
	MOVF    EEADDR,W     ; Put EEPROM address in W, ready to send to EEPROM
	GOTO    PREP_TRANSFER_BYTE

INIT_WRITE_DATA
	INCF    PC_OFFSET, F ; Increment PC offset to go to STOP_BIT next
	MOVF    EEDATA,W     ; Put EEPROM data in W, ready to send to EEPROM
	GOTO    PREP_TRANSFER_BYTE

INIT_WRITE_PAGE_DATA
	DECFSZ	bytecount,f	; count byte tx'd
	GOTO	$+2		; 
	INCF    PC_OFFSET, F    ; Increment PC offset to go to STOP_BIT next
	MOVF    INDF,W          ; Put EEPROM data in W, ready to send to EEPROM
	INCF	FSR,F		; bump pointer
	GOTO    PREP_TRANSFER_BYTE

INIT_READ_CONTROL
	BSF     EEINTF,EESCL ; Raise EESCL
	BSF     EEINTF,EESDA ; raise EESDA
	INCF    PC_OFFSET, F ; Increment PC offset to go to READ_BIT_COUNTER next
	MOVLW   B'10100001'  ; Set up read control byte, ready to send to EEPROM
	GOTO    START_BIT    ;   bit 0 = '1' for read operation


INIT_READ_PAGE_CONTROL
	BSF     EEINTF,EESCL ; Raise EESCL
	BSF     EEINTF,EESDA ; raise EESDA
	INCF    PC_OFFSET, F ; Increment PC offset to go to READ_BIT_COUNTER next
	MOVLW   B'10100001'  ; Set up read control byte, ready to send to EEPROM
	GOTO    START_BIT    ;   bit 0 = '1' for read operation

;**************************  Read EEPROM data  *****************************
;***************************************************************************
READ_PAGE_BIT_COUNTER
	BSF     EEINTF,EESDA ; set data bit to 1 so we're not pulling bus down.
	NOP
	BSF     EEINTF,EESCL
	MOVLW   .8           ; Set counter so 8 bits will be read into EEDATA
	MOVWF   COUNTER

READ_BYTE_RPC
#ifdef  TENMHZ
        call    delay6
#endif
#ifdef  TWENTYMHZ
        call    delay12
#endif
	BSF     EEINTF,EESCL ; Raise EESCL, EESDA valid.  EESDA still input from ack
	SETC                 ; Assume bit to be read = 1
#ifdef  TENMHZ
        call    delay6
#endif
#ifdef  TWENTYMHZ
        call    delay12
#endif
	BTFSS   EEINTF,EESDA ; Check if EESDA = 1
	CLRC                 ; if EESDA not = 1 then clear carry bit
	RLF     EEDATA, F    ; rotate carry bit (=EESDA) into EEDATA;
	BCF     EEINTF,EESCL ; Lower EESCL
	BSF     EEINTF,EESDA ; reset EESDA
	DECFSZ  COUNTER, F   ; Decrement counter
	GOTO    READ_BYTE_RPC    ; Read next bit if not finished reading byte

	movf	EEDATA,w
	movwf	INDF		; write data to buffer
	incf	FSR,f		; increment buffer pointer
	decfsz	bytecount,f
	GOTO	SEND_ACK
	GOTO	SEND_NAK	; skip next 2 instructions
SEND_ACK
	BCF	EEINTF,EESDA	; Send an ACK (More reads to come)
	BSF     EEINTF,EESCL	; 
	NOP
	BCF     EEINTF,EESCL
	GOTO	READ_PAGE_BIT_COUNTER	
SEND_NAK
	BSF	EEINTF,EESDA	; Send an ACK (More reads to come)
	BSF     EEINTF,EESCL	; 
	NOP
	BCF     EEINTF,EESCL
	GOTO	STOP_BIT	; skip next 2 instructions
	
; end read page bit control

READ_BIT_COUNTER
	BSF     EEINTF,EESDA ; set data bit to 1 so we're not pulling bus down.
	NOP
	BSF     EEINTF,EESCL
	MOVLW   .8           ; Set counter so 8 bits will be read into EEDATA
	MOVWF   COUNTER

READ_BYTE_RBC
#ifdef  TENMHZ
        call    delay6
#endif
#ifdef  TWENTYMHZ
        call    delay12
#endif
	BSF     EEINTF,EESCL ; Raise EESCL, EESDA valid.  EESDA still input from ack
	SETC                 ; Assume bit to be read = 1
#ifdef  TENMHZ
        call    delay6
#endif
#ifdef  TWENTYMHZ
        call    delay12
#endif
	BTFSS   EEINTF,EESDA ; Check if EESDA = 1
	CLRC                 ; if EESDA not = 1 then clear carry bit
	RLF     EEDATA, F    ; rotate carry bit (=EESDA) into EEDATA;
	BCF     EEINTF,EESCL ; Lower EESCL
	BSF     EEINTF,EESDA ; reset EESDA
	DECFSZ  COUNTER, F   ; Decrement counter
	GOTO    READ_BYTE_RBC    ; Read next bit if not finished reading byte

	BSF     EEINTF,EESCL
	NOP
	BCF     EEINTF,EESCL
;******************  Generate a STOP bit and RETURN  ***********************
;***************************************************************************
STOP_BIT
	BCF     EEINTF,EESDA ; EESDA=0, on TRIS, to prepare for transition to '1' 
	BSF     EEINTF,EESCL ; EESCL = 1 to prepare for STOP bit
#ifdef  FOURMHZ
        call    delay4  ; wait 4 cycles  Tsu:sto (4.7 us)
#endif
#ifdef  TENMHZ
        call    delay10
#endif
#ifdef  TWENTYMHZ
        call    delay20
#endif
	BSF     EEINTF,EESDA ; Stop bit, EESDA transition to '1' while EESCL high
	BCF	STATUS,RP0
    
	BTFSS   PC_OFFSET,EE_OK ; Check for error
	RETLW   NO              ; if error, send back NO 
	RETLW   OK         ; if no error, send back OK
#ifdef TWENTYMHZ
delay20 goto    delay18
delay18 goto    delay16
delay16 goto    delay14
delay14 goto    delay12
delay12 goto    delay10
delay10 goto    delay8
delay8  goto    delay6
delay6  goto    delay4
delay4  return
#endif
#ifdef TENMHZ
; delay function.  Wait a number of cycles.  
delay10 goto    delay8
delay8  goto    delay6
delay6  goto    delay4
delay4  return
#endif
#ifdef FOURMHZ
delay4	return
#endif

;****************************************************************************
;************************  End EEPROM Subroutines  **************************

⌨️ 快捷键说明

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