⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ty514cpu.c

📁 EMV2000 LEVEL 1实现的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
          IC_RST1=0;
          IC_IO1=0;
          CPU1_REST_FLAG=0;
          IC_PWR1=1;
          STATE_FLAG = 1 ;
	  command = 0x8a;
          return;
          }
           delay2ms();
           delay2ms();
         if((tempPCB&0xc0)==0x80)
         {
           Card1SendR(0x0,tempPCB);
           m++;
           goto trans1_t1_r;
         }
         if((tempPCB&0x80)==0x00)
         {
          if(tempPCB&0x40)
          {
             Card1SendR(0x0,0x92);
             m++;
             tempPCB1=0x92;
             goto trans1_t1_r;
          }
          else
          {
          Card1SendR(0x0,0x82);
          m++;
          tempPCB1=0x82;
           goto trans1_t1_r;
          }
         }
         else
         {
          Card1SendR(0x0,0x82);
          m++;
          tempPCB1=0x82;
          goto trans1_t1_r;
          }
     }

//判断是否请求改变IFSC的长度
        if(PCB==0xc1)
	{
        //S请求块的INF值不符和规则
         if(tempINF>0xfe||tempINF<0x10)
         {
           //判断重发次数是否超过
          if(m==2)
          {
          IC_RST1=0;
          IC_IO1=0;
          CPU1_REST_FLAG=0;
          IC_PWR1=1;
          STATE_FLAG = 1 ;
	  command = 0x8a;
          return;
          }
           delay2ms();
           delay2ms();
          if((tempPCB&0x80)==0x0)
          {
          if((tempPCB&0x40)!=0x40)
           {
           Card1SendR(0x0,0x82);
           tempPCB1=0x82;
           m++;
           goto  trans1_t1_r;
           }
           if((tempPCB&0x40)==0x40)
           {
           Card1SendR(0x0,0x92);
           tempPCB1=0x92;
           m++;
           goto  trans1_t1_r;
           }
          }
          else if(tempPCB&0x80)
          {
           Card1SendR(0x0,tempPCB);
           m++;
           goto trans1_t1_r;
          }
          else
          {
           Card1SendR(0x0,0x80);
           m++;
           goto  trans1_t1_r;
          }
         }
        delay2ms();
        delay2ms();
        IFSC=tempINF;
        SendSblock(0x0,0xe1,tempINF);
        goto trans1_t1_r;
        }
       else if(PCB == 0xc3) //判断是否请求了等待时间扩展
       {
        delay2ms();
        delay2ms();
        SendSblock(0x0,0xe3,tempINF);
        WTX=tempINF;
        goto trans1_t1_r;
        }
        else
        {
          if(m==2)
          {
           IC_RST1=0;
           IC_IO1=0;
           CPU1_REST_FLAG=0;
           IC_PWR1=1;
           STATE_FLAG = 1 ;
	   command = 0x8a;
           return;
          }
        delay2ms();
        if((tempPCB==0x80)||((tempPCB&0x40)!=0x40))
        {
        Card1SendR(0x0,0x80);
        m++;
        goto trans1_t1_r;
        }
        if((tempPCB==0x90)||((tempPCB&0x40)==0x40))
        {
        Card1SendR(0x0,0x90);
        m++;
        goto trans1_t1_r;
        }
       }

     }



/*      收到的是R块       */
     if((PCB&0xc0)==0x80)
     {
       //长度错误
        if(T!=0x00)
        {
         if(m==2)
         {
          IC_RST1=0;
          IC_IO1=0;
          CPU1_REST_FLAG=0;
          IC_PWR1=1;
          STATE_FLAG = 1 ;
	  command = 0x8a;
          return;
          }
           delay2ms();
           delay2ms();
         if((tempPCB&0xc0)!=0xc0)
         {
          if(tempPCB&0x80)
          {
             Card1SendR(0x0,tempPCB);
             m++;
             goto trans1_t1_r;
           }
           else
          {
           if(tempPCB&0x40)
           {
             Card1SendR(0x0,0x92);
             m++;
             goto trans1_t1_r;
            }
            else
            {
              Card1SendR(0x0,0x82);
             m++;
             goto trans1_t1_r;
            }
         }
        }
         if((PCB&0x90)==0x90)
          {
           Card1SendR(0x0,0x90);
           m++;
           goto trans1_t1_r;
          }
          else if((PCB&0x90)==0x80)
          {
           Card1SendR(0x0,0x80);
           m++;
           goto trans1_t1_r;
          }
         else
         {
           Card1SendR(0x0,0x82);
           m++;
           goto trans1_t1_r;
         }
       }
//R块序号错误
     if((Squence_flag==0)&&((PCB&0x9f)==0x90))
     {
      Card1SendR(0x0,0x80);
      m++;
      goto trans1_t1_r;
      }
     if((tempPCB2&0xc0)==0x80)
     {
      if(PCB==tempPCB2)
      {
         if(m==2)
         {
          IC_RST1=0;
          IC_IO1=0;
          CPU1_REST_FLAG=0;
          IC_PWR1=1;
          STATE_FLAG = 1 ;
	  command = 0x8a;
          return;
          }
       if(PCB==0x80)
       {
        Card1SendR(0x0,0x90);
        m++;
        goto trans1_t1_r;
       }
       else
       {
        Card1SendR(0x0,0x80);
        m++;
        goto trans1_t1_r;
       }
      }
     }
//收到格式错误的R块
        if(PCB&0x20)
        {
         if(m==2)
         {
          IC_RST1=0;
          IC_IO1=0;
          CPU1_REST_FLAG=0;
          IC_PWR1=1;
          STATE_FLAG = 1 ;
	  command = 0x8a;
          return;
         }
        delay2ms();
        delay2ms();
        if(!(tempPCB&0x80))
        {
        if((tempPCB&0x40)!=0x40)
        {
        Card1SendR(0x0,0x82);
        tempPCB1=0x82;
        m++;
        goto trans1_t1_r;
        }
         if((tempPCB&0x40)==0x40)
        {
        Card1SendR(0x0,0x92);
        m++;
        tempPCB1=0x92;
        goto trans1_t1_r;
        }
        }
        if((tempPCB&0xc0)==0x80)
        {
        Card1SendR(0x0,tempPCB);
        m++;
        goto trans1_t1_r;
        }
    }

//收到表示错误的R块
        if(((PCB&0x8f)!=0x80))
        {
         delay2ms();
         delay2ms();
         if(m==2)
         {
          IC_RST1=0;
          IC_IO1=0;
          CPU1_REST_FLAG=0;
          IC_PWR1=1;
          STATE_FLAG = 1 ;
	  command = 0x8a;
          return;
         }
          delay2ms();
//之前发送的是I块
         if((tempPCB&0x80)==0x00)
         {
           pointer-=LEN;
           Card1sendI(0x0,tempPCB,LEN);
           m++;
           goto trans1_t1_r;
          }
//之前发送的是R块
         if((tempPCB&0xc0)==0x80)
          {
           Card1SendR(0x0,tempPCB);
           m++;
           goto trans1_t1_r;
           }
//之前发送的是表示错误的R块
          if(tempPCB1&0x0f)
          {
          Card1SendR(0x0,tempPCB1);
          }
//之前发送的是S应答块
          if((tempPCB&0xe0)==0xe0)
          {
            m++;
//            pointer-=T;
            SendSblock(0x0,tempPCB,tempINF);
            goto trans1_t1_r;
           }
//之前发送的是S请求块
          if(tempPCB&0xe0==0xc0)
            {
             m++;
//           pointer-=T;
             SendSblock(0x0,tempPCB,tempINF);
             goto trans1_t1_r;
            }

        }
    //之前发送的是I块
       if(((tempPCB&0x80)==0x00)&&(tempPCB1==0x0))
        {
         if(m==2)
         {
          IC_RST1=0;
          IC_IO1=0;
          CPU1_REST_FLAG=0;
          IC_PWR1=1;
          STATE_FLAG = 1 ;
	  command = 0x8a;
          return;
         }
          delay2ms();
          delay2ms();
          m++;
          pointer-=LEN;
          Card1sendI(0x0,tempPCB,LEN);
          goto trans1_t1_r;
        }

//之前发送的是S块
    if(((tempPCB&0xc0)==0xc0)&&((PCB&0x0f)==0x0))
    {
     if((tempPCB&0xe0)==0xc0)
     {
         if(m==2)
         {
          IC_RST1=0;
          IC_IO1=0;
          CPU1_REST_FLAG=0;
          IC_PWR1=1;
          STATE_FLAG = 1 ;
	  command = 0x8a;
          return;
         }
         m++;
      SendSblock(0x0,tempPCB,&Inf);
     goto trans1_t1_r;
     }
     if((tempPCB&0xe0)==0xe0)
     {
       if(m==2)
       {
         IC_RST1=0;
         IC_IO1=0;
         CPU1_REST_FLAG=0;
         IC_PWR1=1;
         STATE_FLAG = 1 ;
	 command = 0x8a;
         return;
       }
     if(PCB==0x80)
     {
     Card1SendR(0x0,0x80);
     }
     else
     {
      Card1SendR(0x0,0x90);
      tempPCB1=0x90;
     }
     m++;
     goto trans1_t1_r;
     }
    }
//之前发送的是R块
    if(((tempPCB&0xc0)==0x80))
    {
        if(!(tempPCB1&0x0f))
        {
         delay2ms();
          if(m==2)
         {
          IC_RST1=0;
          IC_IO1=0;
          CPU1_REST_FLAG=0;
          IC_PWR1=1;
          STATE_FLAG = 1 ;
	  command = 0x8a;
          return;
         }
         m++;
         Card1SendR(0x0,tempPCB);
         goto trans1_t1_r;
        }
    }
    }
 }

/*收到S应答块*/
      if((PCB&0xe0)==0xe0)
      {
//之前发送的是I块
        if((tempPCB&0x80)==0x00)
        {
          if(tempPCB&0x40)
          {
            if(m==2)
            {
             IC_RST1=0;
             IC_IO1=0;
             CLK_CTR=1;
             IC_PWR1=1;
             CPU1_REST_FLAG=0;
             STATE_FLAG = 1 ;
	     command = 0x8a;
             return;
           }
            Card1SendR(0x0,0x92);
            m++;
            tempPCB1=0x92;
            goto trans1_t1_r;
          }
        if(!(tempPCB&0x40))
        {
            if(m==2)
            {
             IC_RST1=0;
             IC_IO1=0;
             CPU1_REST_FLAG=0;
             IC_PWR1=1;
             STATE_FLAG = 1 ;
	     command = 0x8a;
             return;
            }
            Card1SendR(0x0,0x82);
            tempPCB1=0x82;
            m++;
            goto trans1_t1_r;
        }
      }
//之前发送的是R/S块
        if(tempPCB&0x80)
        {
         if(m==2)
         {
          IC_RST1=0;
          IC_IO1=0;
          CPU1_REST_FLAG=0;
          IC_PWR1=1;
          STATE_FLAG = 1 ;
	  command = 0x8a;
          return;
         }
         if((tempPCB&0xe0)==0xe0)
         {
          delay2ms();
          Card1SendR(0x0,0x80);
          goto trans1_t1_r;
         }
        if((tempPCB&0xc0)==0x80)
        {
          delay2ms();
          Card1SendR(0x0,tempPCB);
          goto trans1_t1_r;
        }
       }
      }

/*   收到I块   */
   if(!(PCB&0x80))
   {
     delay2ms();
     delay2ms();

//序号不对
     if(((PCB&0x40)==(ISquen&0x40))&&(Squence_flag==1))
      {
        if(m==2)
        {
        IC_RST1=0;
        IC_IO1=0;
        CPU1_REST_FLAG=0;
        IC_PWR1=1;
        STATE_FLAG = 1 ;
	command = 0x8a;
        return;
        }
       delay2ms();
       if(PCB&0x40)
       Card1SendR(0x0,0x82);
       else
       Card1SendR(0x0,0x92);
       m++;
       counter-=T;
       goto trans1_t1_r;
      }
     if(Squence_flag==0)
     {
      if((PCB&0x40)==0x40)
      {
        if(m==2)
        {
        IC_RST1=0;
        IC_IO1=0;
        CPU1_REST_FLAG=0;
        IC_PWR1=1;
        STATE_FLAG = 1 ;
	command = 0x8a;
        return;
        }
      Card1SendR(0x0,0x82);
      m++;
      counter-=T;
      goto trans1_t1_r;
      }
     }
 }
          tempPCB1=0;
          tempPCB2=PCB;
          tempR=0;
          T=0;
          if(!(PCB&0x80))
          ISquen=PCB;
          Squence_flag=1;
          m=0;
/************************************************************************************************************/
//从卡片接收块链接处理
  if( (PCB&0x20) == 0)
  return; // 无块链接
trans1_t1_t:
        delay2ms();
	CARD1sendbyte(NAD);
	if(STATE_FLAG)
	{
		command = SErr;
		return;
	}

	if(PCB&0x40)
		PCB = 0x80;
	else
		PCB = 0x90;
	tempPCB=PCB;
	CARD1sendbyte(PCB);
	if(STATE_FLAG)
	{
		command = SErr;
		return;
	}
	CARD1sendbyte(0);
	if(STATE_FLAG)
	{
		command = SErr;
		return;
	}

	CARD1sendbyte(PCB^NAD);	// BCC
	if(STATE_FLAG)
	{
		command = SErr;
		return;
	}
	goto trans1_t1_r;//receive again


/**************************************************************************************************************************/
//接收连接(发送块)处理的R块或I块
trans1_t1_s:
        n=0;
        delay2ms();
        delay2ms();
        delay2ms();
	CARD1sendbyte(NAD);//SENDbyte0(NAD);
	if(STATE_FLAG)
	{
        command = SErr;
        return;
        }
	T1_Bcc = NAD;
	CARD1sendbyte(PCB);//SENDbyte0(pcb)
	if(STATE_FLAG)
	{
	  command = SErr;
	  return;
	}
       	T1_Bcc ^= PCB;
	CARD1sendbyte(LEN);//SENDbyte0(Len);
	if(STATE_FLAG)
	{
	   command = SErr;
	   return;
	}
        T1_Bcc ^= LEN;
	LEN1=LEN;
	while(LEN1)
	{
//           transbuff[n]= XBYTE[pointer];
	   temp = XBYTE[pointer];
	   CARD1sendbyte(temp);
	   T1_Bcc ^= temp;
	 if(STATE_FLAG)
	 {
	   command = SErr;
	   return;
	 }
	  LEN1 --;
	  pointer ++;
          n++;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -