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

📄 mfrc500uc.s

📁 该程序是医院用的CPCR记录仪的终端控制程序
💻 S
📖 第 1 页 / 共 3 页
字号:
	sts _MInfo+9,R2
	.dbline 229
	.dbline 230
;       MSndBuffer[0] = select_code;
	lds R30,_MSndBuffer
	lds R31,_MSndBuffer+1
	std z+0,R10
	.dbline 231
;       MSndBuffer[1] = 0x70;         // number of bytes send
	ldi R24,112
	lds R30,_MSndBuffer
	lds R31,_MSndBuffer+1
	std z+1,R24
	.dbline 232
;       memcpy(MSndBuffer + 2,snr,4);
	ldi R24,4
	ldi R25,0
	std y+1,R25
	std y+0,R24
	movw R18,R22
	lds R16,_MSndBuffer
	lds R17,_MSndBuffer+1
	subi R16,254  ; offset = 2
	sbci R17,255
	xcall _memcpy
	.dbline 233
;       MSndBuffer[6] = MSndBuffer[2] 
	lds R30,_MSndBuffer
	lds R31,_MSndBuffer+1
	ldd R2,z+3
	lds R30,_MSndBuffer
	lds R31,_MSndBuffer+1
	ldd R3,z+2
	eor R3,R2
	lds R30,_MSndBuffer
	lds R31,_MSndBuffer+1
	ldd R2,z+4
	eor R3,R2
	lds R30,_MSndBuffer
	lds R31,_MSndBuffer+1
	ldd R2,z+5
	eor R3,R2
	lds R30,_MSndBuffer
	lds R31,_MSndBuffer+1
	std z+6,R3
	.dbline 237
;                       ^ MSndBuffer[3] 
;                       ^ MSndBuffer[4] 
;                       ^ MSndBuffer[5];
;       MInfo.nBytesToSend   = 7;
	ldi R24,7
	sts _MInfo+4,R24
	.dbline 238
;       status = PcdSingleResponseCmd(0x1e,
	ldi R24,<_MInfo
	ldi R25,>_MInfo
	std y+3,R25
	std y+2,R24
	lds R2,_MRcvBuffer
	lds R3,_MRcvBuffer+1
	std y+1,R3
	std y+0,R2
	lds R18,_MSndBuffer
	lds R19,_MSndBuffer+1
	ldi R16,30
	xcall _PcdSingleResponseCmd
	mov R20,R16
	clr R21
	.dbline 242
;                           MSndBuffer,
;                           MRcvBuffer,
;                           &MInfo);
;        *sak = 0;   
	clr R2
	ldd R30,y+10
	ldd R31,y+11
	std z+0,R2
	.dbline 243
;       if (status == MI_OK)    // no timeout occured
	cpi R20,0
	cpc R20,R21
	brne L99
X9:
	.dbline 244
;       {
	.dbline 245
;          if (MInfo.nBitsReceived != 8)    // last byte is not complete
	lds R24,_MInfo+6
	lds R25,_MInfo+6+1
	cpi R24,8
	ldi R30,0
	cpc R25,R30
	breq L101
	.dbline 246
;          {
	.dbline 247
;             status = MI_BITCOUNTERR;
	ldi R20,-11
	ldi R21,-1
	.dbline 248
;          }
	xjmp L102
L101:
	.dbline 250
;          else
;          {
	.dbline 251
;             *sak = MRcvBuffer[0];
	lds R30,_MRcvBuffer
	lds R31,_MRcvBuffer+1
	ldd R2,z+0
	ldd R30,y+10
	ldd R31,y+11
	std z+0,R2
	.dbline 252
;             memcpy(MLastSelectedSnr,snr,4);            
	ldi R24,4
	ldi R25,0
	std y+1,R25
	std y+0,R24
	movw R18,R22
	ldi R16,<_MLastSelectedSnr
	ldi R17,>_MLastSelectedSnr
	xcall _memcpy
	.dbline 253
;          }
L102:
	.dbline 254
;       }
L99:
	.dbline 255
;    }
L89:
	.dbline 256
;    return status;
	mov R16,R20
	.dbline -2
L88:
	adiw R28,4
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r status 20 I
	.dbsym l sak 10 pc
	.dbsym r snr 22 pc
	.dbsym r select_code 10 c
	.dbend
	.dbfunc e Mf500PcdSetDefaultAttrib _Mf500PcdSetDefaultAttrib fc
;         status -> R16,R17
	.even
_Mf500PcdSetDefaultAttrib::
	.dbline -1
	.dbline 259
; }
; char Mf500PcdSetDefaultAttrib(void)
; {
	.dbline 260
;    int   status = MI_OK;
	clr R16
	clr R17
	.dbline 261
;    return status;
	.dbline -2
L104:
	.dbline 0 ; func end
	ret
	.dbsym r status 16 I
	.dbend
	.dbfunc e Mf500PiccAuth _Mf500PiccAuth fc
;         status -> R20,R21
;          block -> y+9
;       key_addr -> R10
;       key_type -> R22
	.even
_Mf500PiccAuth::
	xcall push_gset3
	mov R10,R18
	mov R22,R16
	sbiw R28,3
	.dbline -1
	.dbline 267
; }
; char Mf500PiccAuth(unsigned char key_type,    // PICC_AUTHENT1A or PICC_AUTHENT1B
;                    unsigned char key_addr,    // key address in reader storage
;                    unsigned char block)       // block number which should be 
;                                               // authenticated
; {
	.dbline 268
;    int            status = MI_OK;
	clr R20
	clr R21
	.dbline 269
;    status = Mf500PiccAuthE2(  key_type,
	ldd R0,y+9
	std y+2,R0
	std y+0,R10
	ldi R18,<_MLastSelectedSnr
	ldi R19,>_MLastSelectedSnr
	mov R16,R22
	xcall _Mf500PiccAuthE2
	mov R20,R16
	clr R21
	.dbline 273
;                               MLastSelectedSnr,
;                               key_addr,
;                               block);
;    return status;
	.dbline -2
L105:
	adiw R28,3
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r status 20 I
	.dbsym l block 9 c
	.dbsym r key_addr 10 c
	.dbsym r key_type 22 c
	.dbend
	.dbfunc e Mf500HostCodeKey _Mf500HostCodeKey fc
;         status -> R20,R21
;             hn -> R20
;             ln -> R22
;            cnt -> R10
;          coded -> R18,R19
;        uncoded -> R16,R17
	.even
_Mf500HostCodeKey::
	xcall push_gset3
	.dbline -1
	.dbline 277
; }
; char Mf500HostCodeKey(  unsigned char *uncoded, // 6 bytes key value uncoded
;                      unsigned char *coded)   // 12 bytes key value coded
; {
	.dbline 278
;    int status = MI_OK;
	clr R20
	clr R21
	.dbline 279
;    unsigned char cnt = 0;
	clr R10
	.dbline 280
;    unsigned char ln  = 0;     // low nibble
	clr R22
	.dbline 281
;    unsigned char hn  = 0;     // high nibble
	.dbline 282
;     for (cnt = 0; cnt < 6; cnt++)
	xjmp L110
L107:
	.dbline 283
	.dbline 284
	mov R30,R10
	clr R31
	add R30,R16
	adc R31,R17
	ldd R22,z+0
	andi R22,15
	.dbline 285
	mov R30,R10
	clr R31
	add R30,R16
	adc R31,R17
	ldd R20,z+0
	swap R20
	andi R20,#0x0F
	.dbline 286
	ldi R24,2
	mul R24,R10
	movw R30,R0
	add R30,R18
	adc R31,R19
	mov R24,R22
	com R24
	andi R24,#0x0F
	swap R24
	or R24,R22
	std z+1,R24
	.dbline 287
	ldi R24,2
	mul R24,R10
	movw R30,R0
	add R30,R18
	adc R31,R19
	mov R24,R20
	com R24
	andi R24,#0x0F
	swap R24
	or R24,R20
	std z+0,R24
	.dbline 288
L108:
	.dbline 282
	inc R10
L110:
	.dbline 282
	mov R24,R10
	cpi R24,6
	brlo L107
	.dbline 289
;    {
;       ln = uncoded[cnt] & 0x0F;
;       hn = uncoded[cnt] >> 4;
;       coded[cnt * 2 + 1]     =  (~ln << 4) | ln;
;       coded[cnt * 2 ] =  (~hn << 4) | hn;
;    }
;    return MI_OK;
	clr R16
	.dbline -2
L106:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r status 20 I
	.dbsym r hn 20 c
	.dbsym r ln 22 c
	.dbsym r cnt 10 c
	.dbsym r coded 18 pc
	.dbsym r uncoded 16 pc
	.dbend
	.dbfunc e Mf500PiccAuthKey _Mf500PiccAuthKey fc
;              i -> R12
;         status -> R20,R21
;          block -> y+14
;           keys -> y+12
;            snr -> R10,R11
;      auth_mode -> R22
	.even
_Mf500PiccAuthKey::
	xcall push_gset4
	movw R10,R18
	mov R22,R16
	sbiw R28,4
	.dbline -1
	.dbline 295
; }
; char Mf500PiccAuthKey(unsigned char auth_mode,
;                      unsigned char *snr,       
;                      unsigned char *keys,      
;                      unsigned char block)      
; {
	.dbline 296
;    int status     = MI_OK;
	clr R20
	clr R21
	.dbline 297
;    unsigned char i = 0;
	clr R12
	.dbline 298
;    PcdSetTmo(106);
	ldi R16,106
	ldi R17,0
	xcall _PcdSetTmo
	.dbline 299
;    FlushFIFO();    // empty FIFO
	xcall _FlushFIFO
	.dbline 300
;    ResetInfo(MInfo);
	clr R2
	sts _MInfo,R2
	.dbline 300
	clr R3
	sts _MInfo+1+1,R3
	sts _MInfo+1,R2
	.dbline 300
	sts _MInfo+3,R2
	.dbline 300
	sts _MInfo+4,R2
	.dbline 300
	sts _MInfo+5,R2
	.dbline 300
	sts _MInfo+6+1,R3
	sts _MInfo+6,R2
	.dbline 300
	sts _MInfo+8,R2
	.dbline 300
	sts _MInfo+9,R2
	.dbline 300
	.dbline 301
;    memcpy(MSndBuffer,keys,12);                  // write 12 bytes of the key
	ldi R24,12
	ldi R25,0
	std y+1,R25
	std y+0,R24
	ldd R18,y+12
	ldd R19,y+13
	lds R16,_MSndBuffer
	lds R17,_MSndBuffer+1
	xcall _memcpy
	.dbline 302
;    MInfo.nBytesToSend = 12;
	ldi R24,12
	sts _MInfo+4,R24
	.dbline 303
;    if ((status=PcdSingleResponseCmd(0x19,MSndBuffer,MRcvBuffer,&MInfo)) == MI_OK)
	ldi R24,<_MInfo
	ldi R25,>_MInfo
	std y+3,R25
	std y+2,R24
	lds R2,_MRcvBuffer
	lds R3,_MRcvBuffer+1
	std y+1,R3
	std y+0,R2
	lds R18,_MSndBuffer
	lds R19,_MSndBuffer+1
	ldi R16,25
	xcall _PcdSingleResponseCmd
	mov R2,R16
	clr R3
	movw R20,R2
	tst R16
	brne L120
	.dbline 304
;    {      
	.dbline 305
;        status = Mf500PiccAuthState(auth_mode,snr,block); 
	ldd R0,y+14
	std y+0,R0
	movw R18,R10
	mov R16,R22
	xcall _Mf500PiccAuthState
	mov R20,R16
	clr R21
	.dbline 306
;    }
L120:
	.dbline 307
;    return status;
	mov R16,R20
	.dbline -2
L111:
	adiw R28,4
	xcall pop_gset4
	.dbline 0 ; func end
	ret
	.dbsym r i 12 c
	.dbsym r status 20 I
	.dbsym l block 14 c
	.dbsym l keys 12 pc
	.dbsym r snr 10 pc
	.dbsym r auth_mode 22 c
	.dbend
	.dbfunc e Mf500PiccAuthState _Mf500PiccAuthState fc
;              i -> R12
;         status -> R20,R21
;          block -> y+12
;            snr -> R22,R23
;      auth_mode -> R10
	.even
_Mf500PiccAuthState::
	xcall push_gset4
	movw R22,R18
	mov R10,R16
	sbiw R28,4
	.dbline -1
	.dbline 312
; }
; char Mf500PiccAuthState(   unsigned char auth_mode,
;                         unsigned char *snr,
;                         unsigned char block)
; {
	.dbline 313
;    int status = MI_OK;
	clr R20
	clr R21
	.dbline 314
;    unsigned char i = 0;
	clr R12
	.dbline 315
;    status = ReadRC(RegErrorFlag);    // read error flags of the previous
	ldi R16,10
	xcall _ReadRC
	mov R20,R16
	clr R21
	.dbline 316
;    if (status != MI_OK)
	cpi R20,0
	cpc R20,R21
	breq L123
X11:
	.dbline 317
;    {
	.dbline 318
;       if (status & 0x40)            // key error flag set
	sbrs R20,6
	rjmp L125
	.dbline 319
;          status = MI_KEYERR;
	ldi R20,-9
	ldi R21,-1
	xjmp L124
L125:
	.dbline 321
;       else
;          status = MI_AUTHERR;       // generic authentication error 
	ldi R20,-4
	ldi R21,-1
	.dbline 322
;    }
	xjmp L124
L123:
	.dbline 324
;    else
;    {
	.dbline 325
;       PcdSetTmo(106);
	ldi R16,106
	ldi R17,0
	xcall _PcdSetTmo
	.dbline 326
;       MSndBuffer[0] = auth_mode;        // write authentication command
	lds R30,_MSndBuffer
	lds R31,_MSndBuffer+1
	std z+0,R10
	.dbline 327
;       MSndBuffer[1] = block;    // write block number for authentication
	lds R30,_MSndBuffer
	lds R31,_MSndBuffer+1
	ldd R0,y+12
	std z+1,R0
	.dbline 328
;       memcpy(MSndBuffer + 2,snr,4); // write 4 bytes card serial number 
	ldi R24,4
	ldi R25,0
	std y+1,R25
	std y+0,R24
	movw R18,R22
	lds R16,_MSndBuffer
	lds R17,_MSndBuffer+1
	subi R16,254  ; offset = 2
	sbci R17,255
	xcall _memcpy
	.dbline 329
;       ResetInfo(MInfo);
	clr R2
	sts _MInfo,R2
	.dbline 329
	clr R3
	sts _MInfo+1+1,R3
	sts _MInfo+1,R2
	.dbline 329
	sts _MInfo+3,R2
	.dbline 329
	sts _MInfo+4,R2
	.dbline 329
	sts _MInfo+5,R2
	.dbline 329
	sts _MInfo+6+1,R3
	sts _MInfo+6,R2
	.dbline 329
	sts _MInfo+8,R2
	.dbline 329
	sts _MInfo+9,R2
	.dbline 329
	.dbline 330
;       MInfo.nBytesToSend = 6;
	ldi R24,6
	sts _MInfo+4,R24
	.dbline 331
;       if ((status = PcdSingleResponseCmd(0x0C,
	ldi R24,<_MInfo
	ldi R25,>_MInfo
	std y+3,R25
	std y+2,R24
	lds R2,_MRcvBuffer
	lds R3,_MRcvBuffer+1
	std y+1,R3
	std y+0,R2
	lds R18,_MSndBuffer
	lds R19,_MSndBuffer+1
	ldi R16,12
	xcall _PcdSingleResponseCmd
	mov R2,R16
	clr R3
	movw R20,R2
	tst R16
	breq X12
	xjmp L135
X12:
	.dbline 335
;                                MSndBuffer,
;                                MRcvBuffer,
;                                &MInfo)) == MI_OK)
;       {
	.dbline 336
;          if (ReadRC(RegSecondaryStatus) & 0x07) // RxLastBits mu

⌨️ 快捷键说明

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