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

📄 93c46.asm

📁 基于pic的例子程序
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	movlw   b'00000010'     ;
	tris    serial
	dsel                    ;De-select the 93C46.

;       nop                     ;NOTE:  Check the 93C46 data sheet for
				;minimum CS low time.  Depending upon
				;processor frequency, a nop(s) may be
				;between the assertion and de-assertion of
				;Chip Select.

	sel                     ;Re-select the 93C46.
notrdy  btfsc   serial,dout     ;If DO is a '0', 93C46 has yet to completed
				;the last operation (still busy).
	goto    no_error        ;Otherwise RDY status is present within the
				;alloted time, and return with good status.
	decfsz  cnt             ;No, not yet ready.  Decrement the LSB of our
				;16 bit timer and check for expiration.
	goto    notrdy          ;Still some time left.  Try again.
	decfsz  cnthi           ;Least significant byte expired - decrement
				;and check for expiration of the MSB.
	goto    notrdy          ;Still some time left.  Try again.
;for a 3 wire interface, convert RA1 line back to an ouput
	movlw   0               ;convert RA1 to an output
	tris    serial          ;       /
	retlw   error           ;RDY status was not present in the alloted
				;time, return with error status.
no_error
;for a 3 wire interface, convert RA1 line back to an ouput
	movlw   0               ;convert RA1 to an output
	tris    serial          ;       /
	retlw   no_err


;********************************************************************
;*                      SEE                                         *
;********************************************************************

				;See will control the entire operation of a
				;93C46 device.  Prior to calling the routine,
				;load a valid command/memory address into
				;location cmd, and for WRITE or WRAL
				;commands, load registers highb and lowb with
				;16 bits of write data.  Upon exit, the W
				;register will contain the completion status.
				;Only 93C46 instructions which require a
				;status check can return with an error as the
				;completion status.  The values that denote
				;the completion status are defined as
				;variables 'error' and 'no_err' in the
				;general assignments section.

see     movlw   cmd             ;Load W with the location of the cmd
				;register.
	movwf   fsr             ;Transfer that information into the File
				;Select Register.  The fsr now points to
				;location cmd.
	sel                     ;Select the 93C46.
	strtbt                  ;Send a start bit.
	call dout8              ;Transmit the 2 bit command and six bit
				;address.
	btfsc   cmd,6           ;Check for a WRITE or ERASE command.
	goto    see2            ;Yes, parse the command further.
	btfsc   cmd,7           ;Check for a READ command.
	goto    read_           ;Yes, process READ command.
	btfsc   cmd,5           ;Check for a EWEN or ERAL command.
	goto    see3            ;Yes, parse the command further.
	btfsc   cmd,4           ;Check for a WRAL command.
	goto    write_          ;Yes, process WRITE/WRAL command.

exit_   dsel                    ;No further processing required; 93C46
				;command completed.
	retlw   no_err          ;Return with good completion status.

see2    btfss   cmd,7           ;Check for a ERASE command.
	goto    write_          ;No, process WRITE command.
exit2_  call    rdychk          ;ERASE command requires a status check.
	dsel                    ;De-select the 93C46.
	addwf   pc              ;Compute completion status from results of
				;status check.
	retlw   no_err          ;Return with good completion status.
	retlw   error           ;Return with bad completion status.

see3    btfsc   cmd,4           ;Check for a EWEN command.
	goto    exit_           ;Yes, no further processing required, exit
				;now.
	goto    exit2_          ;No, ERAL command which requires a status
				;check.

read_   incf    fsr             ;Increment the File Select Register to point
				;to the register receiving the upper byte of
				;the incomming 93C46 data word.
	call    din8            ;Input the upper byte.
	incf    fsr             ;Increment the File Select Register to point
				;to the register receiving the lower byte.
	call    din8            ;Input 8 more bits.
	goto    exit_           ;No further processing required, exit now.

write_  incf    fsr             ;Increment the File Select Register to point
				;to the upper byte of the 16 bit 93C46 data
				;word to be transmitted.
	call    dout8           ;Output that byte.
	incf    fsr             ;Increment the File Select Register to point
				;to the lower byte.
	call    dout8           ;Output the lower byte of the 16 bit 93C46
				;data word.
	goto    exit2_          ;Exit with a status check.

;********************************************************************
;*                      Test Program                                *
;********************************************************************
	main                    ;We've include a sample program to exercise
				;the PIC to 93C46 interface using a simple
				;erase, write and varify routine.
	
	clrf    serial          ;Clear the port tied to the 93C46 device.
	movlw   b'11110100'     ;Intialize the data direction register for
	tris    serial          ;that port.
	
	movlw   ewen            ;Load W with the Erase/Write Enable command.
	movwf   cmd             ;Transfer W into cmd register.
	call    see             ;Enable the 93C46 device.

	movlw   eral            ;Load W with the Erase All command.
	movwf   cmd             ;Transfer W into cmd register.
	call    see             ;Erase the 93C46.
	xorlw   error           ;Check completion status.
	btfsc   status, zflag   ;Test for error condition.
	goto    errloop         ;Yes, bad completion status, error-out.

				;Write loop:
loopcnt equ     0x1F            ;Define an unused location for our test
				;program loop counter.
tstptrn equ     0xAA            ;Define the test pattern to be written.

	movlw   .64             ;Initialize that counter.
	movwf   loopcnt         ;
	movlw   write           ;Load W with the Write command.
	movwf   cmd             ;Transfer W into cmd register.
	movlw   tstptrn         ;Intialize the 93C46 data registers with
				;write data.
	movwf   highb           ;
	movwf   lowb            ;
test1   call    see             ;Write data word into 93C46 device.
	xorlw   error           ;Check completion status.
	btfsc   status,zflag    ;Test for error condition.
	goto    errloop         ;Yes, bad completion status, error-out.
	incf    cmd             ;No, increment the 6 bit memory address
				;field.
	decfsz  loopcnt         ;Have we written all 64 locations?
	goto    test1           ;No, write another location.

				;Read loop:

	movlw   .64             ;Initialize loop counter.
	movwf   loopcnt         ;
	movlw   read            ;Load W with the Read command.
	movwf   cmd             ;Transfer W into cmd register.
test2   call    see             ;Read addressed data word from 93C46 device.
	movlw   tstptrn         ;Load W with the pattern written.
	subwf   highb,0         ;Verify the data read against what was
				;written.
	btfss   status,zflag    ;Same?
	goto    errloop         ;No, error-out.
	movlw   tstptrn         ;Repeat with the lower byte read.
	subwf   lowb,0          ;
	btfss   status,zflag    ;Same?
	goto    errloop         ;No, error-out.
	incf    cmd             ;Yes, both byte correct, increment the 6 bit
				;memory address field.
	decfsz  loopcnt         ;Have we read all 64 locations?
	goto    test2           ;No, read another location.

allok   goto    allok           ;Home safe!

errloop goto    errloop         ;Bad news!

	END                     ;Thats all folks!

⌨️ 快捷键说明

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