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

📄 userio.c

📁 ST72T63游戏杆源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
           TEMP1 = B_DATA[PadCount].Packet[ByteCount];
           TEMP2 = D_DATA[PadCount].Packet[ByteCount];
           
           SendABCDSubroutine();
       }
   }                     

   PADR &=0xf9;            //set DATA D, C to 0;
   PBDR &= 0x0f;           // set DATA A,B to 0;
   for (delay=0; delay<1 ; delay++);
   PADR |= 0x04;           // Set DATA D output pins to 1
   PBDR |= 0x60;           // Set all output pins to 1
   
   //PADR &= 0xfe;           // HC126 control C 1 to 0;
}


/*------------------------------------------------------------------------
ROUTINE NAME : SendPADABCD()
INPUT/OUTPUT : Output
DESCRIPTION  : This function sent the ABD data with the clock C
------------------------------------------------------------------------*/
void SendPADABCD(int Pad_total)
{
   //PADR |= 0x01;           // HC126 control C 0 to 1;

   PadCount=0;
   ByteCount=0;

   //PBDR &= 0xef;            // Clock C  1 to 0;
   PADR &= 0xfd;            // PADR pin 1 1 to 0,Clock C  1 to 0;


   // Send the data through the A,B,C,D to the Computer
   //

   for (PadCount=0;PadCount<Pad_total;PadCount++)
   {
       for (ByteCount=0;ByteCount<4;ByteCount++)
       {
           //PBDR &= 0xef;            // Clock C  1 to 0;
		   PADR &=0xfd;               //PADR pin 1 1 to 0,Clock C  1 to 0;
        
           
           TEMP = A_DATA[PadCount].Packet[ByteCount];
           TEMP1 = B_DATA[PadCount].Packet[ByteCount];
           TEMP2 = D_DATA[PadCount].Packet[ByteCount];
           
           D1=0x80;
           for (BitCount=0; BitCount<8; BitCount++)
           {
                //PBDR &= 0xef;            // Clock C  1 to 0;
                PADR &=0xfd;               //PADR pin 1 1 to 0,Clock C  1 to 0;
                // Set the A, B and D data
                if (TEMP & D1)
                   PBDR |= 0x20;           // set DATA A to 1;
                else PBDR &= 0xdf;           // set DATA A to 0;
                    
                if (TEMP1 & D1)
                   PBDR |= 0x40;           // set DATA B to 1;
                else PBDR &= 0xbf;           // set DATA B to 0;
                    
                //if (TEMP2 & D1)
                   //PBDR |= 0x80;           // set DATA D to 1;
                //else PBDR &= 0x7f;           // set DATA D to 0;
                  if (TEMP2 & D1)
                      PADR |= 0x04;           // set DATA D to 1;
                  else PADR &= 0xfb;           // set DATA D to 0;

				   
                   be();
                   be();
				   //be();
				   //be();
				   asm nop;
				   asm nop;



                // Set the clock high
                //PBDR |= 0x10;           // Clock C  0 to 1;
				  PADR |=0x02;            //PADR PIN 1 TO 1,CLOCK C 0 TO 1;
				   
				  be();
				  be();
                  be();
                  be();
				  be();
				  //asm nop;
				  //asm nop;
				  asm nop;
				  asm nop;

                  

                D1 = D1 >> 1;
                for (delay=0;delay<1;delay++);
                for (delay=0;delay<1;delay++);
                for (delay=0;delay<1;delay++);
          }
        }
    }    

    PBDR |= 0x60;           // Set all output pins to 1
	PADR |=0x04;            //set data  d and data c to 1
    PADR &=0xfd;
    
	be();
	be();
    
}


/*------------------------------------------------------------------------
ROUTINE NAME : GetABCD()
INPUT/OUTPUT : Output
DESCRIPTION  : This function sent the ABD data with the clock C
------------------------------------------------------------------------*/
void GetABCD(int no_of_pad)
{ 
//   PBDR |= 0xf0;           // Set all output pins to 1
//   PBDDR &= 0x0F;

/*   if (ValBit(PADR,6))
   {
      delay=0;

      switch(PadID){
            case 1: TimeOut=600;
                    break;
            case 2: TimeOut=300;
                    break;
            case 3: TimeOut=20;
                    break;
      }
      
      while (ValBit(PADR,6))   // Wait for Clock C to become low
      {     delay++;   
            if (delay>TimeOut)  break;                 }

      if (delay<TimeOut) 
      {       
         for (TEMP=1 ; TEMP<no_of_pad; TEMP++)
             for (TEMP1=0; TEMP1<4; TEMP1++)
             {
                 D1=0;
                 D2=0;
                 D3=0;
              
                 for (TEMP2=0; TEMP2<8 ; TEMP2++)
                 {
                     D1 *= 2;
                     D2 *= 2;
                     D3 *= 2;
           
                     while(!ValBit(PADR,6)); // Wait for rising edge  

                     if (ValBit(PADR,3))
                        D1 += 1;
                     if (ValBit(PADR,4))
                        D2 += 1;
                     if (ValBit(PADR,7))
                        D3 += 1;
                 }   

                 A_DATA[TEMP].Packet[TEMP1]=D1;
                 B_DATA[TEMP].Packet[TEMP1]=D2;
                 D_DATA[TEMP].Packet[TEMP1]=D3;
             }
      }
   }

//   PBDDR |= 0xF0;*/
}


/*------------------------------------------------------------------------
ROUTINE NAME : KeyInit()
INPUT/OUTPUT : N/A
DESCRIPTION  : This function initialize the keys
------------------------------------------------------------------------*/
void KeyInit()
{
    A.pressed=0;
    B.pressed=0;
    C.pressed=0;
    D.pressed=0;
    E.pressed=0;
	MODESW.pressed=0;
    F.pressed=0;
    L.pressed=0;
    R.pressed=0;
    L1.pressed=0;
    R1.pressed=0;
    UP.pressed=0;
    DOWN.pressed=0;
    LEFT.pressed=0;
    RIGHT.pressed=0;
    MODE.pressed=0;
    PROFEDIT.pressed=0;
    
    if (AutofireState1 & 0x01) A.autofire = 1;     else A.autofire=0;
    if (AutofireState1 & 0x02) B.autofire = 1;     else B.autofire=0;
    if (AutofireState1 & 0x04) C.autofire = 1;     else C.autofire=0;
    if (AutofireState1 & 0x08) D.autofire = 1;     else D.autofire=0;
    if (AutofireState1 & 0x08) MODESW.autofire = 1;     else MODESW.autofire=0;
    if (AutofireState1 & 0x10) E.autofire = 1;     else E.autofire=0;
    if (AutofireState1 & 0x20) F.autofire = 1;     else F.autofire=0;
    if (AutofireState1 & 0x80) R.autofire = 1;     else R.autofire=0;
    if (AutofireState1 & 0x40) L.autofire = 1;     else L.autofire=0;
    if (AutofireState2 & 0x80) R1.autofire = 1;    else R1.autofire=0;
    if (AutofireState2 & 0x40) L1.autofire = 1;    else L1.autofire=0;
    
    AutofireEnable = A.autofire||B.autofire||C.autofire||D.autofire||E.autofire
                  ||F.autofire||L.autofire||R.autofire||L1.autofire||R1.autofire;

} 


/*------------------------------------------------------------------------
ROUTINE NAME : KeyInit()
INPUT/OUTPUT : Output
DESCRIPTION  : This function sent the ABD data with the clock C
------------------------------------------------------------------------*/
void Return_OK()
{
     if (PadID!=1)
     {  A_DATA[0].Packet[0]=0x0;
        B_DATA[0].Packet[0]=0x0;
        D_DATA[0].Packet[0]=0x0;
        SendPADABCD(1);
      }
      else {  Buff[0]=0x0;
              Buff[1]=0x0;
              Buff[2]=0x0;
              MidiCmdFlag=1;        
            }
}


/*------------------------------------------------------------------------
ROUTINE NAME : Return_message()
INPUT/OUTPUT : N/A
DESCRIPTION  : This function transfer the return message from the lower pad
------------------------------------------------------------------------*/
void Return_message()
{
     GetABCD(2);
     if (PadID>1)
     {  A_DATA[0].Packet[0]=A_DATA[1].Packet[0];
        B_DATA[0].Packet[0]=B_DATA[1].Packet[0];
        D_DATA[0].Packet[0]=D_DATA[1].Packet[0];
        SendPADABCD(1);
      }
      else {  Buff[0]=A_DATA[1].Packet[0];
              Buff[1]=B_DATA[1].Packet[0];
              Buff[2]=D_DATA[1].Packet[0];
              MidiCmdFlag=1;
           }
}

⌨️ 快捷键说明

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