📄 samcard.c
字号:
* *
* Last changed by: *
* Date: *
* *
* Functional Description: Cuts off the connection to the CPU card,*
* and disfrees the Card *
************************************************************************/
void _SamCardClose(void)
{
/* byte cc,i;
PUB_Card_Asy[PUB_Card_ICNO] = 0;
cc = 0;
for (i=0;i<6;i++)
cc = cc + PUB_Card_Asy[i];
if ( cc == 0 ) */
// _CardSetCLK4(0);
// _CardPutBit(0);
// _CardSetClock(0);
// _CardSetReset(0);
_SamSocketConfig(0);
_SamCardSetPower(0);
return;
}
/************************************************************************
* *
* Module title: _DisableSamRec/_SamEnableSamRec *
* Module type: subprogram *
* *
* Author: JPA *
* Date: 2005-03-08 *
* Reviewed by: *
* Date: *
* *
* Last changed by: *
* Date: *
* *
* Functional Description: Disable or Enable Timer counter ,the *
* reception from CPU Card work on or off *
* these function base on _DisableIcRec and _EnableIcRec *
************************************************************************/
static void _DisableSamRec(void)
{
TBCCTL0 = 0; // TRCCR0 interrupt enabled
TBCTL = MC_0;
}
static void _EnableSamRec(void)
{
P6DIR &=~BIT4; //I/O INPUT MODE
PUB_Card_RI = 0x00;
TBCTL = TBSSEL_2 + TBCLR; // SMCLK, clear TBR
TBCCTL0 = CCIE; // TRCCR0 interrupt enabled
TBCCR0 = BAUDTATE; // etu = 372/2MHz
//TBCTL = TBSSEL_2 + MC_1;
//PUB_Card_Counter = 0;
//PUB_T0Type = DEF_T0_ICREC;
//PUB_Card_RI = 0x00;
//TBCTL = TBSSEL_2 + MC_1; //Enable Interrupt
}
static void _EnableSamSend(void)
{
P6DIR |=BIT4; //I/O OUTPUT MODE
PUB_T0Type = DEF_T0_SAMSEND;
TBCTL = TBSSEL_2 + TBCLR; // SMCLK, clear TBR
TBCCTL0 = CCIE; // TRCCR0 interrupt enabled
TBCCR0 = BAUDTATE; // etu = 372/2MHz
PUB_Card_Counter = 0;
PUB_Card_RecBuff = 0;//yesy add 2005.06.22
CheckSum=0;//yesy add 2005.06.22
PUB_Card_TI = 0x00;
TBCTL = TBSSEL_2 + MC_1; //Enable Interrupt Start sending
}
/************************************************************************
* *
* Module title: _SamCardReadIOLimit *
* Module type: subprogram *
* *
* Author: Yesy *
* Date: 2005-05-21 *
* Reviewed by: *
* Date: *
* *
* Last changed by: *
* Date: *
* *
* Functional Description: During the permitted time( *
* PUB_Card_RecLimit value),received data *
* from I/O OUTCARDDATA *
* Input : *recdata ----received data *
* Reverse ----reference to EMV2000 *
* Output: False -----failure *
* True -----sucess *
* the fucntion base on _CardReadIOLimit *
************************************************************************/
byte _SamCardReadIOLimit(byte *recdata, byte Reverse)
{
uint i;
byte j,ss;
i = 0;
ss = 0;
while (i < PUB_Card_RecLimit)// && ( _CheckStartBit() == 0 ) )
{
for (j=0;j<60;j++)
//if ( _CheckStartBit() )
if ( _SamCheckStartBit() )
{ss=1;break;}
i++;
if(ss) break;
}
if ( ss )
{
if ( Reverse == 0 ) *recdata =_CardReadByte();
else *recdata = _ReverseData(_CardReadByte());
return TRUE;
}
else return FALSE;
}
/************************************************************************
* *
* Module title: _CardReadByte/_CardPutByte *
* Module type: subprogram *
* *
* Author: JPA *
* Date: 2005-03-08 *
* Reviewed by: *
* Date: *
* *
* Last changed by: *
* Date: *
* *
* Functional Description: Uses I/O to simulate a standard serial *
* port , received or sent one byte *
************************************************************************/
static void _SamCardPutByte(byte IOData)
{byte P;
//ET0 = 0;
//P6DIR |=BIT1; // OUTPUT mode
//TBCTL = TBSSEL_2 + MC_1; //Enable Interrupt Start sending
/*PUB_Card_SendBuff=0xff;
_EnableICSend();
while ( PUB_Card_TI == 0x00)
{ //ET0 = 1;
//PCON = PCON | 0x01;
_BIS_SR(LPM0_bits + GIE);
//ET0 = 0;
}*/
//ET0 = 1;
//_Delay(10);
PUB_Card_SendBuff = IOData;
PUB_Card_SendBuff = (PUB_Card_SendBuff << 1) | 0x0fc00;
//ACC = IOData;
P=_Chck_Parity(IOData);
if ( P == 0 )
PUB_Card_SendBuff = PUB_Card_SendBuff | 0x200;
//PUB_T0Type = DEF_T0_ICSEND;
if ( PUB_Card_ICReverse[PUB_Card_ICNO] == 0 )
PUB_Card_SendBuff = PUB_Card_SendBuff ^ 0x200;
_EnableSamSend();
//PUB_Card_Counter = 0;
//PUB_Card_TI = 0x00;
//TBCTL = TBSSEL_2 + MC_1; //Enable Interrupt Start sending
//TL0 = TH0;
//TR0 = 1;
//ET0 = 1;
return;
}
/************************************************************************
* *
* Module title: _ReverseData/_Chck_Parity *
* Module type: subprogram *
* *
* Author: JPA *
* Date: 2005-03-09 *
* Reviewed by: *
* Date: *
* *
* Last changed by: *
* Date: *
* *
* Functional Description: Basic function *
************************************************************************/
/************************************************************************
* *
* Module title: IntTimeB *
* Module type: subprogram *
* *
* Author: JPA *
* Date: 2005-03-09 *
* Reviewed by: *
* Date: *
* *
* Last changed by: *
* Date: *
* *
* Functional Description: Timer B interrupt function *
* Generates the simulated I/O baudrate *
* both sending and receiving *
************************************************************************/
#pragma vector=TIMERB0_VECTOR
__interrupt void IntTimerB (void)
{
// P5DIR |= BIT4;
switch ( PUB_T0Type )
{
case DEF_T0_ICREC:
PUB_Card_Counter++;
if ( PUB_Card_Counter < 9 )
{
PUB_Card_RecBuff = PUB_Card_RecBuff >> 1;
// P5OUT |= BIT4 ;//add yxh
if ( INCARDDATA1) {
PUB_Card_RecBuff = PUB_Card_RecBuff | 0x80;
CheckSum= CheckSum ^ 1;
}
else
CheckSum= CheckSum ^ 0;
// P5OUT &= ~BIT4;//add yxh
}
else
if ( PUB_Card_Counter == 9 ) //yesy 2005.06.22 add CheckBit
{
if (( INCARDDATA1 >>1 )!=CheckSum)
{
//PUB_Card_RecBuff = 0x00;
}
}
else
{
//ET0 = 0x00;
//TR0 = 0x00;
TBCTL = TBSSEL_2 + MC_0;
PUB_Card_RecData = PUB_Card_RecBuff;
PUB_Card_RI = 0x01;
PUB_T0Type = DEF_T0_NONE;
LPM0_EXIT;
//IE0 = 0x00;
//EX0 = 0x01;
//PUB_Event = DEF_EVENT_CARDCOM;
}
break;
case DEF_T0_ICSEND:
if ( PUB_Card_SendBuff & 0x01 )
OUTCARDDATA1;//INT0 = 0x01;
else
OUTCARDDATA0;//INT0 = 0x00;
PUB_Card_SendBuff = PUB_Card_SendBuff >> 1;
PUB_Card_Counter++;
if ( PUB_Card_Counter >= 12 )
{
//ET0 = 0x00;
//TR0 = 0x00;
TBCTL = TBSSEL_2 + MC_0;
PUB_T0Type = DEF_T0_NONE;
PUB_Card_TI = 0x01;
//PUB_Event = DEF_EVENT_CARDCOM;
OUTCARDDATA1;//INT0 = 0x01;
LPM0_EXIT;
}
//else
//PUB_Event = DEF_EVENT_NONE;
break;
/*Add by Yesy 2005.05.21 (Begin)*/
case DEF_T0_SAMREC:
PUB_Card_Counter++;
if ( PUB_Card_Counter < 9 )
{
PUB_Card_RecBuff = PUB_Card_RecBuff >> 1;
if ( INSAMCARDDATA1) PUB_Card_RecBuff = PUB_Card_RecBuff | 0x80;
}
else
if ( PUB_Card_Counter == 9 ) //yesy 2005.06.22 add CheckBit
{
if (( INSAMCARDDATA1 >>1 )!=CheckSum)
{
//PUB_Card_RecBuff = 0x00;
}
}
else
{
//ET0 = 0x00;
//TR0 = 0x00;
TBCTL = TBSSEL_2 + MC_0;
PUB_Card_RecData = PUB_Card_RecBuff;
PUB_Card_RI = 0x01;
PUB_T0Type = DEF_T0_NONE;
LPM0_EXIT;
//IE0 = 0x00;
//EX0 = 0x01;
//PUB_Event = DEF_EVENT_CARDCOM;
}
break;
case DEF_T0_SAMSEND:
if ( PUB_Card_SendBuff & 0x01 )
OUTSAMCARDDATA1;//INT0 = 0x01;
else
OUTSAMCARDDATA0;//INT0 = 0x00;
PUB_Card_SendBuff = PUB_Card_SendBuff >> 1;
PUB_Card_Counter++;
if ( PUB_Card_Counter >= 12 )
{
//ET0 = 0x00;
//TR0 = 0x00;
TBCTL = TBSSEL_2 + MC_0;
PUB_T0Type = DEF_T0_NONE;
PUB_Card_TI = 0x01;
//PUB_Event = DEF_EVENT_CARDCOM;
OUTSAMCARDDATA1;//INT0 = 0x01;
LPM0_EXIT;
}
//else
//PUB_Event = DEF_EVENT_NONE;
break;
/*Add by Yesy 2005.05.21 (End)*/
default :break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -