我正在尝试从C8051微控制器访问智能卡。我可以在重置后从智能卡接收ATR。当我尝试从同一条GPIO线发送命令时,智能卡没有响应。
在这个程序中,我正在使用基于中断的技术,当GPIO的信号变为低电平时,触发中断,因此我们开始接收数据。但是当我发送命令时,这个中断没有被触发。
void transmit_smart_data(void)
{
char j=0,parity,k=0,y=0,q=0;
puts("smart\n\r");
IE_EX0=0; //disabling interrupt
P0MDIN |=P0_B7;
P0MDOUT|=P0_B7;
while(valid_tx=getchar(),valid_tx!='b') //last character of the command is 'a'(asumption)
{
valid_data[j]=valid_tx;
}
valid_data[j]='z';
puts("valid\n\r");
j=0;
while(valid_data[j]!='z')
{
parity=parity_data(valid_data[j]);
putchar(parity);
P0_B7=0;
TMR2RL = -4550; // Init reload values
TMR2 = TMR2RL;
TMR2CN_TR2 = 1;
while(!TMR2CN_TF2H); // Wait for overflow
TMR2CN_TF2H = 0;
while(k<8)
{
if(((valid_data[j])&(1<<q))!=0) //sending bitwise bit data
{
//putchar('1');
P0_B7=1;
TMR2CN_TR2 = 1;
while (!TMR2CN_TF2H); // Wait for overflow
TMR2CN_TF2H = 0;//TMR2CN_TR2 = 0;
k++;q++;
}
else
{// putchar('0');
P0_B7=0;TMR2CN_TR2 = 1;
while (!TMR2CN_TF2H); // Wait for overflow
TMR2CN_TF2H = 0;//TMR2CN_TR2 = 0;
k++;q++;
}
}
if(parity!=0)
{
//putchar('1');
P0_B7=1;
TMR2CN_TR2 = 1;
while (!TMR2CN_TF2H); // Wait for overflow
TMR2CN_TF2H = 0;//TMR2CN_TR2 = 0;
// s
}
else
{
//putchar('0');
P0_B7=0;
TMR2CN_TR2 = 1;
while (!TMR2CN_TF2H); // Wait for overflow
TMR2CN_TF2H = 0;
}
P0_B7=1;
TMR2RL = -(4550*3); // Init reload values
TMR2 = TMR2RL; // Init Timer2 with reload value
TMR2CN_TR2 = 1;
while (!TMR2CN_TF2H); // Wait for overflow
TMR2CN_TF2H = 0;
j++;q=0;k=0;
}
puts("data");
TCON_IE0=0;
P0MDIN |= (1<<7);
P0_B2=1;
// Configure P0.0 as analog input.
// puts("data");
IE_EX0=1;
}