jmp delay51
RET
;=========發(fā)送命令=========
;send command
;==========================
ic_sendcommand:
;start condition
set_clk_out
set_io_out
bc port6,icclk
bs port6,icio
call delay
bs port6,icclk
call delay
bc port6,icio
call delay
bc port6,icclk
call delay
mov dbuf_24,ic_command1
call ic_send_data
mov dbuf_24,ic_command2
call ic_send_data
mov dbuf_24,ic_command3
call ic_send_data
;stop condition
bc port6,icio
call delay
bs port6,icclk
call delay
bs port6,icio
call delay
ret
;process
ic_process:
bc port6,icclk
call delay
bc port6,icio
mov process_temp,@254
puls:
bs port6,icclk
call delay
bc port6,icclk
djz process_temp
jmp puls
ret
/*================讀主存儲(chǔ)器==================
入口:rmm_address 讀取的地址
rmm_len 讀取的長度
出口:ic_buffer1
;============================================*/
ic_readmainmemory:
bank 0
mov ic_command1,@0x30
mov ic_command2,rmm_address
mov ic_command3,@0
call ic_sendcommand
bc port6,icclk
call delay
mov len,@0 ;0x10為私有要保護(hù)
mov rmm_temp,@255
mov a,rmm_address
sub rmm_temp,a
inc rmm_temp ;rmm_temp=256-address
goto_readdata:
CJL len,rmm_temp,readdata
;COMPARE AND JUMP IF REG1
readdata:
CJL len,rmm_len,save_data
call ic_receive_data
jmp drop_data
save_data:
call ic_receive_data
mov a,dbuf_24
mov ic_buffer1,a
drop_data:
inc len
jmp goto_readdata
exit_readdata:
bs port6,icclk
call delay
bc port6,icclk
call delay
ret
/*================寫主存儲(chǔ)器==================
入口:wmm_address 寫主存的地址
wmm_value 寫主存的數(shù)據(jù)
出口:
;============================================*/
ic_writemainmemory:
set_io_out
set_clk_out
mov ic_command1,@0x38
mov ic_command2,wmm_address
mov ic_command3,wmm_data
call ic_sendcommand
bc port6,icclk
call delay
bc port6,icio
call delay
mov len,@0 ;0x10為私有要保護(hù)
goto_writedata:
CJL len,@254,writedata
jmp exit_writedata
writedata:
bs port6,icclk
call delay
bc port6,icclk
call delay
inc len
jmp goto_writedata
exit_writedata:
bs port6,icio
call delay
bs port6,icclk ;stop condition
call delay
bc port6,icclk
call delay
ret
/*================讀安全儲(chǔ)區(qū)=================
入口:
出口:rsm_data1、rsm_data2、rsm_data3、rsm_data4讀取的數(shù)據(jù)
;============================================*/
ic_readsecmemory:
set_io_out
set_clk_out
mov ic_command1,@0x31
;mov a,@0xff
mov ic_command2,@0xff
mov ic_command3,@0xff
call ic_sendcommand
bc port6,icclk
call delay
call ic_receive_data
mov rsm_data1,dbuf_24
call ic_receive_data
mov rsm_data2,dbuf_24
call ic_receive_data
mov rsm_data3,dbuf_24
call ic_receive_data
mov rsm_data4,dbuf_24
set_io_out
set_clk_out
bs port6,icio
call delay
bs port6,icclk ;stop condition
call delay
bc port6,icclk
call delay
ret
/*================比較密碼 =================
入口:
出口:
;============================================*/
ic_compareverifdata:
set_io_out
set_clk_out
call ic_readsecmemory
nop
nop
;mov a,rsm_data1
;and a,@0x07
;mov rsm_data1,a
mov rsm_data1,rsm_data1
jbc 0x03,2
jmp fail_exit
nop
CJE rsm_data1,@0x07,setbit1
CJE rsm_data1,@0x06,setbit2
CJE rsm_data1,@0x04,setbit3
jmp fail_exit
setbit1:
mov wsm_data,@0x06
nop
jmp endcomp
setbit2:
mov wsm_data,@0x04
nop
jmp endcomp
setbit3:
mov wsm_data,@0x00
nop
endcomp:
mov wsm_address,@0
call ic_writesecmemory
;mov len,@0
;CJL len,@3,writedata
;mov password_data,@0xff
mov ic_command1,@0x33
mov ic_command2,@1
mov ic_command3,@0xff
call ic_sendcommand
set_io_out
set_clk_out
bc port6,icclk
call delay
bc port6,icio
call delay
bs port6,icclk ;stop condition
call delay
bc port6,icclk
call delay
bs port6,icclk ;stop condition
call delay
bc port6,icclk
call delay
bs port6,icio
call delay
bs port6,icclk ;stop condition
call delay
bc port6,icclk
call delay
mov ic_command1,@0x33
mov ic_command2,@2
mov ic_command3,@0xff
call ic_sendcommand
bc port6,icclk
call delay
bc port6,icio
call delay
bs port6,icclk ;stop condition
call delay
bc port6,icclk
call delay
bs port6,icclk ;stop condition
call delay
bc port6,icclk
call delay
bs port6,icio
call delay
bs port6,icclk ;stop condition
call delay
bc port6,icclk
call delay
mov ic_command1,@0x33
mov ic_command2,@3
mov ic_command3,@0xff
call ic_sendcommand
bc port6,icclk
call delay
bc port6,icio
call delay
bs port6,icclk ;stop condition
call delay
bc port6,icclk
call delay
bs port6,icclk ;stop condition
call delay
bc port6,icclk
call delay
bs port6,icio
call delay
bs port6,icclk ;stop condition
call delay
bc port6,icclk
call delay
nop
fail_exit:
mov wsm_address,@0
mov wsm_data,@0xff
call ic_writesecmemory
call delay
call ic_readsecmemory
CJE rsm_data1,@0x07,success
mov ic_compare_password_flag,@0
jmp failed
success:
mov ic_compare_password_flag,@1
failed:
nop
nop
ret
/*================讀保護(hù)儲(chǔ)器=================
出口:rpm_data 讀取的數(shù)據(jù)
;============================================*/
ic_readprotectmemory:
set_io_out
set_clk_out
mov ic_command1,@0x34
mov a,@0
mov ic_command2,a
mov ic_command3,a
call ic_sendcommand
bc p6cr,icclk
call delay
call ic_receive_data
mov rpm_data1,dbuf_24
call ic_receive_data
mov rpm_data2,dbuf_24
call ic_receive_data
mov rpm_data3,dbuf_24
call ic_receive_data
mov rpm_data4,dbuf_24
set_io_out
set_clk_out
bs p6cr,icclk ;stop condition
call delay
bc p6cr,icclk
call delay
ret
/*================寫保護(hù)儲(chǔ)器=================
入口:wpm_address 寫的地址
出口:wpm_data 寫的數(shù)據(jù)
;============================================*/
ic_writeprotectmemory:
set_io_out
set_clk_out
mov ic_command1,@0x3c
mov ic_command2,wpm_address
mov ic_command3,wpm_data
call ic_sendcommand
bc p6cr,icclk
call delay
bc p6cr,icio
call delay
mov len,@0
goto_writeprotectdata:
CJL len,@254,writeprotectdata
jmp exit_writeprotectdata
writeprotectdata:
bs p6cr,icclk
call delay
bc p6cr,icclk
call delay
inc len
jmp goto_writeprotectdata
exit_writeprotectdata:
bs p6cr,icio
call delay
bs p6cr,icclk ;stop condition
call delay
bc p6cr,icclk
call delay
ret
/*================寫安全儲(chǔ)區(qū)=================
入口:wsm_address 寫的地址
出口:wsm_data 寫的數(shù)據(jù)
;============================================*/
ic_writesecmemory:
set_io_out
set_clk_out
mov ic_command1,@0x39
mov ic_command2,wsm_address
mov ic_command3,wsm_data
call ic_sendcommand
bc port6,icclk
call delay
bc port6,icio
call delay
mov len,@0
goto_writesecdata:
CJL len,@254,writesecdata
jmp exit_writesecdata
writesecdata:
bs port6,icclk
call delay
bc port6,icclk
call delay
inc len
jmp goto_writesecdata
exit_writesecdata:
bs port6,icio
call delay
bs port6,icclk ;stop condition
call delay
bc port6,icclk
call delay
ret





