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

📄 sdj_v4.0.asm

📁 本软件对IC卡的4442进行了分析,是一个通用的读写软件,并且通过编译,可以直接使用
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;***************************************************************************
;                        售电机程序  版本1.2——12.9
;                   本程序采用PIC16F74单片机,晶振3.579545MHz
;2004-11-10,增加了用户卡的数据帧长度,增加10个字节用于处理和预留
;2004-12-10,增加了工艺卡的数据祯长度
;增加了更改密码功能
;*************************************************************************** 
;操作过程:
;当写电卡时(除老用户购电),售电机收到密码数据贞后,判断此卡是否为旧电卡,
;  如果为旧电卡,提示后台是否确认写新电卡数据。如果电卡为新电卡,则返回密码
;  数据贞正确,且电卡为新电卡。
;当老用户购电时,要判断以下几点:
;   1、电卡中的表号和后台数据的表号是否一致
;   2、电卡上次购电后,是否插过电表
;****************************************************************************
;在本程序中,没有使用中断,对接收和发送数据是采用查询中断标志的方法。
;icreg是对IC进行操作过程中的标志寄存器
;bzreg是在通讯过程中的标志寄存器,其具体定义如下:
;ic_reg,0:是否有+5V电源给IC卡
;ic_reg,1:是否有IC卡插入售电机中
;ic_reg,2:IC卡是否短路
;ic_reg,3:IC卡是否插过电表
;ic_reg,4:IC卡是否损坏
;ic_reg,5:IC卡密码是否正确
;ic_reg,6:是否接收到密码数据贞
;ic_reg,7:读购电区和返写区数据标志

;bzreg,0:第一个字节是否已接收
;bzreg,1:当前接收的字节是否为长度字节
;bzreg,2: 是否接收完毕 
;****************************************************************************
#define                      txif    0c,4      ;发送标志
#define                      rcif    0c,5      ;接收标志
#define                      txrw    05,0      ;读、写控制位 PA.0
icvcc      equ    0          ;IC卡电源
icrst      equ    1          ;IC卡复位    ;PD.1
icscl      equ    2          ;IC卡控制线  ;PD.2
icsda      equ    5          ;IC卡数据线  ;PD.5
plugtest   equ    6          ;IC卡脉冲测试
shorttest  equ    7          ;IC卡短路测试
icfus      equ    3          ;IC卡保护
icpgm      equ    4          ;IC卡编程
indf                         equ     h'0000'
rtcc                         equ     h'0001'
status                       equ     h'0003'
fsr                          equ     h'0004'
porta                        equ     h'0005'
portd                        equ     h'0008'
pclath                       equ     h'000a'
intcon                       equ     h'000b'
pir1                         equ     h'000c'
tmr1l                        equ     h'000e'
tmr1h                        equ     h'000f'
t1con                        equ     h'0010'
pie1                         equ     h'008c'
txsta                        equ     h'0098'
rcsta                        equ     h'0018'
txreg                        equ     h'0019'
rcreg                        equ     h'001a'
spbrg                        equ     h'0099'
adcon1                       equ     h'009f'
adcon0                       equ     h'001f'

OPTION                       equ     h'0081'
trisa                        equ     h'0085'
trisd                        equ     h'0088'
           cblock    0x20
bzreg
count
length
r0
r1
r2
datas
xmtdat
txdat
temp1
temp2
w_temp
status_temp
temp_fsr
id1
id2
id3        ;30h
id4
id5 
ic_bit     
ic_reg
ic_com
ic_addr
ic_data 
ic_code1
ic_code2
ic_code3
ic_count0
ic_code10
ic_code20
ic_code30  

             endc
             cblock     0x40
txdat1
txdat2
txdat3
txdat4
txdat5
txdat6
txdat7
txdat8
txdat9
                endc
				org         0x01
				goto        start
				org         0x04
	                  call        tmr1_int
				retfie
start
				bcf         status,6
				bsf         status,5 
				movlw       h'00'                
				movwf       pie1
				movlw       h'04'              
				movwf       txsta
				movlw       h'bf'              
				movwf       spbrg
				movlw       h'07'
				movwf       adcon1
				movlw       h'00'
				movwf       trisa
                        movlw       h'e0'
                        movwf       trisd
				bcf         status,6
				bcf         status,5
	                  bcf         porta,0
                        bsf         portd,6
				movlw       h'90'              
				movwf       rcsta
;;				bsf         txrw 
                clrf        adcon0	                        
				clrf        rcreg				             
				clrf        ic_reg 
				clrf        bzreg 
				clrf        count
				clrf        length
				clrf        txdat
	       
	                  bcf         intcon,6
                        bcf         t1con,0
                        bcf         intcon,7
                        bsf         status,5
                        bcf         pie1,0
                        bcf         status,5

main
;				bsf         txrw
				btfsc       pir1,5
				goto        sio_rx_init
				btfsc       bzreg,2
				goto        sio_rx_judge   
                        nop
                        nop
;                       goto        sio_errmm       
				goto        main   
;-------------------------------------------------------
tmr1_int
                        btfss       pir1,0
                        retlw       0
                        bcf         pir1,0
                        bcf         intcon,6
                        bcf         t1con,0
                        bcf         intcon,7
                        bsf         status,5
                        bcf         pie1,0
                        bcf         status,5
                        clrf        bzreg
                        clrf        count
                        clrf        length  
                        retlw       0
;-------------------------------------------------------         
sio_rx_init     
                        bcf         pir1,5
				bcf         status,5
				btfss       bzreg,0                ;bzreg,0=0 接收第1个字节
				goto        sio_rx_first
				goto        sio_rx_datas
sio_rx_first     
				bsf         bzreg,0                                 
				movlw       txdat1
				movwf       r1
sio_rx_datas     
                        movlw       01
                        movwf       tmr1l
                        movlw       00
                        movwf       tmr1h
                        bcf         intcon,6
                        bcf         t1con,0
                        bcf         intcon,7
                        bsf         status,5
                        bcf         pie1,0
                        bcf         status,5


				movf        r1,0
				movwf       fsr
				movf        rcreg,0
				movwf       indf
				incf        r1
				incf        count 
				movf        count,0
				xorlw       h'03'
				btfss       status,2
				goto        sio_rx_receiv
				bsf         bzreg,1                   ;receiv L byte
				movlw       d'05'
				addwf       txdat3,0
				movwf       length                    ;length is the total length received	
				goto        sio_rx_over
sio_rx_receiv
				movf        count,0
				xorwf       length,0
				btfss       status,2
				goto        sio_rx_over	
				bsf         bzreg,2                   ;complet receiv  接收完成
                        bcf         intcon,6
                        bcf         t1con,0
                        bcf         intcon,7
                        bsf         status,5
                        bcf         pie1,0
                        bcf         status,5
                        goto        main
sio_rx_over   
                        movlw       01
                        movwf       tmr1l
                        movlw       00h
                        movwf       tmr1h                        
                        bsf         intcon,6
                        bsf         t1con,0
                        bsf         status,5
                        bsf         pie1,0
                        bcf         status,5
                        bsf         intcon,7
                        goto        main  	
;************************************************
sio_rx_judge                                                   ;judge the datas received 
				btfss       bzreg,2
				goto        main
				bcf         bzreg,2                                          
				movf        txdat1,0
				xorlw       h'68'
				btfss       status,2              
				goto        sio_errff
				bcf         status,2				
				call        sio_cscheck 						;csc
				xorwf       indf,0
				btfss       status,2
				goto        sio_errff          
				bcf         status,2
				incf        fsr
				movf        indf,0
				xorlw       h'16'
				btfss       status,2
				goto        sio_errff
				goto        sio_rx_contrl
;**********************************************************************************
sio_rx_contrl                           
				btfsc       portd,6                ;检测电卡是否插入售电机
				goto        sio_no_ic
				bsf         portd,0                ;power-on for ic card 
				nop
				nop
				nop
				btfss       portd,7                ;检测电卡是否短路
				goto        sio_ic_short
	 	        movf        txdat2,0
				xorlw       h'00'                 
				btfsc       status,2
				goto        sio_code_00            ;烽鸣器叫
				movf        txdat2,0
				xorlw       h'01'                 
				btfsc       status,2
				goto        sio_code_01            ;初始化卡
				movf        txdat2,0
				xorlw       h'02'
				btfsc       status,2
				goto        sio_code_02            ;用户卡
				movf        txdat2,0
				xorlw       h'03'
				btfsc       status,2
				goto        sio_code_03	           ;检测卡
				movf        txdat2,0
				xorlw       h'04'
				btfsc       status,2
				goto        sio_code_04	           ;补卡
				movf        txdat2,0
				xorlw       h'05'
				btfsc       status,2
				goto        sio_code_05	           ;工艺卡
                        movf        txdat2,0
				xorlw       h'0f'
				btfsc       status,2
				goto        sio_code_0f            ;接收密码贞 
                        movf        txdat2,0
				xorlw       h'06'
				btfsc       status,2
				goto        sio_code_06         ;读卡数据
				movf        txdat2,0
				xorlw       h'07'
				btfsc       status,2
				goto        sio_code_07
                        movf        txdat2,0
				xorlw       h'08'
				btfsc       status,2
				goto        sio_code_08	
				movf        txdat2,0
				xorlw       h'09'
				btfsc       status,2
				goto        sio_code_09
				movf        txdat2,0
				xorlw       h'10'
				btfsc       status,2
				goto        sio_code_10
				movf        txdat2,0
				xorlw       h'11'
				btfsc       status,2
				goto        sio_code_11
                        movf        txdat2,0
				xorlw       h'12'
				btfsc       status,2
				goto        sio_code_12
				movf        txdat2,0
				xorlw       h'13'
				btfsc       status,2
				goto        sio_code_13
				goto        sio_errff                 
;------------------------------------------------68 00 05 53 55 47 41 52
sio_code_00 
	                  movf        txdat3,0
	                  xorlw       h'05'
	                  btfss       status,2
	                  goto        sio_errff
	                  movf        txdat4,0
	                  xorlw       h'53'
	                  btfss       status,2
	                  goto        sio_errff
                        movf        txdat5,0
	                  xorlw       h'55'
	                  btfss       status,2
	                  goto        sio_errff
                        movf        txdat6,0
	                  xorlw       h'47'
	                  btfss       status,2
	                  goto        sio_errff
                        movf        txdat7,0
	                  xorlw       h'41'
	                  btfss       status,2
	                  goto        sio_errff
                        movf        txdat8,0
	                  xorlw       h'52'
	                  btfss       status,2
	                  goto        sio_errff
                        bsf         porta,0				;jiao 
		            call        del350ms  
		            bcf         porta,0
	                  clrf        count
				clrf        length
				clrf        bzreg
                        goto        main
;------------------------------------------------
sio_code_01                                             ;写初始化电卡  
                        btfss       ic_reg,6
				goto        sio_errmm 
	                  bcf         ic_reg,6               
				movf        txdat3,0
				xorlw       h'1e'
				btfss       status,2
				goto        sio_errff  
				goto        write_ic  
;------------------------------------------------
sio_code_02                                              ;老用户购电,判断表号是否一致,电卡是否插过电表;id=ff 
                        btfss       ic_reg,6 
				goto        sio_errmm
	                  bcf         ic_reg,6               
				movf        txdat3,0
				xorlw       1ch
				btfsc       status,2
				goto        $+5
				movf        txdat3,0
				xorlw       h'17'
				btfss       status,2
				goto        sio_errff  
				call        ic_reset
				movlw       h'5' 
				movwf       r2  
				call        read_iid
				movf        id1,0
				xorwf       txdat4,0
				btfss       status,2
				goto        sio_noin		
				movf        id2,0
				xorwf       txdat5,0
				btfss       status,2
				goto        sio_noin	
				movf        id3,0
				xorwf       txdat6,0
				btfss       status,2
				goto        sio_noin	
				movf        id4,0
				xorwf       txdat7,0
				btfss       status,2
				goto        sio_noin
				movf        id5,0
				xorwf       txdat8,0
				btfss       status,2
				goto        sio_noin 
				goto        write_ic       
;------------------------------------------------
sio_code_03                                        ;写检测卡 
                        btfss       ic_reg,6
 				goto        sio_errmm
                        bcf         ic_reg,6               
				movf        txdat3,0
				xorlw       h'00'
				btfss       status,2
				goto        sio_errff
				movf        txdat4,0
				xorlw       h'6b'
				btfss       status,2
				goto        sio_errff 
				goto        write_ic   
;------------------------------------------------
sio_code_04                                        ;写补卡 
                        btfss       ic_reg,6
				goto        sio_errmm
	                  bcf         ic_reg,6               
				movf        txdat3,0
				xorlw       h'00'
				btfss       status,2
				goto        sio_errff
				movf        txdat4,0
				xorlw       h'6c'
				btfss       status,2
				goto        sio_errff 
				goto        write_ic 

⌨️ 快捷键说明

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