电路设计,软件开发,专业项目团队承接电子产品开发!


ISPRO下载型编程器
火爆销售中

RS232/TTL转换器
全IC串口窃电

RS232/TTL转换线
全IC串口窃电

ByteBlasterMV Cable
CPLD/FPGA并口下载线

ByteBlaster II Cable ISPRO下载型编程器
支持S51/AVR/PIC
超级51开发板套件
前卫实用超值

PC/MCU/CPLD
三合一学习套件

全新万年历方案
AVR单片机开发板
 

Min51单片机仿真机
迷你型

ARM7开发板
仅售260元!
 

RS-232/RS-485双向接口电平转换器  

51单片机升级STM32
火爆销售中
MPLAB-ICD2
火爆销售中
LED51开发板
玩具又名图文显示棒

面板模块/开发板
经济危机明智决择

       

GSM MODEM GSM猫

SMS短信模块 工业级/全自动
火爆销售中

大功率数传电台

高速数传电台

您当前位置:电子技术资料 -> 外围驱动 -> EEPROM ->

祝您阅读愉快!

ISPRO下载型编程器

RS232 TO TTL转换器
↑↑本文相关产品介绍↑↑

X5045汇编驱动


类别:技术文章
来源:未知
作者:未知
关键字:X5045
加入日期:2010-8-3

;*********************************************************************
; Module Name: X5045.asm
;中国电子网www.EC66.com
;*********************************************************************


;---------- 常量定义 --------------
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

;*******************************************************************************


您可能还会关注的相关技术资料:
暂无

中国电子网
www.EC66.com
QQ:34740080 EMAIL:iloveaoe@163.com
最佳浏览:1024*768
Copyright (C) 2001-2010 EC66.COM All Rights Reserved
Aoe/帝国 制作维护
粤ICP备18061901号