📄 epc.c
字号:
pack_and_send();
break;
case 0x0e: //选择天线
// i=detect_antenna();
temp=combuf[3];
if(temp==0)
sel_txian0=1; //??? 选择天线1
else
sel_txian0=0;
sel_txian1 = (~sel_txian0); //选择天线2
sendbuf[0]=0xf0;
sendbuf[1]=0x02;
sendbuf[2]=0x0e;
pack_and_send();
break;
case 0x12: //设定参考电压 供现场测试使用
temp=combuf[3];
flash_addr=1700+temp*5;
if(flash_addr>3000) flash_addr=3000;
eeprom_buf[0]=flash_addr%256;
eeprom_buf[1]=flash_addr/256;
iic_block_write(cur_Ref_Volt,2);
SFRPAGE = 0x01;
DAC1L=flash_addr%256;
DAC1H=flash_addr/256;
SFRPAGE = 0x00;
sendflag=1;
sendcount=1;
receiveflag=0;
sendbuf[0]=0xf0;
sendbuf[1]=0x03;
sendbuf[2]=0x12;
sendbuf[3]=combuf[3];
sendbuf[4]=0;
pack_and_send();
break;
case 0x13: //返回参考电压值
sendflag=1;
sendcount=1;
iic_eeprom_read_adress(cur_Ref_Volt,2);
receiveflag=0;
sendbuf[0]=0xf0;
sendbuf[1]=0x03;
sendbuf[2]=0x13;
i=common_buf[0];
flash_addr=common_buf[1];
flash_addr=flash_addr<<8;
flash_addr+=i;
flash_addr=(flash_addr-1698)/5;
sendbuf[3]=flash_addr;
sendbuf[4]=0;
pack_and_send();
break;
case 0x20: //设定rfs1820配置参数
temp=0;
for(i=0;i<8;i++)
{
eeprom_buf[i]=combuf[3+i];
temp+=eeprom_buf[i];
}
eeprom_buf[8]=(~temp)+1;
iic_block_write(config_1820,9);
delay(100);
iic_eeprom_read_adress(config_1820,9);
temp=0;
is_ok=true;
for(i=0;i<8;i++)
{
if(common_buf[i] != combuf[3+i])
{
is_ok=false;
break;
}
else
temp += common_buf[i];
}
if(is_ok==true)
{
temp = (~temp) + 1;
if(temp != common_buf[8])
is_ok=false;
}
if(is_ok==true)
{
sendbuf[0]=0xf0;
sendbuf[1]=0x02;
}
else
{
sendbuf[0]=0xf4;
sendbuf[1]=0x03;
sendbuf[3]=error_eeprom;
}
sendbuf[2]=0x20;
pack_and_send();
break;
case 0x21: //读rfs1820配置参数
read_config();
for(i=0;i<8;i++)
sendbuf[i+3]=config_buf[i];
sendbuf[0]=0xf0;
sendbuf[1]=0x0a;
sendbuf[2]=0x21;
pack_and_send();
break;
case 0x40: //写厂商授权码
temp=0;
for(i=0;i<4;i++)
{
eeprom_buf[i]=combuf[3+i];
temp +=eeprom_buf[i];
}
eeprom_buf[4]=(~temp)+1;
iic_block_write(mac_code,5);
delay(100);
iic_eeprom_read_adress(mac_code,5);
temp=0;
is_ok=true;
for(i=0;i<4;i++)
{
if(common_buf[i] != combuf[3+i])
{
is_ok=false;
break;
}
else
temp += common_buf[i];
}
if(is_ok==true)
{
temp = (~temp)+1;
if(temp != common_buf[4])
is_ok=false;
}
if(is_ok==true)
{
sendbuf[0]=0xf0;
sendbuf[1]=0x02;
}
else
{
sendbuf[0]=0xf4;
sendbuf[1]=0x03;
sendbuf[3]=error_eeprom;
}
sendbuf[2]=0x40;
pack_and_send();
break;
case 0x41: //读厂商授权码
iic_eeprom_read_adress(mac_code,5);
temp=0;
for(i=0;i<4;i++)
temp += common_buf[i];
temp = (~temp) + 1;
if(temp == common_buf[4])
{
sendbuf[0]=0xf0;
sendbuf[1]=0x06;
for(i=0;i<4;i++)
sendbuf[i+3]=common_buf[i];
}
else
{
sendbuf[0]=0xf4;
sendbuf[1]=0x03;
sendbuf[3]=error_mac_code;
}
sendbuf[2]=0x41;
pack_and_send();
break;
case 0x42: //写用户授权码
temp=0;
for(i=0;i<8;i++)
{
eeprom_buf[i]=combuf[3+i];
temp +=eeprom_buf[i];
}
eeprom_buf[8]=(~temp)+1;
iic_block_write(user_code,9);
delay(100);
iic_eeprom_read_adress(user_code,9);
temp=0;
is_ok=true;
for(i=0;i<8;i++)
{
if(common_buf[i] != combuf[3+i])
{
is_ok=false;
break;
}
else
temp += common_buf[i];
}
if(is_ok==true)
{
temp = (~temp)+1;
if(temp != common_buf[8])
is_ok=false;
}
if(is_ok==true)
{
sendbuf[0]=0xf0;
sendbuf[1]=0x02;
}
else
{
sendbuf[0]=0xf4;
sendbuf[1]=0x03;
sendbuf[3]=error_eeprom;
}
sendbuf[2]=0x42;
pack_and_send();
break;
case 0x43: //读用户授权码
iic_eeprom_read_adress(user_code,9);
temp=0;
for(i=0;i<8;i++)
temp += common_buf[i];
temp = (~temp) + 1;
if(temp == common_buf[8])
{
sendbuf[0]=0xf0;
sendbuf[1]=0x0a;
for(i=0;i<8;i++)
sendbuf[i+3]=common_buf[i];
}
else
{
sendbuf[0]=0xf4;
sendbuf[1]=0x03;
sendbuf[3]=error_uac_code;
}
sendbuf[2]=0x43;
pack_and_send();
break;
case 0x44: //授权标签
temp=write_authorization();
if(temp==error_ok)
{
sendbuf[0]=0xf0;
sendbuf[1]=0x02;
}
else
{
sendbuf[0]=0xf4;
sendbuf[1]=0x03;
sendbuf[3]=temp;
}
sendbuf[2]=0x44;
pack_and_send();
break;
case 0x45: //检验标签是否授权
temp=check_authorization();
if(temp==error_ok)
{
sendbuf[0]=0xf0;
sendbuf[1]=0x02;
}
else
{
sendbuf[0]=0xf4;
sendbuf[1]=0x03;
sendbuf[3]=temp;
}
sendbuf[2]=0x45;
pack_and_send();
break;
case 0x80: //开始下载FPGA数据包
count_addr=0;
for(i=0; i<64; i++)
{
flash_erase(1, 0x8000 + i*0x200);
delay(100);
}
for(i=0;i<64;i++)
{
flash_erase(2, 0x8000 + i*0x200);
delay(100);
}
for(i=0;i<9;i++)
{
flash_erase(3, 0x8000 + i*0x200);
delay(100);
}
sendbuf[0]=0xf0;
sendbuf[1]=0x02;
sendbuf[2]=0x80;
pack_and_send();
break;
case 0x81:
for(i=0;i<64;i++)
flashwritebuf[i] = combuf[i+3];
if(count_addr<512)
{
temp=1;
flash_addr=count_addr*64+0x8000;
}
else if(count_addr<1024)
{
temp=2;
flash_addr=count_addr*64;
}
else
{
temp=3;
flash_addr=(count_addr-512)*64;
}
flash_writenbyte(temp,flash_addr,64);
delay(100);
flash_readnbyte(temp, flash_addr, 64);
delay(10);
temp = true;
for(i=0;i<64;i++)
{
if(flashwritebuf[i]!=flashreadbuf[i])
{
temp=false;
break;
}
}
if(temp==true)
{
count_addr++;
sendbuf[0]=0xf0;
sendbuf[1]=0x02;
}
else
{
sendbuf[0]=0xf4;
sendbuf[1]=0x03;
sendbuf[3]=error_eeprom;
}
sendbuf[2]=0x81;
pack_and_send();
break;
case 0x82:
sendbuf[0]=0xf0;
sendbuf[1]=0x02;
sendbuf[2]=0x82;
pack_and_send();
break;
case 0x83: //开始升级MCU软件
count_addr=0;
for(i=0;i<52;i++)
{
flash_erase(3, 0x9200 + i*0x200);
delay(100);
}
//flashwritebuf[0]=combuf[3];
//flashwritebuf[1]=combuf[4];
//flash_writenbyte(0,0x6000,2);
sendbuf[0]=0xf0;
sendbuf[1]=0x02;
sendbuf[2]=0x83;
pack_and_send();
break;
case 0x84:
for(i=0;i<64;i++)
flashwritebuf[i]=combuf[i+3];
if(count_addr<416)
{
flash_addr=count_addr*64+0x9200;
flash_writenbyte(3,flash_addr,64);
delay(100);
flash_readnbyte(3,flash_addr,64);
delay(10);
temp=true;
for(i=0;i<64;i++)
{
if(flashwritebuf[i] != flashreadbuf[i])
{
temp=false;
break;
}
}
}
else
temp=false;
if(temp==true)
{
count_addr++;
sendbuf[0]=0xf0;
sendbuf[1]=0x02;
}
else
{
sendbuf[0]=0xf4;
sendbuf[1]=0x03;
sendbuf[3]=error_eeprom;
}
sendbuf[2]=0x84;
pack_and_send();
break;
case 0x85: //收到下载MCU程序结束包
flashwritebuf[0]=0xaa;
flashwritebuf[1]=0x55;
flash_writenbyte(0,0x6002,2);
sendbuf[0]=0xf0;
sendbuf[1]=0x02;
sendbuf[2]=0x85;
pack_and_send();
down_ok=1;
break;
case 0xf0: //写一个数据字
if(antenna_is_ok())
{
amplifier_on(); //开功放
for(i=0;i<4;i++)
tagwritebuf[i]=combuf[4+i];
temp=write_data_process(combuf[3]);
amplifier_off();
}
else
temp=error_no_antenna;
if(temp==error_ok)
{
sendbuf[0]=0xf0;
sendbuf[1]=0x02;
}
else
{
ok_300ms=1; //跳频
sendbuf[0]=0xf4;
sendbuf[1]=0x03;
sendbuf[3]=temp;
}
sendbuf[2]=0xf0;
pack_and_send();
break;
case 0xf1: //读一个数据字
if(antenna_is_ok())
{
amplifier_on(); //开功放
data_get = 0;
temp=read_data_process(combuf[3], 1);
amplifier_off();
}
else
temp=error_no_antenna;
if(temp==error_ok)
{
sendbuf[0]=0xf0;
sendbuf[1]=0x06;
for(i=0;i<4;i++)
sendbuf[6-i]=data_code[i];
}
else
{
sendbuf[0]=0xf4;
sendbuf[1]=0x03;
sendbuf[3]=temp;
ok_300ms=1; //跳频
}
sendbuf[2]=0xf1;
pack_and_send();
break;
case 0xf3: //读保护
if(antenna_is_ok())
{
amplifier_on(); //开功
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -