导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→;*The purpose of this code is 

* 58598: 关于25045的问题!急!

   baolqkun 
baolqkun发表的帖子 

 
;*The purpose of this code is to provide routines to interface the xicor x 25043 with the 8031
;*micorcontroller.The interface uses the 8031's general purpose parallel port 1 adn connects
;*p1.0 to the chip select line(/cs),p1.1 to the serial input data line(si),p1.2 to the
;*serial clock line (sck) and p1.3 to the serial output data line(so).
;*
;*All x25045 commands are provided. these are :-
;
;1. set write enable latch
;2. reset write enable latch
;3. write status register
;4. read status register
;5. signle byte read
;6. signle byte read
;7. page write
;8. sequential read
;9. reset watchdog timer
;
;*this code writes 00h to the status register; reads the status register; writes 11h to 
;*address 55h in byte mode;performs a single byte read from address 55h,writes 22h
;*33h,44h,to addresses 1f0h, 1f1h, 1f2h in page mode; performs a sequential read
;*from addresses 1f0h, 1f2h; and resets watchdog timer. this code can also be used with 
;*the x25045 which is identical to the x25045,except for its reset output polarity
;************************************************
;*constants

cs  bit p2.2
si  bit p2.0 
sck  bit p2.1
so  bit p1.7
wren_inst equ 06h
wrdi_inst equ 04h
wrsr_inst equ 01h
rdsr_inst equ 05h
write_inst equ 02h
read_inst equ 03h
byte_addr equ  99h
byte_data equ 5ah
page_addr equ 1f0h
page_data1 equ 22h
page_data2 equ 33h
page_data3 equ 44h
status_reg equ  00h
max_poll equ 99h
init_state equ 08h
inis_state equ 00h
slic  equ 030h

;************************************************
;*interal ram
stack_top equ 060h

;************************************************
;*code

 org 0000h
 ljmp main

 org 0100h
main: 
 mov sp,#stack_top
 clr ea
 setb so
 setb cs
 clr sck
 clr si
 lcall wren_cmd
 lcall wrsr_cmd
 lcall wren_cmd
 lcall byte_write
 lcall byte_read
 lcall wren_cmd
 lcall page_write
 lcall sequ_read
 lcall rst_wdog
 jmp main

;*****************************
;*name: wren_cmd
;*descritpion: set write enable latch
;*function:this routine sends the command to enable writes to the eeprom memory array or
;*status register
;*calls: outbyt
;*input: none
;*output:none
;*register usage: a
;****************************
wren_cmd:
 clr sck
 nop
 clr cs
 nop
 mov a,#wren_inst
 lcall outbyt
 clr sck
 nop
 setb cs
 nop
 ret

;****************************
;*name: wrdi_cmd
;*description:reset write enable latch
;*function:this routine sends the commond to disable writes to the eeprom memory array or
;*status register
;*calls: outbyt
;*input: none
;*output: none
;*register usage: a
;****************************
wrdi_cmd:
 clr sck
 nop
 clr cs
 nop
 mov a,#wrdi_inst
 lcall outbyt
 clr sck
 nop
 setb cs
 nop
 ret 

;****************************
;*name: wrsr_cmd
;*description: write status register
;*function:this routine sends the command to write the wd0,wd1,bpo and bp0 eeprom
;*bits in the status register
;*call: outbyt,wip_poll
;*input: none
;*output: none
;*register usage: a
;***************************
wrsr_cmd:
 clr sck
 nop
 clr cs
 nop
 mov a,#wrsr_inst
 lcall outbyt
 mov a,#status_reg
 lcall outbyt
 clr sck
 nop
 setb cs
 nop
 lcall wip_poll
 ret

;***************************
;*name: rdsr_cmd
;*description: read status register
;*function: this routine sends the command to read the status register
;*call: outbyt, inbyt
;*input: none
;*output: a=status register
;*register usage: a
;***************************
rdsr_cmd:
 clr sck
 nop
 clr cs
 nop
 mov a,#rdsr_inst
 lcall outbyt
 lcall inbyt
 clr sck
 nop
 setb cs
 nop
 ret

;***************************
;*name: byte_write
;*description: signle byte write
;*funtion:this routine sends the command to write a signle byte to the eeprom memory array
;*calls: outbyt, wip_poll
;*input: none
;*output: none
;*register usage: a,b
;**************************
byte_write:
 mov dptr,#byte_addr
 clr sck
 nop
 clr cs
 nop
 mov a,#write_inst
 mov b,dph
 mov c,b.0
 mov acc.3,c
 lcall outbyt
 mov a,dpl
 lcall outbyt
 mov a,#byte_data
 lcall outbyt
 clr sck
 nop
 setb cs
 nop
 lcall wip_poll
 ret

;******************************
;*name: byte_read
;*description: signle byte read
;*function: this routine sends the commond to read a signle byte from the eeprom momery array
;*calls: outbyt, inbyt
;*input: none
;*output: a=read byte
;*register usage: a,b
;*****************************
byte_read:
 mov dptr,#byte_addr
 clr sck
 nop
 clr cs
 nop
 mov a,#read_inst
 mov b,dph
 mov c,b.0
 mov acc.3,c
 lcall outbyt
 mov a,dpl
 lcall outbyt
 lcall inbyt
 clr sck
 nop
 setb cs
 nop
 ret

;*****************************
;*name: page_write
;*description: page write
;*function: this routine sends the commond to write three consecutive bytes to the eeprom
;*memory array using page mode
;*calls: outbyt,wip_poll
;*input:none
;*output:none
;*register usage: a, b
;****************************
page_write:
 mov dptr,#page_addr
 clr sck
 nop
 clr cs
 nop
 mov a,#write_inst
 mov b,dph
 mov c,b.0
 mov acc.3,c
 lcall outbyt
 mov a,dpl
 lcall outbyt
 mov a,#page_data1
 lcall outbyt
 mov a,#page_data2
 lcall outbyt
 mov a,#page_data3
 lcall outbyt
 clr sck
 nop
 setb cs
 nop
 lcall wip_poll
 ret

;*******************************
;*name: sequ_read
;*description: sequential read
;*function: this routine sends the command to read three consecutive bytes from the 
;*memory array using sequential mode
;*calls: outbyt, inbyt
;*input: none
;*output:a=last byte read
;*register usage: a,b
;******************************
sequ_read:
 mov dptr,#page_addr
 clr sck
 nop
 clr cs
 nop
 mov a,#read_inst
 mov b,dph
 mov c,b.0
 mov acc.3,c
 lcall outbyt
 mov a,dpl
 lcall outbyt
 lcall inbyt
 lcall inbyt
 lcall inbyt
 clr sck
 nop 
 setb cs
 nop
 ret

;******************************
;*name: rst_wdog
;*description: reset watchdog timer
;*function : this routine resets the watchdog timer without sending a command
;*call: none
;*input: none
;*output: none
;*register usage: none
;*****************************
rst_wdog:
 clr cs
 nop
 setb cs
 ret

;*****************************
;*name: wip_poll
;*description: write-in-progress polling
;*function: this routine polls for completion of a nonvolatile write cycle by examine
;*wip bit of the status register
;*calls: rdsr_cmd
;*input: none
;*output: none
;*register usage:r1,a
;*****************************
wip_poll: 
 mov r1,#max_poll
wip_poll1:
 lcall rdsr_cmd
 jnb acc.0,wip_poll2
 djnz r1,wip_poll1
wip_poll2:
 ret

;*****************************
;*name: outbyt
;*description: sends byte to eeprom
;*function: this routine shifts out a byte,starting with the msb, to the eeprom
;*calls: none
;*input: a=byte to be sent
;*output: none
;*register usage: r0,a
;*****************************
outbyt:
 mov r0,#08
outbyt1:
 clr sck
 rlc a
 mov si,c
 setb sck
 djnz r0,outbyt1
 clr si
 ret

;****************************
;*name: inbyt
;*description: receives byte from eeprom
;*function: this routine receives a byte ,msb first from the eeprom
;*calls: none
;*input: none
;*output: a=revceive byte
;*register usage: r0,a
;***************************
inbyt: 
 mov r0,#08
inbyt1: 
 setb sck
 nop
 clr sck
 mov c,so
 rlc a
 djnz r0,inbyt1
 ret
 
 END

发表时间:2004年7月20日21:12:47

  
回复该帖

本主题共有 2 帖,分页:>>>>>该主题的所有内容[2]条

 *树形目录 只列出部分跟帖的标题以及简单的摘要信息 该主题的部分跟帖如下:

[上一篇帖子]:介绍一款CF卡MP3播放器时下DIYMP3是热门话题,硬盘MP3与CF卡MP3相比各有优点,前者容量
[下一篇帖子]:义隆产的,如何购买?Email:mmhwww@163.com