📄 main.c
字号:
Status = MI_OK;
break;
case 0x51: // Clr Control Bit
Status = MI_OK;
break;
case 0x52: // Config
Status = M500PcdConfig();
#ifdef AUTODELAY
DelayRate = 0;
#endif
break;
case 0x53: // Check Write
Status = MIS_CHK_FAILED;
if (M500PiccRequest(PICC_REQALL, tt) != MI_OK)
{
if (M500PiccRequest(PICC_REQALL, tt) != MI_OK)
{
break;
}
}
if (M500PiccSelect(&SerBuffer[SERNR], &size) != MI_OK)
{
if (M500PiccRequest(PICC_REQALL, tt) != MI_OK)
{
break;
}
if (M500PiccSelect(&SerBuffer[SERNR], &size) != MI_OK)
{
break;
}
}
memcpy(card_snr,&SerBuffer[SERNR],4);
if(SerBuffer[AUTHMODE]&0X04) SerBuffer[AUTHMODE]=PICC_AUTHENT1B; // keyB
else SerBuffer[AUTHMODE]=PICC_AUTHENT1A; // keyA
//if (Status = M500PiccAuth(SerBuffer[AUTHMODE], card_snr,
// SerBuffer[ADRCHKWR]>>2, SerBuffer[ADRCHKWR]) != MI_OK)
if (Status = M500PiccAuthE2(SerBuffer[AUTHMODE], card_snr,
SerBuffer[ADRCHKWR]>>2, SerBuffer[ADRCHKWR]) != MI_OK)
{
break;
}
if (M500PiccRead(SerBuffer[ADRCHKWR], tmp) != MI_OK)
{
break;
}
if (memcmp(&SerBuffer[DATACHKWR], tmp, 16) != MI_OK)
{
Status = MIS_CHK_COMPERR;
}
else
{
Status = MIS_CHK_OK;
}
break;
case 0x54: // Set Port
P1 |= (SerBuffer[PORTBYTE]&0x0f); // set the desired port pin
P1 &= (SerBuffer[PORTBYTE]|0xf0); // clear the desired port pin
if (SerBuffer[PORTBYTE]&0x10)
LED = ON;
else
LED = OFF;
Status = MI_OK;
break;
case 0x55: // Get Port
SerBuffer[PORTBYTE] = P1&0xf;
SerBuffer[LENGTH] = 1;
Status = MI_OK;
break;
case 0x56: // Authentication2
if(SerBuffer[MODE]&0X04) SerBuffer[MODE]=PICC_AUTHENT1B; // keyB
else SerBuffer[MODE]=PICC_AUTHENT1A; // keyA
//Status = M500PiccAuth(SerBuffer[MODE], card_snr,
// SerBuffer[SECNR], SerBuffer[AUTHADD]);
Status = M500PiccAuthE2(SerBuffer[MODE], card_snr,
SerBuffer[SECNR], SerBuffer[AUTHADD]);
break;
case 0x57: // Decrement+Transfer
Status = M500PiccValue(PICC_DECREMENT, SerBuffer[ADR], &SerBuffer[VALUE], SerBuffer[ADR]);
break;
default:
Status = MI_NY_IMPLEMENTED;
break;
} // end switch (Command)
SerBuffer[STATUS] = ~Status+1;
if (cmd < 0x48 || cmd > 0x4A)
{
EnableTransferCmd = FALSE;
}
else
{
EnableTransferCmd = TRUE;
}
}
/****************************************************************************
* *
* Function: auto_baud *
* *
* Input: - *
* Output: - *
* *
* Description: *
* *
* Mi醫 die Zeitspanne zwischen Start- und Stopbit des ersten empfangenen *
* Zeichens (STX) und ermittelt daraus die Baudrate. *
* *
****************************************************************************/
void auto_baud (void)
{
//int temp;
if (AutoBaud && !RXD) // If autobaud is enable and RXD pin is low
{
TR0 = TRUE; // Start timer0
do
{
if (RXD) // When RXD pin is high
{
Capt_L = TL0;
Capt_H = TH0;
do
{
if (!RXD)
{
break;
}
} while (!TF0);
}
} while (!TF0);
TR0 = FALSE;
TF0 = FALSE;
Capt = ((uint)Capt_H << 5) | ((uint)Capt_L & 0x001F);
for (BaudRate = BAUD_CNT; BaudRate >= 0; BaudRate--)
{
if (Capt >= CmpTable[BaudRate])
{
break;
}
}
if (BaudRate < 0 || BaudRate == BAUD_CNT) // Error baud count
{
TH0 = 0;
TL0 = 0;
Capt_L = 0;
Capt_H = 0;
return;
}
TMOD = 0x21; // Timer 0, mode 1, 16-bit counter
TH1 = BaudRateTable[BaudRate];
TL1 = TH1;
TR1 = TRUE;
TH0 = 0xE0;
TL0 = 0;
TR0 = TRUE;
while (!TF0); // Wait 4.4 ms
TR0 = FALSE;
TF0 = FALSE;
ET0 = TRUE;
AutoBaud = FALSE; // Baudrate had been choose, disable Autobaud
SBUF = NAK;
while (!TI);
TI = FALSE;
RI = FALSE;
ES = TRUE;
}
}
#pragma noaregs
/****************************************************************************
* *
* Function: delay_50us *
* *
* Input: _50us *
* Output: - *
* *
* Description: *
* *
* Time delay with a resolution of 50 us. *
* *
****************************************************************************/
void delay_50us (uchar _50us)
{
RCAP2LH = RCAP2_50us;
T2LH = RCAP2_50us;
ET2 = 0; // Disable timer2 interrupt
T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
while (_50us--)
{
while (!TF2);
TF2 = FALSE;
}
TR2 = FALSE;
}
/****************************************************************************
* *
* Function: delay_1ms *
* *
* Input: _1ms *
* Output: - *
* *
* Description: *
* *
* Time delay with a resolution of 1 ms. *
* *
****************************************************************************/
void delay_1ms (uchar _1ms)
{
RCAP2LH = RCAP2_1ms;
T2LH = RCAP2_1ms;
ET2 = 0; // Disable timer2 interrupt
T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
while (_1ms--)
{
while (!TF2);
TF2 = FALSE;
}
TR2 = FALSE;
}
/****************************************************************************
* *
* Function: delay_10ms *
* *
* Input: _10ms *
* Output: - *
* *
* Description: *
* *
* Time delay with a resolution of 10 ms. *
* *
****************************************************************************/
void delay_10ms (uint _10ms)
{
RCAP2LH = RCAP2_10ms;
T2LH = RCAP2_10ms;
ET2 = 0; // Disable timer2 interrupt
T2CON = 0x04; // 16-bit auto-reload, clear TF2, start timer
while (_10ms--)
{
while (!TF2)
{
if (CmdValid || CmdReceived)
{
TR2 = FALSE;
TF2 = FALSE;
return;
}
}
TF2 = FALSE;
}
TR2 = FALSE;
}
#ifdef NOP_DELAY
/****************************************************************************
* *
* Function: delay_50us_NOP *
* *
* Input: - *
* Output: - *
* *
* Description: *
* *
* Zeitverz攇erung von 50 鎠. *
* *
****************************************************************************/
void delay_50us_NOP (void)
{
uchar i;
for(i=0; i<81; i++) _nop_();
}
#endif
/****************************************************************************
* *
* Function: delay_8us_NOP *
* *
* Input: - *
* Output: - *
* *
* Description: *
* *
* *
****************************************************************************/
void delay_8us_NOP (void)
{
uchar i;
for(i=0; i<14; i++) _nop_();
}
#pragma aregs
/****************************************************************************
* *
* Function: xtoa_h *
* *
* Input: _byte *
* Output: ASCII High-Nibble *
* *
* Description: *
* *
* Wandelt das High-Nibble des 乥ergebenen Bytes in ein ASCII-Zeichen um. *
* *
****************************************************************************/
uchar xtoa_h (uchar _byte)
{
uchar nibble = _byte >> 4;
return ((nibble > 9)? nibble + 'A' - 10 : nibble + '0');
}
/****************************************************************************
* *
* Function: xtoa_l *
* *
* Input: _byte *
* Output: ASCII Low-Nibble *
* *
* Description: *
* *
* Wandelt das Low-Nibble des 乥ergebenen Bytes in ein ASCII-Zeichen um. *
* *
****************************************************************************/
uchar xtoa_l (uchar _byte)
{
uchar nibble = _byte & 0x0F;
return ((nibble > 9)? nibble + 'A' - 10 : nibble + '0');
}
/****************************************************************************
* *
* Function: isr_timer0 *
* *
* Input: - *
* Output: - *
* *
* Description: *
* *
* *
****************************************************************************/
void isr_timer0 (void) interrupt 1 using 2
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -