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

📄 rfid_writemenu.c

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

Revisions: 
	v1.0 - Started
	v2.1 - 1/20/06 Changed to work with new LCD drive
	v2.2 - 3/8/06 Changed to Flash Srings to save SRAM
	v2.3 - 3/14/06 Fixing 5558 read/write routines
	       3/15/06 Adding 5530 Support  
	v2.4 - 4/6/06  Add new working 5558 R/W routines
	       5/19/06 Fixed mfg. ID error and display as dec
	v2.5 - 6/20/06 Add Animal ID section with Read and Write
	v2.6 - 9/19/06 Clean for WinAVR
*************************************************************/

#include "rfid_WriteMenu.h" 

// Declare your global variables here 
static const char sNum0[] PROGMEM = "0";
static const char sNum1[] PROGMEM = "1";
static const char sNum2[] PROGMEM = "2";
static const char sNum3[] PROGMEM = "3";
static const char sNum4[] PROGMEM = "4";
static const char sNum5[] PROGMEM = "5";
static const char sNum6[] PROGMEM = "6";
static const char sNum7[] PROGMEM = "7";
static const char sNum8[] PROGMEM = "8";
static const char sNum9[] PROGMEM = "9";
static const char sNum10[] PROGMEM = "10";
static const char sNum11[] PROGMEM = "11";
static const char sNum12[] PROGMEM = "12";
static const char sNum13[] PROGMEM = "13";
static const char sNum14[] PROGMEM = "14";
static const char sNum15[] PROGMEM = "15";
static const char sNum16[] PROGMEM = "16";
static const char sNum17[] PROGMEM = "17";
static const char sNum18[] PROGMEM = "18";
static const char sNum19[] PROGMEM = "19";
static const char sNum20[] PROGMEM = "20";
static const char sNum21[] PROGMEM = "21";
static const char sNum22[] PROGMEM = "22";
static const char sNum23[] PROGMEM = "23";
static const char sNum24[] PROGMEM = "24";
static const char sNum25[] PROGMEM = "25";
static const char sNum26[] PROGMEM = "26";
static const char sNum27[] PROGMEM = "27";
static const char sNum28[] PROGMEM = "28";
static const char sNum29[] PROGMEM = "29";
static const char sNum30[] PROGMEM = "30";
static const char sNum31[] PROGMEM = "31";
static PGM_P sNumPtr[32] = {sNum0,sNum1,sNum2,sNum3,sNum4,sNum5,sNum6,sNum7,sNum8,sNum9,sNum10,sNum11,sNum12,sNum13,sNum14,sNum15,
						    sNum16,sNum17,sNum18,sNum19,sNum20,sNum21,sNum22,sNum23,sNum24,sNum25,sNum26,sNum27,sNum28,sNum29,sNum30,sNum31};

static unsigned char currentPos, nextPos=0, cPage=0;

// *******************************************************************************
// Menu that allows One Data Block to be written to the selected tag
// Includes verification 
// ******************************************************************************/
#define BLOCKSEL	10
#define BLOCKDAT	11
#define BLOCKDAT1	0
#define BLOCKDAT2	1
#define BLOCKDAT3	2
#define BLOCKDAT4	3
#define BLOCKDAT5	4
#define BLOCKDAT6	5
#define BLOCKDAT7	6
#define BLOCKDAT8	7
#define CONFIRM		12
void rfid_WriteMenu_Single(unsigned char Target_Tag, unsigned char Target_Reader)
{
    unsigned char i,cBlockSel = 1;
           
    unsigned char sBlockDat[9] = "00000000";
    unsigned char *sBlockDatPtr;
    unsigned char cBlockDat[4] = {0};
    unsigned char startBlock = 1, endBlock = 31;
    unsigned char wError=0;
   	
   	if(Target_Tag == 58)
    {
    	startBlock = 0;
    }
    else{endBlock = 7;}
    
    nextPos = BLOCKSEL;
    upDate = 0;
    cPage = 0; 

	uio_Release();
    while(cButton != IO_F1 && cButton != IO_F2 && cButton != IO_F3 && cButton != IO_F4)
    {                                     
		// Menu Display 
		if(currentPos != nextPos || upDate == 0)
		{
			currentPos = nextPos;
 			lcd_clear_area(SCRN_LEFT+1,SCRN_TOP+1,SCRN_RIGHT-1,SCRN_BOTTOM-1);
			if(Target_Tag == 30){lcd_put_fString(4, 2, sRFIDTAGPtr[0]);}
			else if(Target_Tag == 51){lcd_put_fString(4, 2, sRFIDTAGPtr[1]);}
			else if(Target_Tag == 52){lcd_put_fString(4, 2, sRFIDTAGPtr[2]);}
			else if(Target_Tag == 57){lcd_put_fString(4, 2, sRFIDTAGPtr[3]);}
			else if(Target_Tag == 67){lcd_put_fString(4, 2, sRFIDTAGPtr[4]);}
			else if(Target_Tag == 77){lcd_put_fString(4, 2, sRFIDTAGPtr[5]);}
			else if(Target_Tag == 70){lcd_put_fString(4, 2, sRFIDTAGPtr[6]);}
			else if(Target_Tag == 58){lcd_put_fString(4, 2, sRFIDTAGPtr[7]);}	 		
 			lcd_put_fString(32, 2, PSTR(" One"));
	 	
		 	lcd_horz_line(SCRN_LEFT,SCRN_RIGHT,11); 				// First Row Separator
		 	lcd_vert_line(12,SCRN_BOTTOM-1,37);					// First Col Separator
	 		lcd_put_fString(5,16,PSTR("Block"));
	 		lcd_put_fString(53,16,PSTR("Data"));
	 	
		 	// Insert more display code here                        
   			sBlockDatPtr = &sBlockDat[0];
        	for(i=0; i<4; i++)
        	{
    			cBlockDat[i] = Tag_Get_Block(cBlockSel,i);
    			conv_Char2HexStr2(sBlockDatPtr, cBlockDat[i]);
   				sBlockDatPtr += 2;
            }
                
   			sBlockDatPtr = &sBlockDat[0];
			lcd_put_fString(17,26,sNumPtr[cBlockSel]);
			lcd_put_String(41,26,sBlockDatPtr);
	        
			if(currentPos == BLOCKSEL )
			{
				if(Target_Tag == 58){lcd_invert_area(16,25,28,33);}
				else{lcd_invert_area(16,25,22,33);}
			}
			else {lcd_invert_area(40+(currentPos*6),25,46+(currentPos*6),33);}
	        
			lcd_update(SCRN_TOP,SCRN_BOTTOM);
			upDate = 1;
		}
		// end display  
		
		uio_Get();
        switch(currentPos){
        case BLOCKSEL:
            if(cButton == IO_UP && cBlockSel < endBlock)
            {
            	cBlockSel++;
            	upDate = 0;
            }
            else if(cButton == IO_DOWN && cBlockSel > startBlock)
            {
            	cBlockSel--;
            	upDate = 0;
            }
            else if(cButton == IO_ENTER)
            {
            	ioActive = 0;
            	if(Target_Tag == 51){wError = x5551_WriteBlock(Target_Reader, &cBlockDat[0], cBlockSel, 1);}
				else if(Target_Tag == 57){wError = x5557_WriteBlock(Target_Reader, &cBlockDat[0], cBlockSel, 1);} 
				else if(Target_Tag == 67){wError = x5567_WriteBlock(Target_Reader, &cBlockDat[0], cBlockSel, 1);} 
				else if(Target_Tag == 77){wError = x5577_WriteBlock(Target_Reader, &cBlockDat[0], cBlockSel, 1);} 
				else if(Target_Tag == 70){wError = x5570_WriteBlock(Target_Reader, &cBlockDat[0], cBlockSel, 1);}
              	else if(Target_Tag == 58)
              	{
    				x5558_SelectTagID(Target_Reader, &Target_Tag_ID[0]);
					Timer_delay_us(10000);
					x5558_LoginWrite(Target_Reader, &Target_Tag_PWD[0]);
					Timer_delay_us(10000);
             		wError = x5558_WriteSingleBlock(Target_Reader, &cBlockDat[0], cBlockSel, 1);
             	}                         	
				if(wError == 1){message_1sDisplay(PSTR("Write Successful"));}
				else {message_1sDisplay(PSTR("Write Failed"));}                         	
				ioActive = 1;
            }
            else if(cButton == IO_RIGHT){nextPos = BLOCKDAT1;}
            break;
        case BLOCKDAT1:
	    case BLOCKDAT3:
        case BLOCKDAT5:
	    case BLOCKDAT7:
           	if(cButton == IO_RIGHT && currentPos < BLOCKDAT8){nextPos++;}
            else if(cButton == IO_LEFT && currentPos > BLOCKDAT1){nextPos--;}
            else if(cButton == IO_ENTER){nextPos = BLOCKSEL;}
            else if(cButton == IO_UP)
            {
				cBlockDat[currentPos>>1] += 16;
				Tag_Set_Block(&cBlockDat[0], cBlockSel);
				upDate = 0;
           	}
            else if(cButton == IO_DOWN)
            {
				cBlockDat[currentPos>>1] -= 16;
				Tag_Set_Block(&cBlockDat[0], cBlockSel);
				upDate = 0;
			}
            break;
        case BLOCKDAT2:
        case BLOCKDAT4:
        case BLOCKDAT6:
        case BLOCKDAT8:
           	if(cButton == IO_RIGHT && currentPos < BLOCKDAT8){nextPos++;}
            else if(cButton == IO_LEFT && currentPos > BLOCKDAT1){nextPos--;}
            else if(cButton == IO_ENTER){nextPos = BLOCKSEL;}
            else if(cButton == IO_UP)
            {
				i=cBlockDat[currentPos>>1];
				i = (i+1)&0x0F;
				cBlockDat[currentPos>>1] = ((cBlockDat[currentPos>>1]&0xF0) | i);
				Tag_Set_Block(&cBlockDat[0], cBlockSel);
				upDate = 0;
           	}
            else if(cButton == IO_DOWN)
            {
				i=cBlockDat[currentPos>>1];
				i = (i-1)&0x0F;
				cBlockDat[currentPos>>1] = ((cBlockDat[currentPos>>1]&0xF0) | i);
				cBlockDat[currentPos>>1] = (cBlockDat[currentPos>>1] | i);
				Tag_Set_Block(&cBlockDat[0], cBlockSel);
				upDate = 0;
			}
            break;
    	default:
     		break;
        }
        if(cButton>0 && cButton<6){uio_Release();}
    }
    uio_Release();
}

// *******************************************************************************
// Menu that allows All Data Block available to be written to the selected tag
// Includes verification 
// ******************************************************************************/
void rfid_WriteMenu_All(unsigned char Target_Tag, unsigned char Target_Reader)
{
    unsigned char cBlockSel = 1;
   	unsigned char i,j;
    
    unsigned char sBlockDat[9] = "00000000";
    unsigned char *sBlockDatPtr;
    unsigned char cBlockDat[4] = {0};
    unsigned char startBlock = 1, endBlock = 31;
    unsigned char startDisplayBlock = 1, endDisplayBlock = 7;
    unsigned char wError=0;
  	
	//**** Check selected tag and configure appropriate number of Blocks ****//
   	if(Target_Tag == 58)
   	{
   		startBlock = 0;
   		startDisplayBlock = 0;
   	}
   	else if(Target_Tag == 30){endDisplayBlock = 2;}
    else{endBlock = 7;}
                   
    nextPos = BLOCKSEL;
    upDate = 0;
    cPage = 0; 

	uio_Release();
    while(cButton != IO_F1 && cButton != IO_F2 && cButton != IO_F3 && cButton != IO_F4)
    {                                     
		// Menu Display 
		if(currentPos != nextPos || upDate == 0)
		{
 			currentPos = nextPos;
 			lcd_clear_area(SCRN_LEFT+1,SCRN_TOP+1,SCRN_RIGHT-1,SCRN_BOTTOM-1);
			if(Target_Tag == 30){lcd_put_fString(4, 2, sRFIDTAGPtr[0]);}
			else if(Target_Tag == 51){lcd_put_fString(4, 2, sRFIDTAGPtr[1]);}
			else if(Target_Tag == 52){lcd_put_fString(4, 2, sRFIDTAGPtr[2]);}
			else if(Target_Tag == 57){lcd_put_fString(4, 2, sRFIDTAGPtr[3]);}
			else if(Target_Tag == 67){lcd_put_fString(4, 2, sRFIDTAGPtr[4]);}
			else if(Target_Tag == 77){lcd_put_fString(4, 2, sRFIDTAGPtr[5]);}
			else if(Target_Tag == 70){lcd_put_fString(4, 2, sRFIDTAGPtr[6]);}
			else if(Target_Tag == 58){lcd_put_fString(4, 2, sRFIDTAGPtr[7]);}	 		
 			lcd_put_fString(32, 2, PSTR(" All"));

 			lcd_put_fString(82,2,PSTR("Page# "));				// Page Heading
 			lcd_put_fString(118,2,sNumPtr[cPage]);				// Page Number
			
		 	lcd_horz_line(SCRN_LEFT, SCRN_RIGHT, 11); 				// First Row Separator
	 		lcd_vert_line(11,SCRN_BOTTOM,10);					// First Col Separator
			lcd_invert_area(62,12,65,SCRN_BOTTOM-1);                                  // Center Separator
	 		lcd_vert_line(11,SCRN_BOTTOM,75);					// First Col Separator
	        

⌨️ 快捷键说明

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