大家看看这程序,我怎么写不进去
cs bit p1.0
si bit p1.1
sck bit p1.2
so bit p1.3
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 10h
byte_data equ 11h
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
clr sck
clr si
setb cs
lcall wren_cmd
lcall byte_write
lcall wren_cmd
lcall byte_read
lcall wren_cmd
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
clr cs
mov a,#wren_inst
lcall outbyt
clr sck
setb cs
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
clr cs
mov a,#wrdi_inst
lcall outbyt
clr sck
setb cs
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
clr cs
mov a,#wrsr_inst
lcall outbyt
mov a,#status_reg
lcall outbyt
clr sck
setb cs
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
clr cs
mov a,#rdsr_inst
lcall outbyt
lcall inbyt
clr sck
setb cs
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
clr cs
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
setb cs
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
clr cs
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
setb cs
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
clr cs
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
setb cs
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
clr cs
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
clr cs
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
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
clr sck
mov c,so
rlc a
djnz r0,inbyt1
ret
END
发表时间:2003年7月21日19:25:00