/////////////////////////////////////////////////////////////////
// //
// 人员位置监测系统--标识卡检验仪 //
// //
// 2007年4月1日 //
// //
// //
// //
/////////////////////////////////////////////////////////////////
// //
// 文件名:RF_TEST.C //
// 版本号:Ver1.0 //
// 时 间: 2007年4月1日 //
// //
/////////////////////////////////////////////////////////////////
// //
// 通讯协议 //
// baud = 9600bps //
// dc 读头号 58h //
// dc 读头号 进出标志 卡号(2byte) 进出标志 卡号(2byte) ...SUM //
// //
// 卡号(包括标识卡状态): 共3个字节,最高字节的最高两位为标识卡//
// 进出状态位,最高两位为00 //
// //
/////////////////////////////////////////////////////////////////
//
#include "rf_test.h"
/////////////////////////////////////////////////////////////////
//
uint idata reset _at_ 0xce;
uchar idata cSid;
uchar idata cT0Delay;
uint idata iT0Delay1s;
uchar idata cTxCount;
uchar idata cReCount;
uchar idata cReSum;
uchar idata cReLength;
uchar idata cReBuf[24+8];
//= {0xDC,0x11,0x01,0x55,0x00,0x20,0x48,0x00,0x1F,0xD0,0x00,0x1F,0xDE,0x00,0x1F,0xAC,0x62};
// 实验数据
uchar idata cRFCount, idata cRFCountOld;
uchar idata cRFNum[10][3] _at_ 0x80;
union longdata lCardNum;
uchar idata cDispUnit[9] ;
uchar idata cDispWord[8][2] ;
uchar idata cGetData[3] = {0xdc, 0x01, 0x58}; // 访问读头,读取标识卡数据
/////////////////////////////////////////////////////////////////
// 标志位定义
bit bTxEnd;
bit bReStart, bReEnd, bReError, bReOver;
bit bT0Delay, bT0Delay1s, bT0Delay2s;
bit bAlarm;
/////////////////////////////////////////////////////////////////
//
void StartT0();
void AlarmPro(uchar tt);
/////////////////////////////////////////////////////////////////
// exint0 0x0003
void eXint0_Routine() interrupt 0
{
EX0 = 0;
_nop_();
}
/////////////////////////////////////////////////////////////////
// T0中断处理 0x000b
void Time0_Routine() interrupt 1 using 2
{
TH0 = 0x94; // 延时30ms
if(!cT0Delay--)
{
bT0Delay = 1;
}
if(!iT0Delay1s--)
{
bT0Delay1s = 1;
}
_nop_();
}
/////////////////////////////////////////////////////////////////
// exint1 0x0013
void eXint_1() interrupt 2
{
EX1 = 0;
_nop_();
}
/////////////////////////////////////////////////////////////////
// time1 0x001b
void Time_1() interrupt 3
{
ET1 = 0;
}
/////////////////////////////////////////////////////////////////
// sio 0x0023
// 传输接口与井下分站之间
void UART_Routine() interrupt 4 using 3
{
if(RI)
{
RI = 0;
if((cReCount==0) && (SBUF==START)) // 是报头
{
bReStart = 1; // 置报头标志
bReEnd = 0; // 清除接收完成标志
bReError = 0;
cReSum = SBUF; // 校验和
cReBuf[cReCount++] = START;
}
else if((cReCount==0) && (SBUF!=START)) // 不是报头-->返回
{
bReStart = 0; // 清除报头标志
bReEnd = 0; // 清除接收完成标志
bReError = 1;
return;
}
else if(bReStart)
{
if(cReCount==1)
{ // 接收的为报文长度
cReLength = SBUF;
cReSum += SBUF; // 校验和
if(cReLength > (MAX_LEN))
{ // 接收数据长度超出,清除所有标志,退出
bReStart = 0;
bReOver = 1; // 置接收数据溢出标志和完成标志
bReEnd = 1; // 由主程序判别重发且显示标识卡数量太多
cReCount = 0; // 同一次识别卡的数量不得大于8张卡
return;
}
else{
cReBuf[cReCount++] = cReLength ; // cReBuf缓冲区第一个字节为报文长度
//cT0Delay = cReLength / 2; // 有效的报文长度字节,设置延时,启动定时器T0
//StartT0();
}
}//if(cReCount==1)
// 不是报文长度单元,正常接收
else if(cReCount < cReLength)
{
cReBuf[cReCount++] = SBUF ;
cReSum += SBUF ;
if(cReCount == cReLength) // 判断是否为最后一个字节
{
uchar temp;
temp = cReBuf[cReCount-1]*2;
if(cReSum == temp) //(SBUF1<<1))
{
bReEnd = 1;
bReStart = 0;
cReCount = 0;
}else
{
bReError = 1;
bReEnd = 0;
bReStart = 0;
cReCount = 0;
}
}
}
}
}
////////////////////////////////////
// 发送
if(TI)
{
TI = 0;
if(cTxCount < 3)
{
SBUF = cGetData[cTxCount++];
}
else{
cTxCount = 0;
bTxEnd = 1;
EN485 = 0;
}
}
}
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
//
void AlarmPro(uchar tt)
{
ALARM = 1; // 声音报警
Delay50ms(tt);
ALARM = 0;
}
/////////////////////////////////////////////////////////////////
//
void StartT0()
{
bT0Delay = 0;
TH0 = 0x94;
TL0 = 0x00;
TR0 = 1;
}
/////////////////////////////////////////////////////////////////
// CPU初始化
void CPUInit()
{
uchar i;
uchar idata *prt;
IP = 0X00;
IPH = 0X00;
AUXR = 0X00;
//
// 端口设置
// I/O工作类型定义:
// PxM0 PxM1 I/O模式
// 0 0 准双向(传统8051 I/O模式)
// 0 1 推挽输出,(强上拉可达20mA,要加限流电阻)
// 1 0 仅为输入(高阻)
// 1 1 开漏
// (注:PxM0,PxM1中的x为P0,P1,P2,P3)
//
// P1.2-P1.7为输入模式,P1.0,P1.1为开漏输出模式. 复位默认输入高阻模式
// P1 7 6 5 4 3 2 1 0 HEX RESET
// P1M1 0 0 0 0 0 0 1 1 0x03 0x00
// P1M0 1 1 1 1 1 1 1 1 0xff 0xff
//
// P2.0-P2.4为准双向模式.P2.5-P2.7为开漏输出模式。(显示芯片端口为5V弱上拉电阻)
// P2 7 6 5 4 3 2 1 0 HEX RESE
// P2M1 1 1 1 0 0 0 0 0 0xe0 0x00
// P2M0 1 1 1 0 0 0 0 0 0xe0 0xff
//
// P3.0-P3.6为准双向模式.P3.7为推挽输出模式.
// P3 7 6 5 4 3 2 1 0 HEX RESE
// P3M1 1 0 0 0 0 0 0 0 0x80 0x00
// P3M0 0 0 0 0 0 0 0 0 0x00 0xff
//
P1M1 = 0x10;
P1M0 = 0x00;
P3M1 = 0x04;
P3M0 = 0x00;
WDT_CONTR = 0x00;
PCON = 0x00;
TMOD = 0x21;
SCON = 0x50;
TR1 = 0;
TH1 = TL1 = 0xfd; // 9600bps
TR1 = 1;
ES = 1;
ET0 = 1;
prt = &(cRFNum[0]);
for(i=0; i<30; i++)
{
*prt++ = 0x00;
}
bTxEnd = 0;
bReStart = bReEnd = bReError = bReOver = 0;
bT0Delay = bT0Delay1s = bT0Delay2s = 0;