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

📄 rfid_x5567.c

📁 找的一个用U2270B开发的射频卡项目文件
💻 C
字号:
// $Id: rfid_x5567.c,v 1.4 2007/01/24 21:44:15 tprescott Exp $
/*****************************************************
Project : rfid_x5567.h
Date    : 9/08/2006
Author  : Toby Prescott                   
Company : Atmel                           
Comments: AVR Studio GCC

Revisions:
	v1.0 - Started written for CodeVision 
	v2.1 - 1/19/06 Changed from ASCII + stored
		vars in EEPROM
	v2.6 - Clean for WinAVR
*************************************************************/

#include "rfid_x5567.h"

//**** Configuration Block Hard Code ****//
unsigned char x5567_ConfigReg[4] EEMEM = {0x6E,0x3E,0x80,0xE8};  // X-tended mode Invert Data Off
//unsigned char x5567_ConfigReg[4] EEMEM = {0x6E,0x3E,0x80,0xEa};  // X-tended mode Invert Data On

unsigned int x5567_SGap EEMEM = 330;
unsigned int x5567_Gap EEMEM = 220;
unsigned int x5567_Zero EEMEM = 100;
unsigned int x5567_One EEMEM = 370;  

unsigned int x5567_ShortL EEMEM = 50;
unsigned int x5567_ShortH EEMEM = 210;
unsigned int x5567_LongL EEMEM = 210;  
unsigned int x5567_LongH EEMEM = 350;  

unsigned char x5567ResetCmd = 0x00;
                                                             
//**** Load New values for Write Timings ****//                                                              
void x5567_Set_SGap(unsigned int iSGap){eeprom_write_word(&x5567_SGap,iSGap);}
void x5567_Set_Gap(unsigned int iGap){eeprom_write_word(&x5567_Gap,iGap);}
void x5567_Set_Zero(unsigned int iZero){eeprom_write_word(&x5567_Zero,iZero);}
void x5567_Set_One(unsigned int iOne){eeprom_write_word(&x5567_One,iOne);}

//**** Return Status of Write Timings ****//                                                              
unsigned int x5567_Get_SGap(void){return eeprom_read_word(&x5567_SGap);}
unsigned int x5567_Get_Gap(void){return eeprom_read_word(&x5567_Gap);}
unsigned int x5567_Get_Zero(void){return eeprom_read_word(&x5567_Zero);}
unsigned int x5567_Get_One(void){return eeprom_read_word(&x5567_One);}

//**** Load New values for Read Timings ****//                                                              
void x5567_Set_ShortL(unsigned int iShortL){eeprom_write_word(&x5567_ShortL,iShortL);}
void x5567_Set_ShortH(unsigned int iShortH){eeprom_write_word(&x5567_ShortH,iShortH);}
void x5567_Set_LongL(unsigned int iLongL){eeprom_write_word(&x5567_LongL,iLongL);}
void x5567_Set_LongH(unsigned int iLongH){eeprom_write_word(&x5567_LongH,iLongH);}

//**** Return Status of Read Timings ****//                                                              
unsigned int x5567_Get_ShortL(void){return eeprom_read_word(&x5567_ShortL);}
unsigned int x5567_Get_ShortH(void){return eeprom_read_word(&x5567_ShortH);}
unsigned int x5567_Get_LongL(void){return eeprom_read_word(&x5567_LongL);} 
unsigned int x5567_Get_LongH(void){return eeprom_read_word(&x5567_LongH);} 

// *******************************************************************************
// Pass in new Configuration Block data
// ******************************************************************************/
void x5567_Set_Config_Reg(unsigned char *cConfig)
{
	unsigned char i;
	for(i=0; i<4; i++)				// Loop for all bytes in block
	{
		eeprom_write_byte(&x5567_ConfigReg[i],*cConfig++);        // Save new byte
	}
}

// *******************************************************************************
// Program the Configuration Block in the 5567 using specified Reader
// ******************************************************************************/
void x5567_WriteConfigReg(unsigned char Target_Reader)
{
	unsigned char i,tempByte;
	unsigned char writeBuff[5] = {0};
	unsigned char cOpCode = 0x04;
			
	writeBuff[0] = cOpCode<<5;		// Load the Write Op Code into buffer
	for(i=0; i<4; i++)
	{
		tempByte =eeprom_read_byte(&x5567_ConfigReg[i]);  	// Get the Configuration Block Data
		writeBuff[i] |= (tempByte>>3);  // Load into the buffer with shift for Op Code
		writeBuff[(unsigned char)(i+1)] |= (tempByte<<5);
	}
	//writeBuff[4] |= 0x00<<2;  		// Load Address of Configuration Block in buffer
	
	//Select Reader, Currently only supports U2270
	if(Target_Reader == 70)
	{
		U2270_PPCWriteBlock(38, &writeBuff[0]); 	// Call Write Block Routine
		Timer_delay_us(10000);
    	x5567_Reset(Target_Reader);  		// Send Reset Cmd
	}

	snd_Play(BEEPFREQ1,BEEPFREQ0,BEEPTIME);	// return Audio feedback
}

// *******************************************************************************
// Program Block Data in the 5567 using specified Reader 
// Pass in the block data and the block address
// ******************************************************************************/
unsigned char x5567_WriteBlock(unsigned char Target_Reader, unsigned char *inBuff, unsigned char inAddr, unsigned char confirm)
{
	unsigned char i,tempByte;
	unsigned char writeBuff[5] = {0};
	unsigned char cOpCode = 0x04;
	unsigned char *tmpInBuff;
	unsigned char cError=1;
			
	tmpInBuff = &(*inBuff); 			// Store beginning address pointer			
	writeBuff[0] = cOpCode<<5;			// Load the Write Op Code into buffer
	for(i=0; i<4; i++)
	{
		tempByte =*inBuff++;			// Copy each byte from input data
		writeBuff[i] |= (tempByte>>3);		// Shift and load into the buffer
		writeBuff[(unsigned char)(i+1)] |= (tempByte<<5);
	}
	writeBuff[4] |= inAddr<<2;			// Load the correct block address into buffer
	
	//Select Reader, Currently only supports U2270
	if(Target_Reader == 70)
	{
		U2270_PPCWriteBlock(38, &writeBuff[0]); 		// Call Write Block Routine
		Timer_delay_us(10000);
    	x5567_Reset(Target_Reader);  		// Send Reset Cmd
	}
	
	//IF confirm wanted check for successful write
	if(confirm == 1){cError = x5567_ConfirmWrite(Target_Reader, tmpInBuff, inAddr);}
	return cError;
}

// *******************************************************************************
// Program Entire Tag Data in the 5567 using specified Reader 
// ******************************************************************************/
unsigned char x5567_WriteAll(unsigned char Target_Reader)
{
	unsigned char block, i;
	unsigned char tempBlock[4];
	unsigned char cError=0;
	
	// For Data Blocks 1-7 
	for(block=1; block<8; block++)
	{
		for(i=0; i<4; i++)
		{
			tempBlock[i]=Tag_Get_Block(block,i); 		  //Read the Block Data from EEPROM
		}
		cError = x5567_WriteBlock(Target_Reader, &tempBlock[0], block, 1); // Call Block Write for Each Block
		Timer_delay_us(10000);
		if(cError == 0){block=9;}
	}
	return cError;
} 

// *******************************************************************************
// Verify that the Block Data was correctly written
// Pass in the intended block data and the block address
// ******************************************************************************/
unsigned char x5567_ConfirmWrite(unsigned char Target_Reader, unsigned char *inBuff, unsigned char inAddr)
{
 	unsigned char i, k=0;
	unsigned char tmpData;
    unsigned char *rDatPtr;
    unsigned char cError=0;
    
	//Select Reader, Currently only supports U2270
    if(Target_Reader == 70)
    {
    	U2270_PPCWriteBlock(2, &x5567ResetCmd);  		// Send Reset Cmd
		Timer_delay_us(10000);
    	cError = U2270_ReadData(67,&rDatPtr,MANCHESTER,X5557SYNC,224);	// Call Read Routine (All Blocks)
    }
    
    // IF valid Read
   	if(cError == 0)
    {
        rDatPtr = rDatPtr + (unsigned char)((inAddr-1)*4);  // Move pointer to requested Block Address
        for(i=0; i<4; i++)
        {
			tmpData = *inBuff++;  			// Copy attempted block Data byte
			if(*rDatPtr++ == tmpData){k = 1;}	// Check byte against byte read from tag
			else     				// If data does not match
			{
				k=0;  				// Flag mismatch
				i=5;				// Exit check
			}
		}
	}
	if(k==1)
	{
		snd_Play(BEEPFREQ1,BEEPFREQ0,BEEPTIME);	// IF all bytes match, return Audio feedback
		return 1;
	}			
	else
	{
		snd_Play(BUZZFREQ1,BUZZFREQ0,BUZZTIME);
		return 0;
	}
}

void x5567_Reset(unsigned char Target_Reader)
{
    	if(Target_Reader == 70){U2270_PPCWriteBlock(2, &x5567ResetCmd);}  		// Send Reset Cmd
}

⌨️ 快捷键说明

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