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

📄 gcjig.c

📁 GameCubeMemoryCardTestJig_LastCode_ok,is a SOURCE code for GameCube Memory CARD.
💻 C
📖 第 1 页 / 共 2 页
字号:
                                                                                                                             

/******************************************************/
/*   FileName: GameCubeJig.c                          */
/*             for PIC's SoftWare SPI  By manual      */
/*             16c74b 3.3v 4Mhz                       */
/*   WriteBy : John He                                */
/*   Date    : 02/01/8--18 (Last code)                */
/*   Ver     : 2 (Working stats is dis by MemTypeLed  */
/*   RC4---SDI                                        */
/*   RC5---SDO                                        */
/*   RC3---SCK                                        */
/******************************************************/ 
/*****************************************************************/
/*  GetMemType(void)= 0x04--4M  --> 0~1023 Sector                */
/*                    0X08--8M  --> 0~2407 Sector                */
/*                    0X10--16M --> 0~4095 Sector                */
/*  Read   Unit:  Sector == 512 byte                             */
/*  Write  Unit:  Page   == 128 byte                             */
/*  Erase  Unit:  16 Sector                                      */
/*  Note:   1.Writeing the MemCard must to see it's status;      */
/*            and Read it must not to see it's status.           */
/*          2. Level1-4_Command process must use the             */
/*             last 4 bytes data getting by Txd_command_WithRxd()*/
/*             and the ReadArry process is so on                 */
/*          3. The MemCard's BUSY signal must be checking when   */
/*             sending the every command                         */
/*****************************************************************/

// #include "pic.h" 
 #include "stdio.h"
 #include "pic1674.h" 

 #define Mem_CS  	RB1
 #define Mem_Busy 	RB2
 #define Card_Dec       RA5
 #define Start_Key      RA0
 
 #define SDI      RC4
 #define SDO      RC5
 #define SCK      RC3

 #define Led1_Ok   	RA1
 #define Led2_Fail   	RA2
 #define Led3_Read   	RA3
 #define Led4_Write   	RA4


 bank1    unsigned char temp_txd_data;
 bank1    unsigned char verify_error_flag1,verify_error_flag2;
  unsigned char level1_flg,level2_flg,level3_flg,level4_flg; // !!!!!!!!

  unsigned char rxd_data_buf; 
  unsigned char rxd_data[9];
  unsigned char temp_data[8];
       bit Rxd_Bit;  
 
 bank1 unsigned char Level1_Command[] = {0x52,0x03,0xff,0x01,0x48,0xff,0xff,0xff,0xff};
 bank1 unsigned char Level2_Command[] = {0x52,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff}; 
 bank1 unsigned char Level3_Command[] = {0x52,0x9c,0x0f,0x00,0x00,0xff,0xff,0xff,0xff};
 bank1 unsigned char Level4_Command[] = {0x52,0x94,0xa1,0x00,0x00,0xff,0xff,0xff,0xff};
 //unsigned char            Temp_Arry[] = {0x00,0x00,0x00,0x00};

bank1  unsigned char    GetMem_Type[] = {0x00,0x00,0xff,0x80,0x00,0x00};//{0xaa,0x55,0xaa,0x55,0xaa,0x55};
bank1  unsigned char    StatusClear[] = {0x89};
bank1  unsigned char     ReadStutas[] = {0x83,0X00,0Xff} ; 
//bank1  unsigned int   Sector_Addres[] = 
//                            {0,2,4,8,16,(32+1),64,128,256,512,(1024-16),(2048-16),(4096-16)};
bank1 unsigned char Sector_Addres[] ={0x00,0x00, 0x00, 0x01, 0x00,0x02, 0x00,0x04, 0x00,0x08, 0x00,0x10, 0x00,
                     0x21, 0x00,0x40,0x00,0x80, 0x01,0x00, 0x02,0x00, 0x04,0x00, 0x08,0x00, 0x10,0x00 };

const unsigned char ChechData_Lev1[]={0x00,0x01,0x37,0xff, 0x36,0x03,0x5a,0x6e, 0xa4,0x69,0xe8,0x07, 0x31,0xf2,0xeb,0xd9, 
                                      0x5c,0x74,0xd9,0xbc, 0x56,0x25,0x83,0x77, 0x82,0xc2,0xce,0x9e, 0x68,0x42,0xd6,0x3f,
                                      0x84,0x17,0xff,0xec, 0xf3,0x30,0x2f,0xca, 0xcc,0xb6,0x10,0x00, 0xc0,0x43,0x5c,0x21,
                                      0x41,0x45,0x62,0xdb, 0x81,0x4d,0x2d,0xa9, 0x34,0xd5,0xec,0xa0, 0x0f,0x17,0x9e,0x39,
                                      0x51,0x26,0x8d,0x77, 0x81,0xc9,0xda,0x82, 0x6d,0x59,0xfc,0x33, 0xb3,0x30,0xb7,0xac,
                                      0xb2,0x37,0xb9,0x9a, 0x8f,0x3c,0xa5,0xdc, 0xa4,0x5b,0x97,0x2e, 0x55,0xa4,0x0e,0x5c,
                                      0xa2,0x47,0x5a,0xf9}; //ok

const unsigned char ChechData_Lev2[]={0x90,0xea,0x47,0xe9, 0x9a,0x1f,0x1c,0xb5, 0x7d,0x15,0x1b,0xe6, 0xed,0xc5,0x06,0x1c, 
                                      0xfb,0x94,0x80,0x29, 0x35,0x4a,0xa9,0x7b, 0x0d,0xb5,0x6e,0xdf, 0xe0,0xc4,0xd9,0xbd,
                                      0x9e,0x8c,0xe3,0x75, 0xd8,0xa8,0x3c,0x58, 0x82,0x49,0x14,0x91, 0x37,0xdf,0xaf,0x9a,
                                      0x7a,0x0f,0x4f,0xf1, 0xba,0xe5,0xce,0x8d, 0x2c,0x5b,0x98,0x0a, 0x6e,0xb4,0x1f,0x2e,
                                      0xa7,0x01,0x49,0x4d, 0xb4,0x4d,0xd9,0x44, 0x47,0xbe,0xf0,0x7e, 0x40,0x4c,0x6d,0x62};

const unsigned char ChechData_Lev3[]={0xf1,0x18,0xc7,0xbc, 0x7e,0xcb,0x79,0x4b, 0xfb,0xa0,0x1d,0x2e, 0x9b,0x17,0x67,0x49,
                                      0xf0,0x0f,0x87,0x14, 0x83,0xf0,0x96,0x33, 0xad,0x16,0x5b,0x78, 0x90,0x60,0xc1,0x3f,
                                      0x41,0x81,0x82,0xc3, 0xbc,0x01,0x84,0x41, 0x43,0x7a,0x8f,0xcb, 0x47,0x09,0x65,0x42,
                                      0x5f,0x95,0xbd,0x0c, 0x64,0x01,0xec,0x6e, 0xb4,0xca,0x37,0x6b, 0x00,0x37,0xcd,0xd3, 
                                      0xd6,0x58,0x39,0xef, 0xdd,0x44,0xfa,0x43, 0xb8,0x77,0x87,0x30, 0x4f,0xe8,0x66,0x5e,
                                      0xb0,0xa7,0x7a,0x2f, 0x6c,0x88,0xc0,0x85, 0xeb,0x40,0x50,0x0f};

const unsigned char ChechData_Lev4[]={0x5c,0xe6,0xd4,0x5b, 0x2f,0x92,0xb1,0x45, 
                                      0xc6,0xe8,0xf6,0xac, 0xc0,0xb4,0xca,0x18, 0x18,0x5c,0x37,0xbc, 0x18,0xd4,0xe0,0xab,
                                      0x51,0x4c,0x88,0x3c, 0xa5,0x77,0x01,0x55, 0x96,0xd3,0xed,0xfc, 0x10,0x59,0x91,0xdf,
                                      0xc8,0xca,0x01,0x43, 0xe6,0xcf,0x97,0xc6, 0xac,0x9d,0x27,0x64, 0x78,0xfe,0x53,0xe2,
                                      0x41,0xf3,0x08,0x81, 0x06,0x96,0xff,0x92, 0x09,0xb6,0x2d,0x49, 0x3e,0xc9,0x1b,0x81,
                                      0xd1,0x26,0xbe,0xb5, 0x70,0xc9,0x8e,0xa2, 0xfb,0xbb,0x00,0xfa, 0x49,0x3a,0x77,0x0f,
                                      0x2f,0xdc,0xed,0xff};

/* Below array must be modified Sector addres or Page address when useing it */
bank1 unsigned char                 EraseSector[] = {0xf1,0x00,0x00};
bank1 unsigned char                    ReadArry[] = {0x52,0x00,0x00, 0x00, 0x00,0xff,0xff,0xff,0xff};
bank1 unsigned char                Page_Program[] = {0xf2,0x00,0x00, 0x00, 0x00}; 
                                         /*         SA2  SA1   PN          */
 
/**********************/
void CS0_Card(void)
  {
    Mem_CS=0;  
  }
/**********************/
void CS1_Card(void)
  {
   Mem_CS=1;
  }

/***********************/
void delay(unsigned int cnt) 
    {
       unsigned int j;
       for(j=0;j<cnt;j++);
    }
/***********************/
unsigned char read_key()
  { 
   if(RA0==0) 
     { delay(500); 
       if(RA0==0){ return(1);}
     }
   return(0);
  }
/*********************/ 
   void ini_mcu (void)
      { 
        /*++++++++++ for pic ++++++++++++*/
        OPTION=0X00;
        ADCON0 = 0x00;
        ADCON1 = 0x03;
        PORTC=0X00;
        TRISC =0x10;   /* Port C Bit 4  for input;  */
        INTCON=0X00; 
        
        PORTA=0X1F; //0X1E
        TRISA = 0x21;   /* Port A Bit 0&4 for input; Other bit for output */
        TRISB = 0x84;    /* 0x04 Port B Bit 3 for input with /BUSY */
        TRISD = 0x00;   /* Port C Bit 0~7 for output; */    
        TRISE = 0x00;   /* not use */
        /*++++++++++++++++++++++*/
        CS1_Card();    
        SDO=0;
        SCK=0; 
        verify_error_flag1=0; 
        verify_error_flag2=0;
        level1_flg=0;
        level2_flg=0;  
        level3_flg=0;
        level4_flg=0;  

     }

/**********************/
void ClearArray_rxd_data (void)
  {  unsigned char i;
     for(i=0;i<40;i++)
       {
         rxd_data[i]=0;
       }
  }

/****************************************************/

unsigned char ssp_One_Byte(unsigned char txd_data)

  { 
   unsigned char i,temp_data;
   
   rxd_data_buf=0x00;
   temp_txd_data=txd_data;
   temp_data=0X80;            
   for(i=0;i<8;i++)
        { 
          SCK=0;
          Rxd_Bit=SDI;
          if(Rxd_Bit==1) {rxd_data_buf=rxd_data_buf | temp_data;};
          temp_data=(temp_data) >> 1;
          
          if(((temp_txd_data) & 0x80)==0x80) {SDO=1;};
          if(((temp_txd_data) & 0x80)==0x00) {SDO=0;};
          temp_txd_data=(temp_txd_data) << 1; 
          SCK=1;
        } 
    
    SCK=0;
  }

/*************************************************/

void Txd_command_WithRxd ( unsigned char command_array[],unsigned char command_number)
 
   { unsigned char i;
     while(Mem_Busy==1) {}
     for(i=0;i<(command_number);i++)
        {
          ssp_One_Byte(command_array[i]);
          
          rxd_data[i]=rxd_data_buf;                    
        }
    }
/*********************************/

/********************************/
 
unsigned char GetMemType(void)
  {
    unsigned char mem_type;
    CS0_Card();
    delay(20);
    Txd_command_WithRxd(GetMem_Type,6);
    mem_type=rxd_data[5];
    CS1_Card();
    return (mem_type);
    
  }
/********************/

void ClearStatus(void)
  { 
    CS0_Card();
    delay(20);
    //Txd_command_WithRxd(StatusClear,1);   
    ssp_One_Byte(0x89);
    delay(5);
    CS1_Card();
  }

/****************************************/
/* FunctionName: ReadStatus(void)       */
/* Function: to read the card's status  */
/*        until the card is not busy    */
/*        and this function is come end */
/****************************************/
/*
unsigned char ReadStatus(void)
  { 
 
lp1:
     CS0_Card();
     Txd_command_WithRxd(ReadStutas,3); 
     CS1_Card();
     if(rxd_data[2] & 0x80 !=0X00) { ClearStatus();goto lp1 ;}
     if(rxd_data[2] & 0x80 ==0x00) { return (1);}
     return(0);
  }
*/
unsigned char ReadStatus(void)
  { 
     CS0_Card();
     Txd_command_WithRxd(ReadStutas,3);
     CS1_Card();

     if(rxd_data[2] && 0x80 ==0x00) { return (1);}
     else {return (0);}
 }

/***********************************
 Function: To erase 16 sector data
 Return  : 1--ok
********************/
unsigned char Erase16Sector(unsigned int data_sa2,unsigned int data_sa1)
  {
        CS0_Card();
        EraseSector[1]= data_sa2; /* SA2 */
        EraseSector[2]= data_sa1; /* SA1 */
//eras_lp:
          
        Txd_command_WithRxd(EraseSector,3); 
         // The ASIC return the stats is always 0xff now !!!!
         // if(ReadStatus() !=1){goto eras_lp;} 
        CS1_Card(); 
        return (1);
  }

/*******************/
 void Get_TempRxdData_9(void)
   {
     temp_data[0]=rxd_data[5];
     temp_data[1]=rxd_data[6];
     temp_data[2]=rxd_data[7];
     temp_data[3]=rxd_data[8];

   }

/************************/
void Get_TRxdData_4(void)
   {
     temp_data[0]=rxd_data[0];
     temp_data[1]=rxd_data[1];
     temp_data[2]=rxd_data[2];
     temp_data[3]=rxd_data[3];

   }
/**********************/

 void main()
  { 
    unsigned char MemCard_Type;
    unsigned char i,j,k, led_light_data;
   
    unsigned char verify_times;
    unsigned char loop_number;
       unsigned char data_togle;    

lp_t: 
    ini_mcu(); 
    while(Card_Dec==1) {}  
    MemCard_Type = GetMemType(); 
    
    if(MemCard_Type==0x04){led_light_data=0Xf7;};
    if(MemCard_Type==0x08){led_light_data=0Xef;};
    if(MemCard_Type==0x10){led_light_data=0Xe7;};

    /*++++++++++++++++++++++*/
    
    //if(MemCard_Type==0x04) {Led3_Read=0; Led4_Write=1;Led2_Fail=1;Led1_Ok=1;}
    //if(MemCard_Type==0x08) {Led4_Write=1;Led3_Read=1;Led2_Fail=1;Led1_Ok=1;}
    //if(MemCard_Type==0x10) {Led4_Write=0;Led3_Read=0;Led2_Fail=1;Led1_Ok=1;}

    if(MemCard_Type==0x04) {PORTA=0X16;}
    if(MemCard_Type==0x08) {PORTA=0X0e;}

⌨️ 快捷键说明

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