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

📄 cpu.txt

📁 cpu卡和存储卡读写器程序
💻 TXT
📖 第 1 页 / 共 2 页
字号:

{

	VCC = 0;

}



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

/********以下为SLE4442卡的函数**************************************************************/

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



//复位应答

void answer_reset_4442(void)

{

	uchar data i;

	RST=HIGH;

	SDA=HIGH;

	delay(DELAY_SCL_4442);

	SCL = 0;

	delay(DELAY_SCL_4442);

	SCL = 1;

	delay(DELAY_SCL_4442);

	RST=LOW;

	delay(DELAY_SCL_4442);

	for(i=0;i<32;i++)

	{

		SCL = 0;

		delay(DELAY_SCL_4442);

		SCL = 1;

		delay(DELAY_SCL_4442);

	}

	return;

}

//////////////////////////////////////////////////////////////////////////////

//开始状态

void beg






0x7f;  ucDevice=0; mod=8; break;

		case 2: AtolLen=0xff;  ucDevice=1; mod=8; break;

		case 4: AtolLen=0x1ff; ucDevice=1; mod=16;break;

		case 8: AtolLen=0x3ff; ucDevice=1; mod=16;break;

		case 16:AtolLen=0x7ff; ucDevice=1; mod=16;break;

		case 32:AtolLen=0xfff; ucDevice=1; mod=16;break;

		case 64:AtolLen=0x1fff;ucDevice=2; mod=32;break;

	}

	if((iStAdd<0)||(iStAdd>AtolLen-1))

		return FALSE;

	if((AtolLen-iStAdd)<iLenth)

		return FALSE;	

	ucTmp=iStAdd%mod;

	if(ucTmp!=0)

	{

		ipLenth=mod-ucTmp;

		if(ipLenth>iLenth)

		   ipLenth=iLenth;

		if(!WritePage(iStAdd,ipLenth,ucType,DataBuf))

			return(FALSE);

		iStAdd += ipLenth;

		DataBuf+= ipLenth;

		iLenth += ipLenth;

	}

	ucTmp=iLenth/mod;

	for(i=0;i<ucTmp;i++)

	{

		if(!WritePage(iStAdd,mod,ucType,DataBuf))

			return FALSE;

		iStAdd += mod;

		DataBuf+= mod;

		iLenth -= mod;

	}

	if(iLenth!=0)

	{

		if(!WritePage(iStAdd,iLenth,ucType,DataBuf))

			return FALSE;

		else

			return TRUE;

	}

}                  


#include "52user.h"





//cardtype number define

#define ReadPassword 	0x01

#define VerifyPassword 	0x02

#define ChangePassword 	0x03





//define memcard operate delay time 

//SLE4442

#define DELAY_SCL_4442   10

//SLE4428

#define DELAY_CLK_4428   10

//SLE4406

#define DELAY_4406   10

//SLE4404

#define DELAY_CLK_4404   10

//AT45D041 Card;

#define DELAY_WRITE_AT45D041 30000

#define DELAY_SCK_AT45D041   10

//AT88 card

#define DELAY_CLK_102   10

//AT24C card

#define DELAY_SCK_24C01   10

#define DELAY_WRITE_24C01 2000

#define DELAY_WRITE_24C16 2000

#define DELAY_WRITE_24C64 2000



#define  WRITE 0xa0

#define  READ  0xa1



//constant define for memcard;

#define OP_OK         0

#define OP_ERR        -1

#define ERR_PARAMETER -2

#define FALSE  0

#define TRUE   1

#define HIGH   1

#define LOW    0

//type redefine

#define uchar unsigned char

#define uint  unsigned int

//commmon function pre-define for all kind of memcard;

void delay(uint iTime);

	

//bit   By



har* sBuffer);

void write_10sl_a(uchar  iOffset,uchar iWriteLen,uchar* sBuffer);



//AT45D041 Card;

//sub function

void rd_45d041(uint iPage,uint iOffset,uchar iLenth,unsigned char* sBuffer);

void wr_45d041(uint iPage,uint iOffset,uchar iLenth,unsigned char* sBuffer);

void begin_45d041(void);

void adjadd_45d041(uint* iPage,uint iOffset);

void check_byrd_45d041(void);

void byte_write_45d041(unsigned char cByte);

unsigned char byte_read_45d041();

//sle4442 sub function

void answer_reset_4442(void);

void byte_write_4442(uchar cTemp);

uchar byte_read_4442_b(void);

uchar byte_read_4442_a(void);

void begin_4442(void);

void stop_4442(void);

bit process_4442(void);

uchar error_counter_4442(void);

///////////////////////



//sle4428 Sub function

void answer_reset_4428(void);

void byte_write_4428(uchar cTemp);

uchar byte_read_4428(void);

uchar byte_read_wpbit_4428(void);

bit process_4428(void);

uchar error_counter_4428(void);

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



void power_on(void);

void power_down(void);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//sle4442  main function

bit read_sle4442(uchar iOffset,uchar iReadLen,uchar *sBuffer);

bit write_sle4442(uchar iOffset,uchar iWriteLen,uchar* sBuffer);//used

bit read_pbit_sle4442(uchar iReadLen,uchar* sBuffer);

bit write_pbit_sle4442(uchar iOffset,uchar iBufferLen,uchar* sBuffer);

bit compare_password_sle4442(uchar* sPassword,uchar iPassLen);//used

bit read_password_sle4442(uchar* sPassword,uchar iPassLen);//used

bit change_password_sle4442(uchar* sPassword,uchar iPassLen);//used

uchar error_counter_sle4442(void);//used

//sle4428 Main function

bit read_sle4428(uint iOffset,uchar iReadLen,uchar* sBuffer);//used

bit write_sle4428(uint iOffset,uchar iWriteLen,uchar* sBuffer);//used

bit read_wpbit_sle4428(uint iOffset,uchar iReadLen,uchar* sBuffer);



bit write_wpbit_sle4428(uint iOffset,uchar iWriteLen,uchar* sBu


r* sBuffer);

bit read_password_at88sc1604(uchar* sPassword,uchar iZone,uchar iPassLen);

bit change_password_at88sc1604(uchar* sPassword,uchar iZone,uchar iPassLen);

bit personal_at88sc1604(void);

bit fake_at88sc1604(uchar operation);

bit clr_wpbit_at88sc1604(uchar iZone);

bit clr_rpbit_at88sc1604(uchar iZone);

bit compare_erase_password_at88sc1604(uchar *sPassword,uchar iZone,uchar iPassLen);

bit read_erase_password_at88sc1604(uchar *sPassword,uchar iZone,uchar iPassLen);

uchar read_erase_counter_at88sc1604(uchar iZone);

bit change_erase_password_at88sc1604(uchar *sPassword,uchar iZone,uchar iPassLen);

uchar error_counter_at88sc1604(uchar iZone);



//AT45D041 Card;//main function

bit read_at45d041(uint iPage,uint iOffset,uchar iLenth,uchar* sBuffer);

bit write_at45d041(uint iPage,uint iOffset,uchar iLenth,uchar* sBuffer);

uchar register_at45d041(void);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//#define PBYTE  ((uchar *)0x30000L)

#define BGT_VALUE       0x2280



#define NO_ERROR        0       /*  */

#define PARITY_OR_EDC   1       /* 奇偶或EDC错误 */

#define ERROR1			9



#define BWT_OCCURRED    0xff    /* 字组等待时间 */

#define PARITY_ERROR    0xfe    /* 奇偶错误 */

#define STARTBIT_ERROR  0xfd	/* 起始位错 */

#define STOPBIT_ERROR   0xfc    /* 停止位错 */

#define UNDERRUN_ERROR  0xfb    /* 存于PCB中的新的错误值 */

#define OVERRUN_ERROR   0xfa    /*    */

#define PCB_ERROR       0xf9    /*    */

                                

#define FATAL_ERROR     0x02    /* Low-Nibble im R-Block */

#define INT_EMCY        0x0c    /* Vektor f. Emergency Int. */



#define NAD             0       /* 结点地址 */

#define LEN_I_BUF       120     /* I字组组冲区长度 */

#define LEN_R_S_BUF     10      /* R,S字组组冲区长度 */



#define RESET_MAX       3       /* 最大复位计数次数 */

#define RESYNC_MAX      3       /* 最大同步计数次数 */



#define NAD_IDX         0       /* 结?/textarea><BR>
<table width=756 border=0>
<tr><td width=1 bgcolor=#B0B0B0></td><td>
<script type="text/javascript"><!--
google_ad_client = "pub-8055710228382273";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "000000";
google_color_text = "333333";
google_color_url = "666666";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td>
<td width=15 bgcolor=#E4E0D8></td></tr></table>
<textarea cols=105 rows=12>文件尾:
   //uchar  LRC;               /* 标志: True=LRC, False=CRC */

     //uchar  Chksum;            /* 复位就答校验和*/

     //uchar  Convention;        /* 转换顺序*/

     //uchar  no_hist_char;      /* 没有历史字符 */

     //uchar  def_prot;          /* 默认的协议 */

     //uchar  BWT_Value;         /* 字组等待时间 */

     //uint   BWT_Extens;        /* 扩展字组等待时间 */

     //uchar  CGT_Value;         /* 字符保护时间 */

     //uint   CGT_Extens;        /* 扩展字符保护时间 */

     //uchar  CWT_Value;         /* 字符等待时间 */

     //uint   CWT_Extens;        /* 扩展字符等待时间 */

     //uchar  WWT_Value;         /* 工作等待时间 */

     //uint   WWT_Extens;        /* 扩展工作等待时间 */

     //uchar  RWT_Value;         /* 响应等待时间 */

     //uint   RWT_Extens;        /* 扩展响应等待时间 */

     uchar  T0_Compliance;     /* T=0协议 */

     uchar  T1_Compliance;

}ATR;

//#define PSTRUCT2 ((ATR *)0x30000L)

//#define Addr5  PSTRUCT2[0x00e6]

ATR aATR;

ATR aATRSAM;


//#define  uchar unsigned char

//#define  uint  unsigned int

//#define PBYTE    ((uchar *)0x30000L)

//#define Addr3    PBYTE[0xdc]

//#define Addr4    PBYTE[0xe6]



uchar   idata iStartOfProt=1;             /* 协议开始 */

uchar   idata iICC_State;                 /* ICC状态 */

uchar	idata iLastRcvMsg;

uchar   idata R_ChainPos=0;

                                            

uchar   idata uiICC_IFSC;                 /* 信息字段长度*/

uchar   idata uiICC_BWTMul;



uchar idata aucR_SndBuf[10];//=&Addr3;					/* R字组发送缓冲区 */

uchar idata aucS_SndBuf[10];//=&Addr4;					/* S字组发送缓冲区 */



bit ucICC_Parity_Error  = 0;

bit ucICC_Startbit_Error= 0;

bit ucICC_Stopbit_Error = 0;

bit ucICC_CWT_Timeout   = 0;

bit ucICC_BWT_Timeout   = 0;



bit iICC_CNT	=0;             /* ICC字组计数(0..1) */

bit iIFD_CNT	=0;             /* IFD字组计数(0..1) */



bit iICC_SAVE	=0;             /* ICC字组计数(0..1) */

bit iICC_IFD_SAVE	=0;             /* IFD字组计数(0..1) */



bit iSAM_SA



VE	=0;             /* ICC字组计数(0..1) */

bit iSAM_IFD_SAVE	=0;             /* IFD字组计数(0..1) */

⌨️ 快捷键说明

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