?? duxiem1ka.c
字號:
zhilingma=SBUF;
if (zhilingma!=jiaozhengshizhongma)
{
// led_cyc_on();
/*-----------------------------------------------------------------------------------------------
;Step1
;通訊測試
;下傳命令:3C 04 00 60 00 00 BCC 0D
;成功返回:3C 01 01 BCC 0D
;錯誤返回:3C 01 00 BCC 0D*/
tmpResult=0xFC;
Commu_test();
//SetRes(CardStatus,1); //Result中最高位是Commu_Test成功標志,執(zhí)行此條把tmpResult的最高位置零
delay10ms(3);
if (CardStatus) //如果通訊測試正常,則執(zhí)行尋卡操作
{Search_Card(CardNo,SearMode);}
else
goto start;
delay10ms(3);
/*-----------------------------------------------------------------------------------------------
;Step2
;尋卡 void Search_Card(uchar *CardNo,uchar SearMode)
;下傳命令:3C 04 01 70 00(尋卡模式00(IDLE)或01(ALL)) 00 BCC 0D
;成功返回:3C 05 四字節(jié)卡號 00 BCC 0D
;錯誤返回:3C 01 FF(錯誤返回代碼) BCC 0D
;其中:00尋卡模式要求操作的卡在讀寫完成后要離開感應區(qū)才能再讀寫;
;01尋卡模式要求操作的卡在讀寫完成后卡片只需關閉后又可讀寫;*/
//sen(0xff);
//SetRes(CardStatus,2);//Result中第二位成功標志,執(zhí)行此條把tmpResult的第二位置零
//******************************************************
if (zhilingma==chqingkongma) //清空刷卡記錄
{
RI=0;
for (i=0;i<48;i++)
{
startkaqingkong:
tmpResult=0xFC;
Commu_test();
//SetRes(CardStatus,1); //Result中最高位是Commu_Test成功標志,執(zhí)行此條把tmpResult的最高位置零
delay10ms(3);
if (CardStatus) //如果通訊測試正常,則執(zhí)行尋卡操作
{Search_Card(CardNo,SearMode);}
else
{ sen(0xfe); goto startkaqingkong; };
delay10ms(3);
//RI=0;
//while(!RI);
//CardBlockNo=SBUF;
//RI=0;
// if ((i+1)%4!=0 || i==0)
if (i!=(i/4)*4+3)
{
CardBlockNo=i+0x0c;
if (CardStatus)
{
Psd_Verify(CardBlockKey,BlockKeyAorB,CardBlockNo,CardNo);
if (CardStatus)
{
for (j=0;j<16;j++)
CardDataBuf[j]=0x00;
delay10ms(3);
Write_Card(CardBlockNo,CardDataBuf);
//TurnOff_Card();
}
else
{ sen(0xff); sen(CardBlockNo);goto startkaqingkong; };
}
else
{ sen(0xfa); goto startkaqingkong; };
};
//delay10ms(3);
sen(CardBlockNo);
};
};
//******************************************************
//******************************************************
if (zhilingma==dukama) //讀卡指令 0x55
{
//sen(0xf9);
RI=0;
for (i=0;i<64;i++)
{
rrr2: sen(i);
Search_Card(CardNo,SearMode);
CardBlockNo=i;
if (CardStatus)
{
Psd_Verify(CardBlockKey,BlockKeyAorB,CardBlockNo,CardNo);
if (CardStatus)
{
Read_Card(CardBlockNo,CardDataBuf);
if (CardStatus)
{
for (j=0;j<16;j++)
sen(CardDataBuf[j]);
}
else
{ sen(0xfe);
TurnOff_Card();
delay10ms(3);
goto rrr2; //讀取數(shù)據(jù)失敗
};
}
else
{
sen(0xf1); //密碼校驗失敗
goto rrr2;
};
}
else
{
sen(0xf0); //尋卡失敗
TurnOff_Card();
delay10ms(3);
goto rrr2;
};
}; //for
};
}; //if (zhilingma==jiaozhengshizhongma)
//******************************************************
if (zhilingma==dukashujuma) //讀卡數(shù)據(jù)指令
{
//sen(0xf9);
RI=0;
for (i=0;i<64;i++)
{
sen(i);
if (i!=(i/4)*4+3)
{
startkashuju:
tmpResult=0xFC;
Commu_test();
//SetRes(CardStatus,1); //Result中最高位是Commu_Test成功標志,執(zhí)行此條把tmpResult的最高位置零
delay10ms(3);
if (CardStatus) //如果通訊測試正常,則執(zhí)行尋卡操作
{Search_Card(CardNo,SearMode);}
else
goto startkashuju;
delay10ms(3);
CardBlockNo=i;
if (CardStatus)
{ Psd_Verify(CardBlockKey,BlockKeyAorB,CardBlockNo,CardNo);}
else
{goto startkashuju;};
delay10ms(3);
if (CardStatus)
{
Read_Card(CardBlockNo,CardDataBuf);
if (CardStatus)
{
for (j=0;j<16;j++)
sen(CardDataBuf[j]);
}
else
{sen(0xee);goto startkashuju;};
}
else
{
sen(0xff);
};
delay10ms(3);
};
delay10ms(3);
//TurnOff_Card();
};
};
//******************************************************
if (SBUF==jiaozhengshizhongma)
{
//校正時鐘
RI=0;
//接收6個字節(jié)數(shù)據(jù),順序年、月、日、時、分、秒
// shoufa485=shou;
for (i=0;i<6;i++)
{
// time=0;
while(!RI)
{
//超時處理
//if (time>50)
// { goto xianshishizhong; };
};
shezhiriqishijian[i]=SBUF;
RI=0;
};//接收6個字節(jié)數(shù)據(jù),順序年、月、日、時、分、秒
//設置時鐘芯片 2007.07.09
i=(readrtc(0x0a)); //讀取設置寄存器A
writertc(0x0a,i&0xaf); //打開時鐘芯片
i=(readrtc(0x0a)); //讀取設置寄存器A
writertc(0x0a,i|0x20);
i=(readrtc(0x0b)); //讀取設置寄存器B
writertc(0x0b,i|0x80); //
//設置寄存器B為可以設置狀態(tài)
// i=(readrtc(0x0b)); //讀取設置寄存器B
// writertc(0x0b,i|0x86);
//寫入時鐘芯片中
writertc(0x00,shezhiriqishijian[5]); //秒
writertc(0x02,shezhiriqishijian[4]); //分
writertc(0x04,shezhiriqishijian[3]); //時
// writertc(0x06,shezhizhou); //周
writertc(0x07,shezhiriqishijian[2]); //日
writertc(0x08,shezhiriqishijian[1]); //月
writertc(0x09,shezhiriqishijian[0]); //年
//設置寄存器B為數(shù)據(jù)更新狀態(tài)
//設置時鐘芯片 2007.08.27
writertc(0x0b,i&0x7f); //
writertc(0x0b,0x02); //
//讀取時鐘芯片中并發(fā)送
//讀取日期時間
// time=0;
//while(time<20);
// xianshishizhong:
xtshijian[5]=(readrtc(0x00)); //讀取秒
xtshijian[4]=(readrtc(0x02)); //讀取分
xtshijian[3]=(readrtc(0x04)); //讀取時
xtshijian[2]=(readrtc(0x07)); //讀取日
xtshijian[1]=(readrtc(0x08)); //讀取月
xtshijian[0]=(readrtc(0x09)); //讀取年
//shoufa485=shou;
// sen(0x30);
//shoufa485=fa;
for (i=0;i<6;i++)
{sen(xtshijian[i]);};
//sen(readrtc(0x0b));
};
//校正時鐘
//********************************8
if (zhilingma==cqingkongma) //把卡0x0c清空指令
{
RI=0;
while(!RI);
CardBlockNo=SBUF;
RI=0;
Psd_Verify(CardBlockKey,BlockKeyAorB,CardBlockNo,CardNo);
if (CardStatus)
{
for (j=0;j<16;j++)
CardDataBuf[j]=0x00;
Write_Card(CardBlockNo,CardDataBuf);
};
};
//******************************************************
if (zhilingma==xieshujuma) //寫數(shù)據(jù)卡指令 02 38 02 39
{
RI=0;
CardBlockNo=0x04;
Psd_Verify(CardBlockKey,BlockKeyAorB,CardBlockNo,CardNo);
if (CardStatus)
{
for (j=0;j<16;j++)
CardDataBuf[j]=0x00;
CardDataBuf[0]=0x02;
CardDataBuf[1]=0x38;
CardDataBuf[2]=0x02;
CardDataBuf[3]=0x39;
Write_Card(CardBlockNo,CardDataBuf);
};
};
//******************************************************
if (zhilingma==qingkongma) //把卡清空指令
{
};
if (zhilingma==dukuaima) //把卡清空指令
{
RI=0;
while(!RI);
sen(i);
CardBlockNo=i;
Psd_Verify(CardBlockKey,BlockKeyAorB,CardBlockNo,CardNo);
if (CardStatus)
{
Read_Card(CardBlockNo,CardDataBuf);
if (CardStatus)
{
for (j=0;j<16;j++)
sen(CardDataBuf[j]);
}
else
{
sen(0xdd);
};
}
else
{
sen(0xde);
};
}
TurnOff_Card();
SetRes(CardStatus,6);
delay10ms(3);
display(tmpResult);
//*****************************************************
//數(shù)據(jù)區(qū):
//啟動卡:1塊 4塊
// 1塊:AA 以后全零
// 4塊:02 38 02 38 以后全零
//通行卡:1塊 4塊
// 1塊:55 以后全零
// 4塊:02 38 以后全零
//使用后 C塊 D塊 E塊 10塊
//C塊:02 38 09 02 18 54 00 10 除最后1個外全零 02
//D塊:02 38 09 02 18 55 00 10 除最后1個外全零 02
//E塊:同D塊
//10塊:同D塊
//2007.9.3 程序流程
//上電流程
//1、讀取標志,判斷是否初始化過;
//2、如果初始化過,則初始化標志置位,等待讀卡;
//3、如果沒有初始化過,等待讀卡;
//1、尋卡
//2、如果有卡則密碼驗證
//3、驗證正確后,讀1塊,判斷是啟動卡,還是通行卡
//4、如果是啟動卡,讀取4塊,驗證數(shù)據(jù)一致性,如果一致則存儲數(shù)據(jù)
//5、如果是通行卡,讀取4塊,驗證是否和啟動數(shù)據(jù)一致,如果一致并且C塊沒有數(shù)據(jù)則寫收車數(shù)據(jù);
//6、如果和啟動數(shù)據(jù)不一致,則報告錯誤;
//7、返回 尋卡
//*****************************************************
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -