EMC指令版本SLE4428卡读写程序

发布者:superstar11最新更新时间:2014-12-18 来源: laogu关键字:EMC指令  SLE4428  卡读写程序 手机看文章 扫描二维码
随时随地手机看文章
SLE4428卡读写程序。这个EMC指令版本是根据C51程序改写的。已经通过了调试。
;============================
;发送数据子程序
;入口: DBUF_24 =要发送的数据(8_BIT)
;============================
ic_send_data:
MOV A,@8 ;循环次数=8
MOV COUNT_24,A
TXLP:
RRC DBUF_24 ;左移(带C)
CALL ic_BITOUT ;输出1_BIT
DJZ COUNT_24 ;循环结束?
JMP TXLP
RET
;=================
;位输入子程序
;说明: 当SCL=1时,从SDA上读电平
;出口: C=从SDA上读入的位值
;=================
ic_BITIN:
set_io_in ;设置i/o为输入口
set_clk_out
bc 0x05,0
bs port6,icclk ;clk=1
call delay ;延时
BC R3,0
JBC port6,icio
BS R3,0 ;C=io
call delay ;延时0.6US
BC port6,icclk ;clk=0
call delay ;延时0.6US
RET
;=================
;位输出子程序
;说明: 每当SCL=0时,改写SDA上的电平
;入口: C=要写到SDA上的位值
;=================
ic_BITOUT:
;SDA_OUT ;设置SDA为输出口
set_io_out
set_clk_out

JBS R3,0
JMP BIT0
BS port6,icio ;io=C=1
JMP io1
BIT0:
BC port6,icio ;io=C=0
io1:
call delay ;延时0.6US
bs port6,icclk ;clk=1
BIT2:
call delay
call delay
bc port6,icclk ;clk=0
RET
;============================
;接收数据子程序
;入口: TT_24.REND_24 =读完毕标志
;出口: DBUF_24 =接受到的数据(8_BIT)
;============================
ic_receive_data:
MOV A,@8 ;循环次数=8
MOV COUNT_24,A
CLR DBUF_24
RXLP:
CALL ic_BITIN ;输入1_BIT
RRC DBUF_24 ;左移(带C)
DJZ COUNT_24 ;循环结束?
JMP RXLP
RET


;===========================
;复位操作
;============================
ic_reset:
set_clk_out
set_io_out
set_rst_out

bc port6,icclk ;clk=0
call delay10
bc port6,icrst ;rst=0
call delay10
bs port6,icio ;i/o=1
call delay10
bs port6,icrst ;rst=1
call delay10
bs port6,icclk ;clk=1
call delay10
bc port6,icclk ;clk=0
call delay10
bc port6,icrst ;rst=0
call delay10

call ic_receive_data
mov ic_buffer1,dbuf_24
call ic_receive_data
;mov ic_buffer2,dbuf_24
call ic_receive_data
;mov ic_buffer3,dbuf_24
call ic_receive_data
;mov ic_buffer4,dbuf_24
ret

;============================延时子程序====================================
;功能:短延时 入口:NONE 出口:NONE
;影响资源:A,TEMP ,STATUS
;=====================================================
DELAY:
MOV A,@0X05
MOV TEMP,A
DJZ TEMP
JMP $-1
RET
;============================延时子程序10MS================================
;功能:延时 入口:NONE 出口:NONE
;影响资源:A,TEMP ,STATUS
;==================================================
DELAY10:
MOV A,@0x10
MOV TEMP,A
MOV A,@0xff
MOV TEMP1,A
DJZ TEMP1
JMP $-1
DJZ TEMP
JMP $-5
RET

DELAY100:
mov a, @0x36
mov delay_time1, a
delay51:
mov a, @0x25
mov delay_time2,a
delay52:
mov a, @0x42
mov flag, a
delay53:
djz flag
jmp delay53
djz delay_time2
jmp delay52
djz delay_time1
jmp delay51
RET

;=========发送命令=========
;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

/*================读主存储器==================
入口: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为私有要保护
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 jmp exit_readdata
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

/*================写主存储器==================
入口:wmm_address 写主存的地址
wmm_value 写主存的数据
出口:
;============================================*/
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为私有要保护
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
/*================读安全储区=================
入口:
出口:rsm_data1、rsm_data2、rsm_data3、rsm_data4读取的数据
;============================================*/
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
/*================读保护储器=================
出口:rpm_data 读取的数据
;============================================*/
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

/*================写保护储器=================
入口:wpm_address 写的地址
出口:wpm_data 写的数据
;============================================*/
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


/*================写安全储区=================
入口:wsm_address 写的地址
出口:wsm_data 写的数据
;============================================*/
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
关键字:EMC指令  SLE4428  卡读写程序 引用地址:EMC指令版本SLE4428卡读写程序

上一篇:EM78系列单片机的编程技巧
下一篇:单片机笔记——数码管显示

推荐阅读最新更新时间:2024-03-16 13:49

EMC单片机指令应用的误区与技巧
EMC的基本指令语法,其实也就57/58条,如何变化折腾,就看各位的修行造化了。 但是,新手上路总容易进入一些误区,而老鸟们的一些技巧也值得借鉴。 废话少说,言归正传,且看匠人娓娓道来…… 1.减法指令的误区 之一:关于ACC EMC的减法指令有三条,如下: SUB A,R (R-A→A) SUB R,A (R-A→R) SUB A,K (K-A→A) 需要注意的是,不论A的位置在前面还是后面,A都是减数,不是被减数. 也就是說如果我們想計算A-2的值,如果寫成: SUB A,@2 其實是執行2-A 解決方法如下: ADD A,@256-2 或 AD
[单片机]
小广播
添点儿料...
无论热点新闻、行业分析、技术干货……
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

换一换 更多 相关热搜器件
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved