📄 main.s
字号:
ret
.even
_stop_time0::
; }
;
; /**********************************************************************
; functionName:void stop_time0(void)
; description:停止定时器0
; **********************************************************************/
; void stop_time0(void)
; {
; TCCR0 = 0x00; //stop
clr R2
out 0x33,R2
;
; gTmr0OvrCount = 0;
clr R3
sts _gTmr0OvrCount+1,R3
sts _gTmr0OvrCount,R2
L76:
.dbline 0 ; func end
ret
; _20ms -> R16,R17
.even
_start_timer2::
; }
;
;
; /**********************************************************************
; functionName:void start_timer2(void)
; description:定时器2初始化
; desired value: 20mSec
; actual value: 19.861mSec (0.7%)
; **********************************************************************/
; void start_timer2(uint _20ms)
; {
; TCCR2 = 0x00; //stop
clr R2
out 0x25,R2
; ASSR = 0x00; //set async mode
out 0x22,R2
; TCNT2 = 0x71;
ldi R24,113
out 0x24,R24
;
; TIMSK |= 0x40; // 定时器2溢出中断
in R24,0x39
ori R24,64
out 0x39,R24
; OCR2 = 0x8F; // 定时器比较值
ldi R24,143
out 0x23,R24
;
; gTmr2OvrCount = _20ms;
sts _gTmr2OvrCount+1,R17
sts _gTmr2OvrCount,R16
;
; TCCR2 = 0x07; // Count clock/1024, start Timer0
ldi R24,7
out 0x25,R24
L77:
.dbline 0 ; func end
ret
.even
_stop_time2::
; }
;
; /**********************************************************************
; functionName:void stop_time2(void)
; description:停止定时器2
; **********************************************************************/
; void stop_time2(void)
; {
; TCCR0 = 0x00; //stop
clr R2
out 0x33,R2
;
; gTmr2OvrCount = 0;
clr R3
sts _gTmr2OvrCount+1,R3
sts _gTmr2OvrCount,R2
L78:
.dbline 0 ; func end
ret
; cKeyCode -> R22
; sak1 -> y+71
; tempbuf -> y+66
; M41T0Data -> y+58
; tt1 -> y+56
; OpCardOk -> R10
; blockdata -> y+40
; leftMoney -> R12,R13
; CurrTimeInfo -> y+28
; cardserialno -> y+24
; statusOfIC -> R14
; szRecordInfoBytes -> y+4
; counter -> R20
.even
_main::
sbiw R28,63
sbiw R28,10 ; offset = 73
; }
;
;
;
;
;
;
;
;
;
;
;
;
;
; /**********************************************************************
; functionName:void main(void)
; description:主函数
; **********************************************************************/
; void main(void)
; {
; uchar counter;
; char tempbuf[5];
;
; //键盘
; uchar cKeyCode = 0;
clr R22
;
; uchar tt1[2];
; uchar statusOfIC;
;
; //寻射频卡号和扇区的某数据块缓冲
; uchar cardserialno[4];
; uchar *sak1;
; uchar blockdata[16];
;
; //卡内剩余金额
; uint leftMoney = 0;
clr R12
clr R13
;
; //从M41T0器件中读取的当前时间信息
; uchar M41T0Data[8];
; uchar CurrTimeInfo[12];
;
; //完整的一条消费信息字节
; uchar szRecordInfoBytes[20];
; //卡消费成功标志
; uchar OpCardOk = 0;
clr R10
;
;
;
;
;
; ///////////////////////////////////////////////////////////////////
; //初始化硬件资源
; all_init();
xcall _all_init
;
; //得到FLASH的历史数据页号和字节地址
; GetHistoryPageAndBytesAddr(&gnHistoryFlashPage, &gnHistoryBytesBlock);
ldi R18,<_gnHistoryBytesBlock
ldi R19,>_gnHistoryBytesBlock
ldi R16,<_gnHistoryFlashPage
ldi R17,>_gnHistoryFlashPage
xcall _GetHistoryPageAndBytesAddr
xjmp L81
L80:
;
; while(1)
; {
; ////////////////////////////////////////////////////////
; //当有用户选择用水模式时
; if (cKeyRiseEvent == 1)
lds R24,_cKeyRiseEvent
cpi R24,1
breq X2
xjmp L83
X2:
; {
; //屏蔽int1、int0中断和UART中断,定时器Timer0,Timer2仍开始
; DISINT01INT()
in R24,0x3b
andi R24,191
out 0x3b,R24
in R24,0x3b
andi R24,127
out 0x3b,R24
; DISRXINT()
sbi 0xa,7
;
; //清除用水标记
; cKeyRiseEvent = 0;
clr R2
sts _cKeyRiseEvent,R2
;
; //判断出出水模式
; cKeyCode = Zlg7290_ReadKey();
xcall _Zlg7290_ReadKey
mov R22,R16
;
; //启动定时器0,等待5秒内刷卡
; start_timer0(2000);
ldi R16,2000
ldi R17,7
xcall _start_timer0
xjmp L86
L85:
;
; //若超时
; while (gTmr0OvrCount>0)
; {
; M500PcdConfig(); // Initialise the RC500 must be call in the initialisation
xcall _M500PcdConfig
; PcdReadE2(8, 4, Snr_RC500); // Read out the MFRC500 serial number and store it
ldi R24,<_Snr_RC500
ldi R25,>_Snr_RC500
std y+1,R25
std y+0,R24
ldi R18,4
ldi R16,8
ldi R17,0
xcall _PcdReadE2
; M500PcdMfOutSelect(2); // 设定MFOut管教的信号类型
ldi R16,2
xcall _M500PcdMfOutSelect
;
; statusOfIC = M500PiccRequest(PICC_REQALL, tt1); //寻卡
movw R18,R28
subi R18,200 ; offset = 56
sbci R19,255
ldi R16,82
xcall _M500PiccRequest
mov R14,R16
;
; if (statusOfIC == MI_OK)
tst R16
brne L88
; statusOfIC = M500PiccAnticoll(0,cardserialno); //取第1卡
movw R18,R28
subi R18,232 ; offset = 24
sbci R19,255
clr R16
xcall _M500PiccAnticoll
mov R14,R16
L88:
;
; if (statusOfIC == MI_OK)
tst R14
brne L90
; statusOfIC = M500PiccSelect(cardserialno,sak1);//选中卡号
movw R30,R28
subi R30,185 ; addi 71
sbci R31,255
ldd R18,z+0
ldd R19,z+1
movw R16,R28
subi R16,232 ; offset = 24
sbci R17,255
xcall _M500PiccSelect
mov R14,R16
L90:
;
; if (statusOfIC == MI_OK) //安全验证
tst R14
brne L92
; statusOfIC = M500PiccAuth(PICC_AUTHENT1A, cardserialno, 1, 4);
ldi R24,4
std y+2,R24
ldi R24,1
std y+0,R24
movw R18,R28
subi R18,232 ; offset = 24
sbci R19,255
ldi R16,96
xcall _M500PiccAuth
mov R14,R16
L92:
;
; if (statusOfIC == MI_OK)
tst R14
brne L94
; statusOfIC = M500PiccRead(4, blockdata);
movw R18,R28
subi R18,216 ; offset = 40
sbci R19,255
ldi R16,4
xcall _M500PiccRead
mov R14,R16
L94:
;
; //RC500得到IC卡号后
; if (statusOfIC == MI_OK)
tst R14
breq X3
xjmp L96
X3:
; {
; //计算IC卡余额
; leftMoney = blockdata[0];
ldd R12,y+40
clr R13
; leftMoney = leftMoney<<8+blockdata[1];
ldd R18,y+41
clr R19
subi R18,248 ; offset = 8
sbci R19,255
movw R16,R12
xcall lsl16
movw R12,R16
;
; //检查余额是否还够消费
; if (leftMoney < 50) //蜂鸣器响2次
cpi R16,50
ldi R30,0
cpc R17,R30
brsh L99
; {
; SETBIT(PORTD,6);
sbi 0x12,6
; SoftDelay();//每次循环延时0.8秒
xcall _SoftDelay
; CLRBIT(PORTD,6);
cbi 0x12,6
;
; SoftDelay();
xcall _SoftDelay
; SETBIT(PORTD,6);
sbi 0x12,6
;
; SoftDelay();
xcall _SoftDelay
; CLRBIT(PORTD,6);
cbi 0x12,6
; break;
xjmp L87
L99:
; }
;
; //扣除IC卡余额
; leftMoney -= 50;
movw R24,R12
sbiw R24,50
movw R12,R24
; blockdata[0] = (uchar)((leftMoney&0xFF00)>>8);
andi R24,0
mov R24,R25
clr R25
std y+40,R24
; blockdata[1] = leftMoney&0xFF;
movw R24,R12
andi R25,0
std y+41,R24
;
; //根据卡号、金额和时间形成完整一个消费记录
; //1.>卡号
; for (counter=0; counter<4; counter++)
clr R20
xjmp L105
L102:
movw R24,R28
adiw R24,24
mov R30,R20
clr R31
add R30,R24
adc R31,R25
ldd R2,z+0
movw R24,R28
adiw R24,4
mov R30,R20
clr R31
add R30,R24
adc R31,R25
std z+0,R2
L103:
inc R20
L105:
cpi R20,4
brlo L102
; szRecordInfoBytes[counter] = cardserialno[counter];
; //2.>金额部分
; memcpy((void *)&szRecordInfoBytes[4], (void *)utoa(tempbuf/*暂存缓冲区*/, leftMoney, 10), 4);
ldi R24,10
ldi R25,0
std y+1,R25
std y+0,R24
movw R18,R12
movw R16,R28
subi R16,190 ; offset = 66
sbci R17,255
xcall _utoa
ldi R24,4
ldi R25,0
std y+1,R25
std y+0,R24
movw R18,R16
movw R16,R28
subi R16,248 ; offset = 8
sbci R17,255
xcall _memcpy
; //3.>时间部分
; for (counter=0; counter<12; counter++)
clr R20
xjmp L110
L107:
movw R24,R28
adiw R24,28
mov R30,R20
clr R31
add R30,R24
adc R31,R25
ldd R2,z+0
movw R24,R28
adiw R24,12
mov R30,R20
clr R31
add R30,R24
adc R31,R25
std z+0,R2
L108:
inc R20
L110:
cpi R20,12
brlo L107
; szRecordInfoBytes[8+counter] = CurrTimeInfo[counter];
;
; //计算出当前消费的数据页和字节块号
; CalcNextPageAndBytesAddr(gnHistoryFlashPage, gnHistoryBytesBlock,
ldi R24,<_gnCurrentBytesBlock
ldi R25,>_gnCurrentBytesBlock
std y+3,R25
std y+2,R24
ldi R24,<_gnCurrentFlashPage
ldi R25,>_gnCurrentFlashPage
std y+1,R25
std y+0,R24
lds R18,_gnHistoryBytesBlock
lds R19,_gnHistoryBytesBlock+1
lds R16,_gnHistoryFlashPage
lds R17,_gnHistoryFlashPage+1
xcall _CalcNextPageAndBytesAddr
; &gnCurrentFlashPage, &gnCurrentBytesBlock);
;
; //先写入FLASH中,并确认已正确写入消费记录
; OpCardOk = CommitPaidSuccess(gnCurrentFlashPage, gnCurrentBytesBlock,
ldi R24,20
std y+2,R24
movw R24,R28
adiw R24,4
std y+1,R25
std y+0,R24
lds R18,_gnCurrentBytesBlock
lds R16,_gnCurrentFlashPage
lds R17,_gnCurrentFlashPage+1
xcall _CommitPaidSuccess
mov R10,R16
; szRecordInfoBytes, 20);
;
; //回写IC卡成功
; statusOfIC = M500PiccWrite(4/*IC块号*/, blockdata);
movw R18,R28
subi R18,216 ; offset = 40
sbci R19,255
ldi R16,4
xcall _M500PiccWrite
mov R14,R16
;
; //若写入则成功,则产生下一个新页和字节块的地址,否则维持历史页和字节块地址
; if (OpCardOk == TRUE && statusOfIC ==MI_OK)
mov R24,R10
cpi R24,1
brne L112
tst R16
brne L112
; {
; //写入0页,记录已消费的记录和字节信息
; WriteContextInfo(gnCurrentFlashPage, gnCurrentBytesBlock);
lds R18,_gnCurrentBytesBlock
lds R16,_gnCurrentFlashPage
lds R17,_gnCurrentFlashPage+1
xcall _WriteContextInfo
;
; //提前取出FLASH中记录的历史数据页号和字节地址,为新消费准备
; GetHistoryPageAndBytesAddr(&gnHistoryFlashPage, &gnHistoryBytesBlock);
ldi R18,<_gnHistoryBytesBlock
ldi R19,>_gnHistoryBytesBlock
ldi R16,<_gnHistoryFlashPage
ldi R17,>_gnHistoryFlashPage
xcall _GetHistoryPageAndBytesAddr
;
; //打开相应编号的电磁阀放水
; SETBIT(PORTC, cKeyCode);
ldi R16,1
mov R17,R22
xcall lsl8
in R2,0x15
or R2,R16
out 0x15,R2
; }
xjmp L113
L112:
; else //写入操作失败,则蜂鸣器响3次
; {
; SETBIT(PORTD,6);
sbi 0x12,6
; SoftDelay(); //每次循环延时0.8秒
xcall _SoftDelay
; CLRBIT(PORTD,6);
cbi 0x12,6
;
; SoftDelay();
xcall _SoftDelay
; SETBIT(PORTD,6);
sbi 0x12,6
;
; SoftDelay();
xcall _SoftDelay
; CLRBIT(PORTD,6);
cbi 0x12,6
;
; SoftDelay();
xcall _SoftDelay
; SETBIT(PORTD,6);
sbi 0x12,6
;
; SoftDelay();
xcall _SoftDelay
; CLRBIT(PORTD,6);
cbi 0x12,6
; }
L113:
; }//end of if
L96:
in R24,0x3b
ori R24,64
out 0x3b,R24
in R24,0x3b
ori R24,128
out 0x3b,R24
cbi 0xa,7
xjmp L87
L86:
lds R2,_gTmr0OvrCount
lds R3,_gTmr0OvrCount+1
tst R2
breq X4
xjmp L85
X4:
tst R3
breq X5
xjmp L85
X5:
X0:
L87:
;
; //开启int1、int0中断和UART中断
; ENINT01INT()
; ENRXINT()
;
; //规定时间内完成当前操作模式,则退出操作卡限时
; break;
; }
;
; stop_time0();
xcall _stop_time0
; }//end if while
L83:
;
; ///////////////////////////////////////////////////////
; //1.当操作员要求读取FLASH内的消费记录时,开始传送数据,
; //结束后操作员要复位重启。
; //2.当操作员校定M41T0时间时,直接写I2C器件M41T0
; if (gbRecvPCFrameCmd == 1)
lds R24,_gbRecvPCFrameCmd
cpi R24,1
brne L114
; {
; gbRecvPCFrameCmd = 0;
clr R2
sts _gbRecvPCFrameCmd,R2
;
; //读取Flash数据并上传命令
;
;
; //向M41T0写校定时间
; M41T0Data[0] = 0x12;
ldi R24,18
std y+58,R24
; M41T0_SendInfo(M41T0Data, 8);
ldi R18,8
movw R16,R28
subi R16,198 ; offset = 58
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -