📄 sdj_v4.0.asm
字号:
;------------------------------------------------
sio_code_05 ;写工艺卡
btfss ic_reg,6
goto sio_errmm
bcf ic_reg,6
movf txdat3,0
xorlw h'08'
btfss status,2
goto sio_errff
goto write_ic
;------------------------------------------------
sio_code_06 ;读IC卡数据
bcf ic_reg,7
movf txdat3,0
xorlw h'01'
btfss status,2
goto sio_errff
movf txdat4,0
xorlw h'01'
btfss status,2
goto $+2
bsf ic_reg,7 ;读电卡购电区数据
btfsc status,2
goto read_ic
movf txdat4,0
xorlw h'02'
btfsc status,2
goto read_ic ;读电卡返写区数据
goto sio_errff
;------------------------------------------------
sio_code_07
movf txdat3,0
xorlw 1
btfss status,2
goto sio_errff
movf txdat4,0
btfss status,2
goto sio_errff
goto clr_ic
;------------------------------------------------
sio_code_08
movf txdat3,0
xorlw 06
btfss status,2
goto sio_errff
movf txdat4,0
movwf ic_code1
movf txdat5,0
movwf ic_code2
movf txdat6,0
movwf ic_code3
call ic_reset
call chk_ic_code
btfsc ic_reg,4
goto sio_ic_bad
btfsc ic_reg,5
goto sio_ic_errmm
movlw 03
movwf r2
movlw h'39' ;写密码
movwf ic_com
movlw h'01'
movwf ic_addr
movlw txdat7
movwf fsr
ic_wr_com
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_com
call del70ms
call rd_ic_code
movf ic_code10,0
movwf txdat7
movf ic_code20,0
movwf txdat8
movf ic_code30,0
movwf txdat9
goto write_ic_ok
;------------------------------------------------
sio_code_09
goto sio_errff
;------------------------------------------------
sio_code_10 ;读IC卡数据
movf txdat3,0
xorlw h'02'
btfss status,2
goto sio_errff
goto read_ic_ty
;------------------------------------------------
sio_code_11 ;写IC卡数据
btfss ic_reg,6
goto sio_errmm
bcf ic_reg,6
goto write_ic_ty
;------------------------------------------------
sio_code_12 ;读保护存储区
movf txdat3,0
xorlw h'02'
btfss status,2
goto sio_errff
goto read_ic_pro
;------------------------------------------------
sio_code_13 ;写保护存储区
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'3c'
movwf ic_com ;ic_com=32h
movf txdat4,0
movwf ic_addr ;ic_data=34h
movlw txdat5
movwf fsr
ic_wr_com0
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_com0
call del70ms
movf length,0
movwf r2
movf txdat4,0
movwf ic_addr
movlw txdat5
movwf fsr
movlw h'34'
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
;------------------------------------------------
sio_code_0f ;密码数据贞
movf txdat3,0
xorlw .5
btfss status,2
goto sio_errff
movf txdat4,0
addwf txdat6,0
xorwf txdat5,0
btfss status,2
goto sio_errff
movf txdat6,0
addwf txdat8,0
xorwf txdat7,0
btfss status,2
goto sio_errff
movf txdat4,0
movwf ic_code1
movf txdat6,0
movwf ic_code2
movf txdat8,0
movwf ic_code3
call ic_reset
movlw h'1'
movwf r2
call read_68
movf id1,0
xorlw h'ff'
bsf ic_reg,6
btfss status,2
goto sio_ic_old ;此卡为旧电卡
goto sio_ok_mm ;密码数据贞正确,且电卡为新电卡
;------------------------------------------------
sio_noin ;判断返写区是否有数据,IC卡是否插过电表
movf id1,0
xorlw h'ff'
btfss status,2
goto sio_iderr
movf id2,0
xorlw h'ff'
btfss status,2
goto sio_iderr
movf id3,0
xorlw h'ff'
btfss status,2
goto sio_iderr
movf id4,0
xorlw h'ff'
btfss status,2
goto sio_iderr
movf id5,0
xorlw h'ff'
btfss status,2
goto sio_iderr
goto sio_ic_noin
;-----------------------出错提示信息数据-------------
sio_no_power movlw h'00' ;电卡无电
goto sio_wrong
sio_no_ic movlw h'01' ;没有IC卡插到售电机中
goto sio_wrong
sio_ic_short bcf portd,0
movlw h'02' ;IC卡短路
goto sio_wrong
sio_ic_noin movlw h'03' ;电卡上次购电后没有插过电表
goto sio_wrong
sio_ic_bad movlw h'04' ;IC卡已作废
goto sio_wrong
sio_ic_errmm movlw h'05' ;IC卡密码错
goto sio_wrong
sio_errmm movlw h'06' ;密码数据贞出错,请重新发送数据
goto sio_wrong
sio_errff movlw h'07' ;数据传输错误
goto sio_wrong
sio_iderr movlw h'08' ;电卡表号和接收数据表号不一致
goto sio_wrong
sio_ic_old movlw h'09' ;此卡为旧电卡
goto sio_wrong
sio_ok_mm movlw h'10' ;密码数据贞正确,且电卡为新电卡
goto sio_wrong
sio_wrong
movwf txdat4
movlw h'68'
movwf txdat1
movlw h'a0'
movwf txdat2
movlw h'01'
movwf txdat3
call sio_tx
goto main
;------------------------------------------------
ic_clr_ok
movlw 68h
movwf txdat1
movlw 07
movwf txdat2
movlw 02
movwf txdat3
movlw 79h
movwf txdat4
movlw 75h
movwf txdat5
movlw 5fh
movwf txdat6
movlw 16h
movwf txdat7
call sio_tx
; bsf porta,0
; call del350ms
; bcf porta,0
goto main
;------------------------------------------------
sio_tx call sio_cscheck
movwf indf
incf fsr
movlw h'16'
movwf indf
; bcf txrw
bsf status,5
movlw h'bf' ;1200 under 3.579545MHz
movwf spbrg
movlw h'24'
movwf txsta
bsf txsta,5
bcf status,5
movf txdat3,0
addlw d'5'
movwf r1
movlw txdat1
movwf fsr
; bcf txrw
sio_send0
movf indf,0
movwf txreg
btfss pir1,4
goto $-1
movlw h'14' ;for 4m ,this sub program delay 12ms
movwf temp1
movlw h'ff'
movwf temp2
decfsz temp2
goto $-1
decfsz temp1
goto $-5
incf fsr
decfsz r1
goto sio_send0
bsf status,5
bcf txsta,5
bcf status,5
; bsf txrw
clrf count
clrf length
clrf bzreg
btfss ic_reg,6
clrf ic_reg
movlw txdat1
movwf fsr
bcf portd,0
retlw 0
;------------------------------------------------
sio_cscheck
movf txdat3,0
addlw h'03'
movwf r1
movlw txdat1
movwf fsr
clrw
addwf indf,0
incf fsr,1
decfsz r1,1
goto $-3
return
;------------------------------------------------
delay12 ;在4MHz晶振时,可延时12ms
movlw h'17'
movwf temp1
movlw h'ff'
movwf temp2
decfsz temp2
goto $-1
decfsz temp1
goto $-5
return
;------------------------------------------------
; opration to the ic_card
;------------------------------------------------
read_ic_ok
write_ic_ok
bsf status,5
movlw h'bf' ;1200 under 3.579545MHz
movwf spbrg
movlw h'24'
movwf txsta
bsf txsta,5
bcf status,5
movf length,0
movwf r1
movlw txdat1
movwf fsr
call sio_send0
; bsf porta,0
; call del350ms
; bcf porta,0
btfsc portd,6 ;检测电卡是否插入售电机
goto sio_no_ic
goto main
;------------------------------------------------
read_ic_ty
call ic_reset
movf txdat4,0
movwf ic_addr
movf txdat5,0
movwf length
movwf r2
call read_icty
goto read_ic_ok
;------------------------------------------------
read_ic_pro
call ic_reset
movf txdat4,0
movwf ic_addr
movf txdat5,0
movwf length
movwf r2
movlw txdat1
movwf fsr
movlw h'34'
movwf ic_com
movwf ic_data
call read_00
goto read_ic_ok
;------------------------------------------------
read_ic
call ic_reset
movlw h'30'
movwf length
movwf r2
btfsc ic_reg,7
call read_ic1
btfss ic_reg,7
call read_ic2
goto read_ic_ok
;------------------------------------------------
read_ic1
movlw h'20'
goto $+2
read_ic2
movlw h'50'
movwf ic_addr
read_icty
movlw txdat1
movwf fsr
movlw h'30'
movwf ic_com
movwf ic_data
goto read_00
;------------------------------------------------
read_68 movlw h'20'
goto $+2
read_iid
movlw h'53'
movwf ic_addr
movlw id1
movwf fsr
movlw h'30'
movwf ic_com
movwf ic_data
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -