?? eeprom04.asm
字號:
;----------------------------------------------------------------
; Author : QinPinJian
; Native place: ShangLin county GuangXi Province China
; Create date : April/12/2K2
; Function : Atmel 24LC04 EEPROM Write read routine
;----------------------------------------------------------------
; ?//--- parameter ---//?
;/////
;///// MP0 --> indirect address of the data will be writed
;///// R_EE_Byte_count --> need write data byte quantity
;///// R_WR_EE_address --> the eeprom operating address
;///// R_EE_bank --------> operating eeprom bank
;/////
;--------------- write byte data to eeprom routine ------------------
F_Write_EE_Byte:
call setportoutput
call starteeprom
mov a, R_EE_bank ;0a0h ;0a0h
mov R_write_EE_data,a
call sand_data ;device address
call setportinput
call acknowledge ;ack
sz sda ;ack
jmp F_Write_EE_Byte
call setportoutput
mov a,R_WR_EE_address
mov R_write_EE_data,a
call sand_data ;word address
call setportinput
call acknowledge ;ack
sz sda ;ack
; ret
jmp F_Write_EE_Byte
call setportoutput
;;L_write_ee_loop:
nop
mov a, [00h] ;the data which be saved in
mov R_write_ee_data,a ;eeprom indirect by MP0
call sand_data ;write data
call setportinput
call acknowledge ;ack
sz sda ;ack
ret
call setportoutput
call stopeeprom
inc mp0
sdz R_EE_Byte_count
jmp L_write_ee_loop
ret
L_write_ee_loop:
call nop4t
call nop4t
call nop4t
call nop4t
; mov a,2
; mov R_Time_count_L,a ;wait 2ms
; mov a,0
; mov R_Time_count_H,a
; call F_wait_time
inc R_WR_EE_address
jmp F_Write_EE_Byte
;----------------------------------------------------------------
; ?//--- parameter ---//?
;/////
;///// MP0 --> indirect address of the data will be saved in
;///// R_EE_Byte_count --> need read data byte quantity
;///// R_WR_EE_address --> the eeprom operating address
;///// R_EE_bank --------> operating eeprom bank
;/////
;--------------- read byte data from eeprom routine ------------------
F_Read_EE_Byte:
call setportoutput
call starteeprom
mov a,R_EE_bank ;0a0h
mov R_write_EE_data,a
call sand_data ;device address
call setportinput
call acknowledge ;ack
sz sda ;ack
;ret
jmp F_Read_EE_Byte
call setportoutput
mov a,R_wR_EE_address ;00h
mov R_write_EE_data,a
call sand_data ;word address
call setportinput
call acknowledge ;ack
sz sda ;ack
; ret
jmp F_Read_EE_Byte
call setportoutput
call starteeprom
mov a,R_EE_bank ;0a1h
set acc.0
mov R_write_EE_data,a
call sand_data ;device address
call setportinput
call acknowledge ;ack
sz sda ;ack
; ret
jmp F_Read_EE_Byte
;L_read_ee_loop:
call recieve_data ;recieve data from eeprom
call setportoutput
call stopeeprom
inc mp0
sdz R_EE_Byte_count
jmp L_read_ee_loop
ret
L_read_ee_loop:
call nop4t
call nop4t
call nop4t
call nop4t
; mov a,2
; mov R_Time_count_L,a ;wait 2ms
; mov a,0
; mov R_Time_count_H,a
;
; call F_wait_time
inc R_WR_EE_address
jmp F_Read_EE_Byte
;/// last one not need ack !!
;--------------------start EE-prom---------------------------
starteeprom:
clr scl
set sda
call nop4t
set scl
call nop4t
clr sda
call nop4t
ret
;--------------------stop EE-prom----------------------------
stopeeprom:
clr sda
clr scl
call nop4t
set scl
call nop4t
set sda
call nop4t
ret
;------------------acknowledge from EEprom----------------
acknowledge:
call nop4t
set scl
call nop4t
call nop4t
;; clr scl
ret
;-----------------sand address or data-----------------------
sand_data:
mov a,8
mov R_WR_bit_count,a
mov a,R_write_EE_data
clr scl
call nop4t
WriteBit:
rLc acc ;left rotate
snz c
jmp ClrDI
set SDA ;Output "1"
jmp RisingEdge
ClrDI:
clr SDA ;Output "0"
RisingEdge:
call nop4t
set scl
call nop4t
call nop4t
clr scl
call nop4t
sdz R_WR_bit_count
jmp WriteBit
; clr SDA ;Output "0"
;/// start wait EEPROM ack ////
ret
;-----------------recieve data--------------------------
recieve_data:
clr scl
call nop4t
call nop4t
mov a,8
mov R_WR_bit_count,a
ReadBit:
; clr scl
; call nop4t
; call nop4t
set scl
call nop4t
call nop4t
set c
snz SDA ;test pb.1 pin
clr c
RLC acc
clr scl
call nop4t
call nop4t
sdz R_WR_bit_count
jmp ReadBit
mov [00h],a ;save data in memory
ret
;;------------------------------------------------------
;recieve_data: bits emb
; smb 15
; bitr scl
; call nop4t
; ld l #7h
;loop_rbsc0:
; ldb c sda
; ldb bsc0.@l c
; call nop4t
; bits scl
; call nop4t
; bitr scl
; call nop4t
; decs l
; jps loop_rbsc0
; ld ea bsc0
; ret
;
nop4t:
nop
nop
nop
nop
nop
ret
;------------------set port pb.1/p3.1 input---------------
setportinput:
set pbc.1
nop
nop
ret
;------------------set port pb.1/p3.1 output---------------
setportoutput:
clr pbc.1
; clr pbc.0
nop
nop
ret
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -