📄 rfid_animalidmenu.c
字号:
else if(cButton == IO_DOWN){nextPos = XTRADATA;}
else if(cButton == IO_RIGHT){c64bIDCodetmp[5] = c64bIDCodetmp[5]|0x80;}
else if(cButton == IO_LEFT){c64bIDCodetmp[5] = c64bIDCodetmp[5]&~0x80;}
break;
case XTRADATA: // Data?
if(cButton == IO_ENTER){progFlag = 1;}
else if(cButton == IO_UP){nextPos = ANIMAL;}
else if(cButton == IO_DOWN){nextPos = COUNTRY;}
else if(cButton == IO_RIGHT){c64bIDCodetmp[6] = c64bIDCodetmp[6]|0x01;}
else if(cButton == IO_LEFT){c64bIDCodetmp[6] = c64bIDCodetmp[6]&~0x01;}
break;
case COUNTRY: // Country Label
if(cButton == IO_ENTER){progFlag = 1;}
else if(cButton == IO_UP){nextPos = XTRADATA;}
else if(cButton == IO_DOWN){nextPos = NATIONAL;}
else if(cButton == IO_RIGHT){;}//nextPos = COUNTRY1;}
else if(cButton == IO_LEFT){;}
break;
case COUNTRY1:
if(cButton == IO_ENTER){nextPos = COUNTRY;}
else if(cButton == IO_UP){fCountry[0] = (fCountry[0]&0x0F)|((fCountry[0]+16)&0xF0);}
else if(cButton == IO_DOWN){fCountry[0] = (fCountry[0]&0x0F)|((fCountry[0]-16)&0xF0);}
else if(cButton == IO_RIGHT){nextPos = COUNTRY2;}
else if(cButton == IO_LEFT){nextPos = COUNTRY;}
break;
case COUNTRY2:
if(cButton == IO_ENTER){nextPos = COUNTRY;}
else if(cButton == IO_UP){fCountry[0] = (fCountry[0]&0xF0)|((fCountry[0]+1)&0x0F);}
else if(cButton == IO_DOWN){fCountry[0] = (fCountry[0]&0xF0)|((fCountry[0]-1)&0x0F);}
else if(cButton == IO_RIGHT){nextPos = COUNTRY3;}
else if(cButton == IO_LEFT){nextPos = COUNTRY1;}
break;
case COUNTRY3:
if(cButton == IO_ENTER){nextPos = COUNTRY;}
else if(cButton == IO_UP){fCountry[1] = (fCountry[1]&0x0F)|((fCountry[1]+16)&0xF0);}
else if(cButton == IO_DOWN){fCountry[1] = (fCountry[1]&0x0F)|((fCountry[1]-16)&0xF0);}
else if(cButton == IO_RIGHT){nextPos = COUNTRY4;}
else if(cButton == IO_LEFT){nextPos = COUNTRY2;}
break;
case COUNTRY4:
if(cButton == IO_ENTER){nextPos = COUNTRY;}
else if(cButton == IO_UP){fCountry[1] = (fCountry[1]&0xF0)|((fCountry[1]+1)&0x0F);}
else if(cButton == IO_DOWN){fCountry[1] = (fCountry[1]&0xF0)|((fCountry[1]-1)&0x0F);}
else if(cButton == IO_RIGHT){}
else if(cButton == IO_LEFT){nextPos = COUNTRY3;}
break;
case NATIONAL: // National Label
if(cButton == IO_ENTER){progFlag = 1;}
else if(cButton == IO_UP){nextPos = COUNTRY;}
else if(cButton == IO_DOWN && ((c64bIDCodetmp[6]&0x01) == 0x01)){nextPos = TRAILER;}
else if(cButton == IO_RIGHT){nextPos = NATIONAL1;}
else if(cButton == IO_LEFT){;}
break;
case NATIONAL1:
if(cButton == IO_ENTER){nextPos = NATIONAL;}
else if(cButton == IO_UP){fNational[0] = (fNational[0]&0x0F)|((fNational[0]+16)&0xF0);}
else if(cButton == IO_DOWN){fNational[0] = (fNational[0]&0x0F)|((fNational[0]-16)&0xF0);}
else if(cButton == IO_RIGHT){nextPos = NATIONAL2;}
else if(cButton == IO_LEFT){nextPos = NATIONAL;}
break;
case NATIONAL2:
if(cButton == IO_ENTER){nextPos = NATIONAL;}
else if(cButton == IO_UP){fNational[0] = (fNational[0]&0xF0)|((fNational[0]+1)&0x0F);}
else if(cButton == IO_DOWN){fNational[0] = (fNational[0]&0xF0)|((fNational[0]-1)&0x0F);}
else if(cButton == IO_RIGHT){nextPos = NATIONAL3;}
else if(cButton == IO_LEFT){nextPos = NATIONAL1;}
break;
case NATIONAL3:
if(cButton == IO_ENTER){nextPos = NATIONAL;}
else if(cButton == IO_UP){fNational[1] = (fNational[1]&0x0F)|((fNational[1]+16)&0xF0);}
else if(cButton == IO_DOWN){fNational[1] = (fNational[1]&0x0F)|((fNational[1]-16)&0xF0);}
else if(cButton == IO_RIGHT){nextPos = NATIONAL4;}
else if(cButton == IO_LEFT){nextPos = NATIONAL2;}
break;
case NATIONAL4:
if(cButton == IO_ENTER){nextPos = NATIONAL;}
else if(cButton == IO_UP){fNational[1] = (fNational[1]&0xF0)|((fNational[1]+1)&0x0F);}
else if(cButton == IO_DOWN){fNational[1] = (fNational[1]&0xF0)|((fNational[1]-1)&0x0F);}
else if(cButton == IO_RIGHT){nextPos = NATIONAL5;}
else if(cButton == IO_LEFT){nextPos = NATIONAL3;}
break;
case NATIONAL5:
if(cButton == IO_ENTER){nextPos = NATIONAL;}
else if(cButton == IO_UP){fNational[2] = (fNational[2]&0x0F)|((fNational[2]+16)&0xF0);}
else if(cButton == IO_DOWN){fNational[2] = (fNational[2]&0x0F)|((fNational[2]-16)&0xF0);}
else if(cButton == IO_RIGHT){nextPos = NATIONAL6;}
else if(cButton == IO_LEFT){nextPos = NATIONAL4;}
break;
case NATIONAL6:
if(cButton == IO_ENTER){nextPos = NATIONAL;}
else if(cButton == IO_UP){fNational[2] = (fNational[2]&0xF0)|((fNational[2]+1)&0x0F);}
else if(cButton == IO_DOWN){fNational[2] = (fNational[2]&0xF0)|((fNational[2]-1)&0x0F);}
else if(cButton == IO_RIGHT){nextPos = NATIONAL7;}
else if(cButton == IO_LEFT){nextPos = NATIONAL5;}
break;
case NATIONAL7:
if(cButton == IO_ENTER){nextPos = NATIONAL;}
else if(cButton == IO_UP){fNational[3] = (fNational[3]&0x0F)|((fNational[3]+16)&0xF0);}
else if(cButton == IO_DOWN){fNational[3] = (fNational[3]&0x0F)|((fNational[3]-16)&0xF0);}
else if(cButton == IO_RIGHT){nextPos = NATIONAL8;}
else if(cButton == IO_LEFT){nextPos = NATIONAL6;}
break;
case NATIONAL8:
if(cButton == IO_ENTER){nextPos = NATIONAL;}
else if(cButton == IO_UP){fNational[3] = (fNational[3]&0xF0)|((fNational[3]+1)&0x0F);}
else if(cButton == IO_DOWN){fNational[3] = (fNational[3]&0xF0)|((fNational[3]-1)&0x0F);}
else if(cButton == IO_RIGHT){nextPos = NATIONAL9;}
else if(cButton == IO_LEFT){nextPos = NATIONAL7;}
break;
case NATIONAL9:
if(cButton == IO_ENTER){nextPos = NATIONAL;}
else if(cButton == IO_UP){fNational[4] = (fNational[4]&0x0F)|((fNational[4]+16)&0xF0);}
else if(cButton == IO_DOWN){fNational[4] = (fNational[4]&0x0F)|((fNational[4]-16)&0xF0);}
else if(cButton == IO_RIGHT){nextPos = NATIONAL10;}
else if(cButton == IO_LEFT){nextPos = NATIONAL8;}
break;
case NATIONAL10:
if(cButton == IO_ENTER){nextPos = NATIONAL;}
else if(cButton == IO_UP){fNational[4] = (fNational[4]&0xF0)|((fNational[4]+1)&0x0F);}
else if(cButton == IO_DOWN){fNational[4] = (fNational[4]&0xF0)|((fNational[4]-1)&0x0F);}
else if(cButton == IO_RIGHT){;}
else if(cButton == IO_LEFT){nextPos = NATIONAL9;}
break;
case TRAILER: // TRAILER Label
if(cButton == IO_ENTER){progFlag = 1;}
else if(cButton == IO_UP){nextPos = NATIONAL;}
else if(cButton == IO_DOWN){;}
else if(cButton == IO_RIGHT){nextPos = TRAILER1;}
else if(cButton == IO_LEFT){;}
break;
case TRAILER1:
if(cButton == IO_ENTER){nextPos = TRAILER;}
else if(cButton == IO_UP){fTrailer[0] = (fTrailer[0]&0x0F)|((fTrailer[0]+16)&0xF0);}
else if(cButton == IO_DOWN){fTrailer[0] = (fTrailer[0]&0x0F)|((fTrailer[0]-16)&0xF0);}
else if(cButton == IO_RIGHT){nextPos = TRAILER2;}
else if(cButton == IO_LEFT){nextPos = TRAILER;}
break;
case TRAILER2:
if(cButton == IO_ENTER){nextPos = TRAILER;}
else if(cButton == IO_UP){fTrailer[0] = (fTrailer[0]&0xF0)|((fTrailer[0]+1)&0x0F);}
else if(cButton == IO_DOWN){fTrailer[0] = (fTrailer[0]&0xF0)|((fTrailer[0]-1)&0x0F);}
else if(cButton == IO_RIGHT){nextPos = TRAILER3;}
else if(cButton == IO_LEFT){nextPos = TRAILER1;}
break;
case TRAILER3:
if(cButton == IO_ENTER){nextPos = TRAILER;}
else if(cButton == IO_UP){fTrailer[1] = (fTrailer[1]&0x0F)|((fTrailer[1]+16)&0xF0);}
else if(cButton == IO_DOWN){fTrailer[1] = (fTrailer[1]&0x0F)|((fTrailer[1]-16)&0xF0);}
else if(cButton == IO_RIGHT){nextPos = TRAILER4;}
else if(cButton == IO_LEFT){nextPos = TRAILER2;}
break;
case TRAILER4:
if(cButton == IO_ENTER){nextPos = TRAILER;}
else if(cButton == IO_UP){fTrailer[1] = (fTrailer[1]&0xF0)|((fTrailer[1]+1)&0x0F);}
else if(cButton == IO_DOWN){fTrailer[1] = (fTrailer[1]&0xF0)|((fTrailer[1]-1)&0x0F);}
else if(cButton == IO_RIGHT){nextPos = TRAILER5;}
else if(cButton == IO_LEFT){nextPos = TRAILER3;}
break;
case TRAILER5:
if(cButton == IO_ENTER){nextPos = TRAILER;}
else if(cButton == IO_UP){fTrailer[2] = (fTrailer[2]&0x0F)|((fTrailer[2]+16)&0xF0);}
else if(cButton == IO_DOWN){fTrailer[2] = (fTrailer[2]&0x0F)|((fTrailer[2]-16)&0xF0);}
else if(cButton == IO_RIGHT){nextPos = TRAILER6;}
else if(cButton == IO_LEFT){nextPos = TRAILER4;}
break;
case TRAILER6:
if(cButton == IO_ENTER){nextPos = TRAILER;}
else if(cButton == IO_UP){fTrailer[2] = (fTrailer[2]&0xF0)|((fTrailer[2]+1)&0x0F);}
else if(cButton == IO_DOWN){fTrailer[2] = (fTrailer[2]&0xF0)|((fTrailer[2]-1)&0x0F);}
else if(cButton == IO_RIGHT){;}
else if(cButton == IO_LEFT){nextPos = TRAILER5;}
break;
default:
break;
}
if(cButton>0 && cButton<6){uio_Release();}
upDate = 0;
c64bIDCodetmp[7] = fCountry[0]<<6;
c64bIDCodetmp[7] = c64bIDCodetmp[7]|(fCountry[1]>>2);
c64bIDCodetmp[8] = (c64bIDCodetmp[8]&0x3F) | (fCountry[1]<<6);
c64bIDCodetmp[8] = (c64bIDCodetmp[8]&0xC0)|(fNational[0]&0x3F);
for(j=1; j<5; j++){c64bIDCodetmp[(unsigned char)(8+j)] = fNational[j];}
for(j=0; j<3; j++){c64bIDCodetmp[j] = fTrailer[j];}
CRCval = 0x0000;
for(i=0; i<8; i++)
{
// CRCval = CRC_CCITT16(CRCval, c64bIDCodetmp[i], 0x1021);
CRCval = CRC_CCITT16_Reverse(CRCval, c64bIDCodetmp[12-i], 0x8408);
}
c64bIDCodetmp[3] = CRCval>>8;
c64bIDCodetmp[4] = CRCval&0x00FF;
if(progFlag == 1)
{
ioActive = 0;
if(Target_Reader == 70)
{
for(j=0; j<13; j++)
{
tmpData = c64bIDCodetmp[12-j];
tmpData1 = 0;
for(i=0; i<8; i++)
{
if(tmpData & 0x01)
{
tmpData1 = tmpData1<<1;
tmpData1 = tmpData1|0x01;
}
else{tmpData1 = tmpData1<<1;}
tmpData = tmpData >> 1;
}
c64bIDCode[j] = tmpData1;
}
// tmpBlockDat1[4]={0x00,0x20,0x10,0x08};
// tmpBlockDat2[4]={0x04,0x02,0x01,0x00};
// tmpBlockDat3[4]={0x80,0x40,0x20,0x10};
// tmpBlockDat4[4]={0x08,0x04,0x02,0x01};
tmpBlockDat1[0] = 0x00;
tmpBlockDat1[1] = 0x20|(c64bIDCode[0]>>3);
tmpBlockDat1[2] = 0x10|((c64bIDCode[0]<<5)|(c64bIDCode[1]>>4));
tmpBlockDat1[3] = 0x08|((c64bIDCode[1]<<4)|(c64bIDCode[2]>>5));
tmpBlockDat2[0] = 0x04|((c64bIDCode[2]<<3)|(c64bIDCode[3]>>6));
tmpBlockDat2[1] = 0x02|((c64bIDCode[3]<<2)|(c64bIDCode[4]>>7));
tmpBlockDat2[2] = 0x01|(c64bIDCode[4]<<1);
tmpBlockDat2[3] = 0x00|c64bIDCode[5];
tmpBlockDat3[0] = 0x80|(c64bIDCode[6]>>1);
tmpBlockDat3[1] = 0x40|((c64bIDCode[6]<<7)|(c64bIDCode[7]>>2));
tmpBlockDat3[2] = 0x20|((c64bIDCode[7]<<6)|(c64bIDCode[8]>>3));
tmpBlockDat3[3] = 0x10|((c64bIDCode[8]<<5)|(c64bIDCode[9]>>4));
tmpBlockDat4[0] = 0x08|((c64bIDCode[9]<<4)|(c64bIDCode[10]>>5));
tmpBlockDat4[1] = 0x04|((c64bIDCode[10]<<3)|(c64bIDCode[11]>>6));
tmpBlockDat4[2] = 0x02|((c64bIDCode[11]<<2)|(c64bIDCode[12]>>7));
tmpBlockDat4[3] = 0x01|(c64bIDCode[12]<<1);
if(Target_Tag == 57 || Target_Tag == 67 || Target_Tag == 77)
{
tmpBlockDat0[0] = 0x60;
tmpBlockDat0[1] = 0x3F;
tmpBlockDat0[2] = 0x80;
tmpBlockDat0[3] = 0x80;
x5567_WriteBlock(Target_Reader, &tmpBlockDat0[0], 0, 0);
Timer_delay_us(10000);
x5567_WriteBlock(Target_Reader, &tmpBlockDat1[0], 1, 0);
Timer_delay_us(10000);
x5567_WriteBlock(Target_Reader, &tmpBlockDat2[0], 2, 0);
Timer_delay_us(10000);
x5567_WriteBlock(Target_Reader, &tmpBlockDat3[0], 3, 0);
Timer_delay_us(10000);
x5567_WriteBlock(Target_Reader, &tmpBlockDat4[0], 4, 0);
Timer_delay_us(10000);
x5567_Reset(Target_Reader); // Send Reset Cmd
}
else if(Target_Tag == 70)
{
tmpBlockDat0[0] = 0x60;
tmpBlockDat0[1] = 0x3F;
tmpBlockDat0[2] = 0x80;
tmpBlockDat0[3] = 0x82;
x5567_WriteBlock(Target_Reader, &tmpBlockDat0[0], 0, 0);
Timer_delay_us(10000);
x5567_WriteBlock(Target_Reader, &tmpBlockDat1[0], 1, 0);
Timer_delay_us(10000);
x5567_WriteBlock(Target_Reader, &tmpBlockDat2[0], 2, 0);
Timer_delay_us(10000);
x5567_WriteBlock(Target_Reader, &tmpBlockDat3[0], 3, 0);
Timer_delay_us(10000);
x5567_WriteBlock(Target_Reader, &tmpBlockDat4[0], 4, 0);
Timer_delay_us(10000);
x5567_Reset(Target_Reader); // Send Reset Cmd
}
snd_Play(BEEPFREQ1,BEEPFREQ0,BEEPTIME); // return Audio feedback
message_1sDisplay(PSTR("Write Attempted"));
}
ioActive = 1;
progFlag = 0;
}
}
uio_Release();
for(i=0; i<13; i++){eeprom_write_byte(&(c64bAnimalIDCode[i]),c64bIDCodetmp[i]);}
}
// *******************************************************************************
// Menu that Demonstrates Reading Animal ID
// ******************************************************************************/
void animalID_ReadAll(unsigned char Target_Tag, unsigned char Target_Reader)
{
unsigned char i, j, rError = 1, firstTime = 1;
unsigned char *cDatPtr;
unsigned char c64bIDCode[13]={0};
unsigned char c64bIDCodetmp[13]={0};
unsigned char *c64bIDCodePtr;
unsigned char *choldDatPtr;
unsigned char sBlockDat[12]={0};
unsigned char *sBlockDatPtr;
unsigned char tmpData, tmpData1, end;
unsigned long int test;
unsigned int CRCval;
upDate = 0;
uio_Release(); // Delay until next I/O interval passes (debounce)
while(cButton != IO_F1 && cButton != IO_F2 && cButton != IO_F3 && cButton != IO_F4)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -