⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdj_v4.0.asm

📁 本软件对IC卡的4442进行了分析,是一个通用的读写软件,并且通过编译,可以直接使用
💻 ASM
📖 第 1 页 / 共 3 页
字号:
                        goto        read_00
read_00
	                  call        start_ic
	                  call        com_ic
	                  call        stop_ic
    	                  call        read_data
                        movf        temp1,0
                        movwf       indf
                        incf        fsr
                        incf        ic_addr
                        decfsz      r2
                        goto        $-6
                        retlw       0  
;------------------------------------------------
clr_ic
                        call        ic_reset
				call        chk_ic_code
				btfsc       ic_reg,4
				goto        sio_ic_bad
				btfsc       ic_reg,5
				goto        sio_ic_errmm 
                        
                        movlw       0c0
                        bsf         status,5
                        movwf       trisd
                        bcf         status,5  
				movlw       h'20'        
				movwf       ic_addr
				movlw       h'ff'
				movwf       ic_data
				movlw       h'38'
				movwf       ic_com
				movlw       h'55'
				movwf       r2
                        call        start_ic       
                        call        com_ic
                        call        stop_ic
                        incf        ic_addr
                        movlw       h'7f'       ;h'ff'   
	                  movwf       ic_bit
		            call        delay_bits
                        decfsz      r2
                        goto        $-8
				goto        ic_clr_ok
;------------------------------------------------
write_ic_ty
                        call        ic_reset
				call        chk_ic_code
				btfsc       ic_reg,4
				goto        sio_ic_bad
				btfsc       ic_reg,5
				goto        sio_ic_errmm 
				
				movlw       0c0
				bsf         status,5
				movwf       trisd
				bcf         status,5 
				movf        txdat3,0	                  
				movwf       length
				decfsz      length
				nop
				movf        length,0
				movwf       r2            ;r2=25h    	
				movlw       h'38'               
				movwf       ic_com        ;ic_com=32h
				movf        txdat4,0
				movwf       ic_addr       ;ic_data=34h
				movlw       txdat5
				movwf       fsr
ic_wr_com1
				movf        indf,0
				movwf       ic_data
				call        start_ic
				call        com_ic
				call        stop_ic 
				incf        fsr
				incf        ic_addr
				movlw       h'ff'   
				movwf       ic_bit
				call        delay_bits
				decfsz      r2
				goto        ic_wr_com1
				call        del70ms 
				movf        length,0
				movwf       r2                        
				movf        txdat4,0
				movwf       ic_addr 
				movlw       txdat5
				movwf       fsr                            
				movlw       h'30'                
				movwf       ic_com
				movwf       ic_data
				call        read_00
				movf        txdat3,0
				addlw       5
				movwf       length
				movlw       0e0
				bsf         status,5
				movwf       trisd
				bcf         status,5
				goto        write_ic_ok 
;------------------------------------------------
write_ic 
				call        ic_reset
				call        chk_ic_code
				btfsc       ic_reg,4
				goto        sio_ic_bad
				btfsc       ic_reg,5
				goto        sio_ic_errmm 
                        
				movlw       0c0
				bsf         status,5
				movwf       trisd
				bcf         status,5
				movf        length,0      ;length=22h
				movwf       r2            ;r2=25h    	
				movlw       h'38'               
				movwf       ic_com        ;ic_com=32h
				movlw       h'20'         ;ic_addr=33h
				movwf       ic_addr       ;ic_data=34h
				movlw       txdat1
				movwf       fsr
ic_wr_com2
				movf        indf,0
				movwf       ic_data
				call        start_ic
				call        com_ic
				call        stop_ic 
				incf        fsr
				incf        ic_addr
				movlw       h'ff'   
				movwf       ic_bit
				call        delay_bits
				decfsz      r2
				goto        ic_wr_com2
				call        del70ms 
				movf        length,0
				movwf       r2
				call        read_ic1
				call        ic_eraser 
				movlw       0e0
				bsf         status,5
				movwf       trisd
				bcf         status,5
				goto        write_ic_ok 
;------------------------------------------------
ic_eraser                                     ;擦除电卡的返写区
                        call        del70ms 
				call        reset_ic
				movlw       h'50'        
				movwf       ic_addr
				movlw       h'ff'
				movwf       ic_data
				movlw       h'38'
				movwf       ic_com
				movlw       h'30'
				movwf       r2
                        call        start_ic       
                        call        com_ic
                        call        stop_ic
                        incf        ic_addr
                        movlw       h'7f'   ;h'ff'   
	                  movwf       ic_bit
		            call        delay_bits
                        decfsz      r2
                        goto        $-8
				return
;------------------------------------------------
ic_reset                           
				call        del70ms         ;对IC卡进行两次复位操作,以确保复位
				call        del70ms
				call        reset_ic
				call        del70ms
				call        reset_ic
				retlw       0
reset_ic                                        
				movlw       0e0      ;0         ;复位和复位应答
				bsf         status,5
				movwf       trisd
				bcf         status,5
				bcf         portd,icscl
				bsf         portd,icrst
				call        delus
				bsf         portd,icscl
				call        delus
				call        delus
				bcf         portd,icscl
				call        delus
				bcf         portd,icrst
				movlw       20h
				movwf       ic_bit
make_32puls
				bsf         portd,icscl
				call        delus
				call        delus
				bcf         portd,icscl
				call        delus
				decfsz      ic_bit
				goto        make_32puls
				retlw       0
;------------------------------------------------
read_data                  
				movlw       8             ;从IC卡中读取一个字节
				movwf       ic_bit
				movlw       0e0h    ;20h
				bsf         status,5
				movwf       trisd
				bcf         status,5
read_data1     
				bcf         portd,icscl
				call        delus
				bsf         portd,icscl
				bcf         status,0
				btfsc       portd,icsda
				bsf         status,0
				rrf         temp1
				decfsz      ic_bit
				goto        read_data1
				movlw       0e0     ;0
				bsf         status,5
				movwf       trisd
				bcf         status,5
				retlw       0    
;------------------------------------------------
chk_ic_code                                    ;校验密码
				call        rd_ic_code		
				movf        ic_count0,0
				btfsc       status,2
				bsf         ic_reg,4           ;ic_reg,4=1 ,IC卡坏
				btfsc       ic_reg,4
				retlw       0                              
				btfsc       ic_count0,0
				goto        ic_one
				btfsc       ic_count0,1
				goto        ic_two
				movlw       3
				goto        ic_three
ic_one                  movlw       6
		            goto        ic_three
ic_two	            movlw       5
ic_three                movwf       ic_data
				call        wr_ic_code
				movlw       h'ff'   ;7ch                  
				movwf       ic_bit
				call        delay_bits
				movlw       1
				movwf       ic_addr 
				movf        ic_code1,0
				movwf       ic_data		
				call        verify
				movlw       2
				movwf       ic_addr 
				movf        ic_code2,0
				movwf       ic_data
				call        verify
				movlw       3
				movwf       ic_addr 
				movf        ic_code3,0
				movwf       ic_data
				call        verify
				movlw       0ffh
				movwf       ic_data
				call        wr_ic_code
				movlw       7ch                   ;h'ff'  
				movwf       ic_bit
				call        delay_bits                
				call        rd_ic_code
				movf        ic_count0,0
				andlw       h'07'
				xorlw       h'07'
				btfss       status,2
				bsf         ic_reg,5               ;ic_reg,5=1 ,密码错
	                  btfsc       status,2
	                  bcf         ic_reg,5
	                  retlw       0  
verify                                            ;校验密码
				movlw       33h
				movwf       ic_com		
				call        start_ic
				call        com_ic
				call        stop_ic
				movlw       8
				movwf       ic_bit
				call        delay_bits
				retlw       0
;------------------------------------------------
rd_ic_code                                         ;读IC卡密码 
				movlw       4
				movwf       r1
				movlw       ic_count0
				movwf       fsr                           
				movlw       31h
				movwf       ic_com
				call        start_ic
				call        com_ic
				call        stop_ic
rd_ic_code1
				call        read_data
				movf        temp1,0
				movwf       indf
				incf        fsr
				decfsz      r1	
				goto        rd_ic_code1        			
				bcf         portd,icscl
				retlw       0
wr_ic_code                                         ;写IC卡密码
				movlw       39h
				movwf       ic_com		
				clrf        ic_addr
				call        start_ic
				call        com_ic
				call        stop_ic
				retlw       0	
;------------------------------------------------
start_ic                                           ;起始条件
                        bsf         status,5
                        bcf         trisd,5
                        bcf         status,5
				bcf         portd,icscl
				nop
				bsf         portd,icsda
				call        delus
				bsf         portd,icscl
				call        delus
				bcf         portd,icsda
				call        delus
				retlw       0	
stop_ic                                            ;停止条件
				bcf         portd,icscl
				bcf         portd,icsda
				bsf         portd,icscl
				call        delus
				bsf         portd,icsda
				call        delus
				retlw       0	
;------------------------------------------------
com_ic   
				movf        fsr,0
				movwf       temp_fsr
				movlw       3                       ;向IC 卡中写命令字
				movwf       temp2
				movlw       ic_com
				movwf       fsr
com_ic1	 
				movlw       8
				movwf       ic_bit
				movf        indf,0
				movwf       temp1
				incf        fsr
com_ic2	     
				bcf         portd,icscl
				btfsc       temp1,0
				bsf         portd,icsda
				btfss       temp1,0
				bcf         portd,icsda
				call        delus
				bsf         portd,icscl
				call        delus
				call        delus
				rrf         temp1
				decfsz      ic_bit
				goto        com_ic2
				decfsz      temp2
				goto        com_ic1
				movf        temp_fsr,0
				movwf       fsr
				retlw       0	 
;------------------------------------------------
;              对电卡外围电路的检查
;------------------------------------------------
check_ic
                        btfsc       portd,6         ;检测电卡是否插入售电机
                        bsf         ic_reg,1 
                        bsf         portd,0         ;检测电卡是否有电
                        movlw       h'ff'
                        movwf       ic_bit
                        call        delay_bits
                        btfss       portd,7         ;检测电卡是否短路
                        bsf         ic_reg,2
                        btfss       portd,7
                        bcf         portd,0
                        retlw       0
;-----------------------------------------------
break                                               ;finish all options
				bcf         portd,icscl
				bcf         portd,icrst
				call        delus
				bsf         portd,icrst
				call        delus
				call        delus
				bcf         portd,icrst
				retlw       0	
delay_bits                                          ;产生bit个脉冲		
				bcf         portd,icscl
				call        delus
				call        delus
				bsf         portd,icscl
				call        delus
				decfsz      ic_bit
				goto        delay_bits
				retlw       0
delus	
				movlw       6                          
				movwf       r0
				decfsz      r0
				goto        $-1
				retlw       0	
del70ms                 clrf        rtcc                      ;在3.579545MHz下,延时70ms
delays		
				movlw       7        
				OPTION
				movf        rtcc,0
				xorlw       0f5h
				btfss       status,2
				goto        delays
				retlw       0

del350ms                clrf        rtcc                      ;在3.579545MHz下,延时350ms
                        movlw       h'20'
                        movwf       r0
delays1		
				movlw       7        
				OPTION
				movf        rtcc,0
				xorlw       0f5h
				btfss       status,2
				goto        delays1
	                  decfsz      r0
	                  goto        delays1
				retlw       0 
                        end

;***********************************在sdj-ok3的基础上更改的****************************************
注释1:
        更改内容: 
     1、读电卡数据:       68 10 02 addr L cs 16 
     2、写电卡数据:       68 11 L addr data cs 16  
     3、写公司标识的数据为 68 99 L 79(addr) 42 88 74 69 69 77 42 53 16            *XJEEM* 的ASCII码
     4、重写电卡请求数据为:68 07 01 00 70 16                            ;对电卡的购电区和返写区清零
        售电机允许应答贞: 68 09 02 79 75 61 16  (OK)
     5、读保护区数据:     68 12 02 addr L cs 16 
     6、写保护区数据:     68 13 L addr data cs 16  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -