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

📄 x5045.asm

📁 C51源程序集合 包括以下目录源码 ├─AD-MSP430f149D ├─ADC8535 ├─bin ├─c51源程序 ├─c51源程序锦集 ├─ct2Timer ├─
💻 ASM
字号:
;*********************************************************************
;	Module Name:	X5045.asm
;	Author:			涛行九天
;	Version:		1.0
;	CreateDate:		2002-06-12
;	Description:
;	Remark:
;	Revision History:
;*********************************************************************


;---------- 常量定义 --------------
WREN_INST 	equ		06H 		; Write enable latch instruction (WREN)
WRDI_INST 	equ 	04H 		; Write disable latch instruction (WRDI)
WRSR_INST 	equ 	01H 		; Write status register instruction (WRSR)
RDSR_INST 	equ 	05H 		; Read status register instruction (RDSR)
WRITE_INST 	equ 	02H 		; Write memory instruction (WRITE)
READ_INST 	equ 	03H 		; Read memory instruction (READ)

MAX_POLL 	equ 	99H 		; Maximum number of polls

;---------- 管脚定义 --------------
SCK 	EQU		P1.1			;X25045
SI		EQU 	P1.2	    	
SO		EQU		P1.0		
CS		EQU		P1.3		

	
;*******************************************************************************
;		The following is about X25045
;*******************************************************************************
;* All X25045 commands are provided.
;* 1. Set Write Enable Latch
;* 2. Reset Write Enable Latch
;* 3. Write Status Register
;* 4. Read Status Register
;* 5. Single Byte Write
;* 6. Single Byte Read
;* 7. Page Write
;* 8. Sequential Read
;* 9. Reset Watchdog Timer

;INIT_STATE equ 09H 		; Initialization value for control ports 
;SLIC equ 030H 				; Address location of SLIC 

;-------------------------------------------------------------------------------------------------
;Invoke example
;-------------------------------------------------------------------------------------------------
	;LCALL	RDSR_CMD
	;LCALL	WREN_CMD
	;MOV	R5,#30H
	;LCALL	WRSR_CMD
	;LCALL	RDSR_CMD	;Test read & write status ---ok!
	
	;MOV	R3,#00H
	;MOV	R4,#10H
	;LCALL	READBYTE	;Test read
	
	;LCALL	WREN_CMD
	;MOV	R3,#00H
	;MOV	R4,#10H
	;MOV	R5,#01H;
	;LCALL	WRITEBYTE	;Test write eeprom( a byte ) ---ok!
	
;-------------------------------------------------------------------------------------------------

;-------------------------------------------------------------------------------------------------
;   WREN_CMD 	Set write enable latch
;	Function:	Sends the command to enable writes to the EEPROM memory array or status register
;   Calls:		outbyte
;	InPara:		None
;	OutPara:	None
;	Register Usage: A 
;-------------------------------------------------------------------------------------------------
wren_cmd: 
	clr	sck 				; Bring SCK low
	clr	cs 					; Bring /CS low
	mov 	A, #WREN_INST 
	lcall 	outbyte 		; Send WREN instruction
	clr 	sck 			; Bring SCK low	
	setb 	cs 				; Bring /CS high
	ret
	
;-------------------------------------------------------------------------------------------------
;   WRDI_CMD 	Reset write enable latch
;	Function:	Sends the command to disable writes to the EEPROM memory array or status register
;   Calls:		outbyte
;	InPara:		None
;	OutPara:	None
;	Register Usage: A 
;-------------------------------------------------------------------------------------------------
wrdi_cmd: 
	clr	sck 				; Bring SCK low
	clr	cs 					; Bring /CS low
	mov 	A, #WRDI_INST 
	lcall 	outbyte 		; Send WRDI instruction
	clr 	sck 			; Bring SCK low	
	setb 	cs 				; Bring /CS high
	ret

;-------------------------------------------------------------------------------------------------
;   WRSR_CMD 	Write Status Register
;	Function:	Sends the command to write the WD0, WD1, BP0 and BP0 EEPROM bits in the status register
;   Calls:		outbyte, wip_poll
;	InPara:		R5 = byte to be wrote
;	OutPara:	None
;	Register Usage: A 
;-------------------------------------------------------------------------------------------------
wrsr_cmd: 
	clr	sck				; Bring SCK low
	clr	cs 				; Bring /CS low
	mov	A, #WRSR_INST 
	lcall	outbyte 	; Send WRSR instruction
	mov	A, R5 
	lcall	outbyte 	; Send status register 
	clr	sck 			; Bring SCK low
	setb	cs 			; Bring /CS high
	lcall	wip_poll 	; Poll for completion of write cycle
	ret

;-------------------------------------------------------------------------------------------------
;  	RDSR_CMD 	Read Status Register
;	Function:	Sends the command to read status register
;   Calls:		outbyte, inbyte
;	InPara:		None
;	OutPara:	A = status register
;	Register Usage: A 
;-------------------------------------------------------------------------------------------------
rdsr_cmd:
	clr	sck 				; Bring SCK low
	clr	cs 					; Bring /CS low
	mov 	A, #RDSR_INST 
	lcall	outbyte 		; Send RDSR instruction
	lcall	inbyte 			; Read status register 
	clr	sck 				; Bring SCK low	
	setb	cs 				; Bring /CS high
	ret

;-------------------------------------------------------------------------------------------------
;   WRITEBYTE 	Single Byte Write
;	Function:	Sends the command to write a single byte to the EEPROM memory array
;   Calls:		outbyte, wip_poll
;	InPara:		R3 = high address, R4 = low address, R5 = byte to be wrote
;	OutPara:	None
;	Register Usage: A,B 
;-------------------------------------------------------------------------------------------------
WRITEBYTE:
	clr	sck 				; Bring SCK low
	clr	cs 					; Bring /CS low 
	mov	A, #WRITE_INST
	mov	B, R3
	mov	C, B.0
	mov	ACC.3, C 
	lcall	outbyte 		; Send WRITE instruction including MSB of address
	mov	A, R4 
	lcall	outbyte 		; Send 8 LSBs of address 
	mov	A, r5
	lcall	outbyte 		; Send data byte
	clr	sck 				; Bring SCK low
	setb	cs 				; Bring /CS high
	lcall	wip_poll 		; Poll for completion of write cycle
	ret

;-------------------------------------------------------------------------------------------------
;   READBYTE 	Single Byte Read
;	Function:	Sends the command to read a single byte from the EEPROM memory array
;   Calls:		outbyte, inbyte
;	InPara:		R3 = high address, R4 = low address
;	OutPara:	A = read byte
;	Register Usage: A,B 
;-------------------------------------------------------------------------------------------------
READBYTE:
	clr	sck 				; Bring SCK low
	clr	cs 					; Bring /CS low
	mov	A, #READ_INST
	mov	B, R3
	mov	C, B.0
	mov	ACC.3, C 
	lcall	outbyte 		; Send READ instruction including MSB of address
	mov 	A, R4
	lcall	outbyte 		; Send 8 LSBs of address 
	lcall	inbyte 			; Read data byte
	clr	sck 				; Bring SCK low
	setb	cs 				; Bing /CS high
	ret

;-------------------------------------------------------------------------------------------------
;   PAGEWRITE 	Page Write (max number which can write one time is 4)
;	Function:	Sends the command to write 4 consecutive bytes to the EEPROM memory array using page mode
;   Calls:		outbyte, wip_poll
;	InPara:		R3 = high address, R4 = low address, R0 = start address of data
;	OutPara:	None
;	Register Usage: A,B 
;-------------------------------------------------------------------------------------------------
page_write: 
	clr	sck 				; Bring SCK low
	clr	cs 					; Bring /CS low 
	mov	A, #WRITE_INST
	mov	B, r3
	mov	C, B.0
	mov	ACC.3, C 
	lcall	outbyte 		; Send WRITE instruction including MSB of address
	mov 	A, r4 
	lcall 	outbyte 		; Send 8 LSBs of address 
	mov 	A, @R0
	inc	r0
	lcall	outbyte 		; Send 1st data byte
	mov	A, @R0
	inc	r0
	lcall 	outbyte 		; Send 2nd data byte
	mov	A,@r0
	inc	r0
	lcall 	outbyte 		; Send 3rd data byte
	mov	A,@r0
	inc	r0
	lcall 	outbyte 		; Send 4rd data byte
	clr 	sck 			; Bring SCK low
	setb	cs 				; Bring /CS high
	lcall	wip_poll 		; Poll for completion of write cycle
	ret

;-------------------------------------------------------------------------------------------------
;   BYTES_READ 	Sequential Read
;	Function:	Sends the command to read 8 consecutive bytes from the EEPROM memory array using sequential mode
;   Calls:		outbyte, inbyte
;	InPara:		R5 = number read, R3 = high address, R4 = low address,
;	OutPara:	R0 = address to store data
;	Register Usage: A,B 
;-------------------------------------------------------------------------------------------------
bytes_read: 
	clr	sck 				; Bring SCK low
	clr	cs 					; Bring /CS low
	mov	A, #READ_INST
	mov	B, R3
	mov	C, B.0
	mov	ACC.3, C 
	lcall	outbyte 		; Send READ instruction with MSB of address
	mov	A, R4
	lcall 	outbyte 		; Send low order address byte 
readag:	lcall	inbyte 		; Read 1st data byte
	mov	@r0,a
	inc	r0
	djnz	r5,readag
	clr 	sck 			; Bring SCK low
	setb 	cs 				; Bring /CS high
	ret

;-------------------------------------------------------------------------------------------------
;  	RST_WDOG 	Reset Watchdog Timer
;	Function:	Resets the watchdog timer without sending a command 
;   Calls:		None
;	InPara:		None
;	OutPara:	None
;	Register Usage: None 
;-------------------------------------------------------------------------------------------------
rst_wdog:
	clr	cs 						; Bring /CS low to reset watchdog timer
	setb	cs 					; Bring /CS high
	ret

;-------------------------------------------------------------------------------------------------
;   WIP_POLL 	Write-In-Progress Polling
;	Function:	Polls for completion of a nonvolatile write cycle by examining the WIP bit of the status register
;   Calls:		None
;	InPara:		None
;	OutPara:	None
;	Register Usage: R2,A 
;-------------------------------------------------------------------------------------------------
WIP_POLL:
	mov	R2, #MAX_POLL 			; Set maximum number of polls
wip_poll1:
	lcall	rdsr_cmd 			; Read status register
	jnb	ACC.0,wip_poll2 		; If WIP bit '0' write cycle completed 
	djnz	R2, wip_poll1 		; If WIP bit '1' continue polling
wip_poll2: 
	ret

;-------------------------------------------------------------------------------------------------
;   OUTBYTE 	Sends byte to EEPROM
;	Function:	Shifts out a byte, starting with the MSB, to the EEPROM 
;   Calls:		None
;	InPara:		A = byte to be sent
;	OutPara:	None
;	Register Usage: R2,A 
;-------------------------------------------------------------------------------------------------
OUTBYTE:mov	r2, #08 			; Set bit counter to eight
outbyt1:clr	sck 				; Bring SCK low
	rlc	a 						; Shift byte left through carry
	mov	si,C 					; Send data bit in carry
	setb	sck 				; Bring SCK high
	djnz	r2, outbyt1			; Finish if last data bit
	clr	si 						; Place SI in known condition
	ret
	
;-------------------------------------------------------------------------------------------------
;   INBYTE 		Recieves byte from EEPROM
;	Function:	Recieves a byte, MSB first, from the EEPROM
;   Calls:		None
;	InPara:		None
;	OutPara:	A = recieved byte
;	Register Usage: R2,A 
;-------------------------------------------------------------------------------------------------
INBYTE:	mov	R2, #08 			; Set bit counter to eight
inbyt1:	setb	sck 			; Bring SCK high
	clr	sck 					; Bring SCK low
	mov	C, so					; Receive data bit and store in carry
	rlc	A 						; Shift byte left through carry 
	djnz	R2, inbyt1 			; Finish if last data bit
	ret
	
;*******************************************************************************

⌨️ 快捷键说明

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