📄 tx_2313_1.asm
字号:
; M. Ohsmann
; 13.56 MHz Clock ATtiny2313
; generate REQ or WUPA signal for MIFARE cards
;
; PORTB.0 Modulation output
; PORTB.1 Trigger output
.nolist
.include "tn2313def.inc"
.list
.def fastCNTR =r16 // fast inner counter for generating short times
.def slowCNTR =r17 // outer loop counter
.def temp =r18 // temporary storage
.CSEG
.org 0
rjmp RESET // goto to start of main program
RESET: ldi r16,low(RAMEND) // initialize STACK
out SPL,r16
ldi temp,$00f // set port B.0 B.1 B.2 B.3 as output
out DDRB,temp
start: cbi PORTB,0 // TX off
ldi slowCNTR,5 // wait 5 units of long time
rcall long // to do POWER-ON-RESET of card
sbi PORTB,0 // TX on
ldi slowCNTR,14 // wait 14 units of long time
rcall long // to CHARGE card
sbi PORTB,1 // generate TRIGGER
rcall REQA // execute command
ldi slowCNTR,32 // delay until answer begins
rcall delay
cbi PORTB,1 // generate TRIGGER falling edge
ldi slowCNTR,5 // wait 5 units to observe answer
rcall long
rjmp start // and start all over aigain
//-----------------------------------------------------------------------------------
/*
from iso 14443-2-fcd:
The following sequences are defined:
X ..P. sequence X after a time of 64/fc a "pause" shall occur
Y .... sequence Y for the full bit duration (128/fc) no modulation shall occur
Z P... sequence Z at the beginning of the bit duration a "pause" shall occur
pause: approx 2.5 us =approx 32/fc
Bit time: 128/fc = 9.439528.. us
The above sequences are used to code the following information :
logic "1" sequence X
logic "0" sequence Y with the following two exceptions:
i) If there are two or more contiguous "0"s, sequence Z shall be used from the second "0" on
ii) If the first bit after a "start of frame" is "0" , sequence Z shall be used to represent
this and any "0"s which follow directly thereafter
Start of communication sequence Z
End of communication logic "0" followed by sequence Y
No information at least two sequences Y
*/
/*
REQA command =026H 00100110B as 7 Bits: 0100110B
7Bit LSB first REQU bit sequence 0110010
S 0 1 1 0 0 1 0 E S=start, E=End
Z Z X X Y Z X Y Z Y sequence
P...P.....P...P.....P.....P.....P....... pulse pattern
3 5 3 5 5 5 infty time between pulses
*/
REQA: rcall seq3
rcall seq5
rcall seq3
rcall seq5
rcall seq5
rcall seq5
rcall seq3
ret
/*
WUPA command =052H 01010010B as 7 Bits: 1010010B
7Bit LSB first WUPA bit sequence 0100101
S 0 1 0 0 1 0 1 E S=start, E=End
Z Z X Y Z X Y X Y Y sequence
P...P.....P.....P.....P.......P......... pulse pattern
3 5 5 5 7 infty time between pulses
*/
WUPA: rcall seq3
rcall seq5
rcall seq5
rcall seq5
rcall seq7
rcall seq3
ret
//-----------------------------------------------------------------------------------
seq3: ldi slowCNTR,3
rjmp GENseq
seq5: ldi slowCNTR,5
rjmp GENseq
seq7: ldi slowCNTR,7
rjmp GENseq
// GENseq generates
// a pause of duration TAU in the carrier
// and then waits slowCNTR times TAU
//
GENseq: cbi PORTB,0 ; TX off
rcall tau
sbi PORTB,0 ; TX on
delay: rcall tau
dec slowCNTR
brne delay
ret
// generate a time delay approx. 32/fc long
tau: ldi fastCNTR,6
tauLP: dec fastCNTR
brne tauLP
nop
ret
// generate a long time delay, length specified in slowCNTR
long: clr fastCNTR
rcall tauLP
dec slowCNTR
brne long
ret
//-----------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -