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

📄 readermodule1.c

📁 Use this program to decode the Manchester Code of the RFID. Validate the accessibility of detected c
💻 C
📖 第 1 页 / 共 5 页
字号:
			i=START_CARD_ADD;			
		}
		else		
			i=cardpos_last;
			
			
		lockoutcount=0;	
		for(cpos=i; cpos<=MAX_CARD_ADD; cpos+=4)
		{
			if(get_eeprom_bytes(cpos)==0xff)
			{
				wr=1;
				gcrec.Lockcount=0;
				break;				
			}	
		}	
		
		if(cpos>MAX_CARD_ADD)
			return 0;
		/*	//working part, disable on 12/19/2005 10:46PM
		cpos=32;
		lockoutcount=0;
		while(cpos<=MAX_CARD_PAGE)
		{
			if(get_eeprom_bytes(cpos)==0xff)	//0xff is the empty byte
			{
				wr=1;
				gcrec.Lockcount=0;
				break;
			}
			cpos+=4;
		}

		if(cpos>MAX_CARD_PAGE)
			return 0;		
		*/
	}
	
	if(wr)
	{
		//jah version
		if(cpos>cardpos_last)
		{
			cardpos_last=cpos;
			Flags.EmptySign=1;
		}
		
		fillintbuffer(buf, 4, cardpos_last);
		buf[4]=0;
		CommPutStr(buf);			

	
		write_block(cpos, &gcrec.CardNo[0], 3);	
		
        	cpos+=1;        	
        	  
        	cpos+=1;        	
        	        	
        	cpos+=1;
        	write_eeprom_bytes (cpos, lockoutcount);     

		/*
		//put_c('F');
		write_eeprom_bytes (cpos, gcrec.CardNo[0]);	//2
		//put_c(gcrec.CardNo[2]);
        	cpos+=1;
        	//put_c('C');
        	write_eeprom_bytes (cpos, gcrec.CardNo[1]);
        	//put_c(gcrec.CardNo[1]);
        	cpos+=1;
        	//put_c('K');
        	write_eeprom_bytes (cpos, gcrec.CardNo[2]);	//1
        	//put_c(gcrec.CardNo[0]);
        	cpos+=1;
        	write_eeprom_bytes (cpos, lockoutcount);        	       	
        	*/
        	return 1;		
	}	
	return 0;
}
/*******************************************************************************************
Function	:Delete this cardno from card database
Remarks		: and delete it by setting all byte to 0xff
return		:1-card exist and succefully deleted. 0-card no exist, cannot delete
********************************************************************************************/
unsigned char DeleteThisCard (void)
{
    if(FindThisCard ())
    { 
        	write_eeprom_bytes (cardpos, 0xff);
        	cardpos+=1;
        	write_eeprom_bytes (cardpos, 0xff);
        	cardpos+=1;
        	write_eeprom_bytes (cardpos, 0xff);
        	cardpos+=1;
        	write_eeprom_bytes (cardpos, 0xff);
        	        	      	        	        	
        	return 1;
    }
    return 0;
}
unsigned char JoinNibbletoChar (char* str)
{
	return (((str[0] << 4) & 0xf0) + str[1]);
}
char Process_Card(void)
{
char i=0;
unsigned long idata cno;
	if(CardDataIn)
	{
		SHD=SLEEP;	//12/4/2005 9:36AM
		/*
		for(i=0;i<=9;i++)
		{
			if(cardbytein[i]<=0x09)		put_c(cardbytein[i]+0x30);
			else 				put_c(cardbytein[i]+0x37);
						
		}		
		put_c('K');
		*/	
		cno    = (long) (JoinNibbletoChar (&cardbytein[8]));
        	cno    +=((long) (JoinNibbletoChar (&cardbytein[6]))) * 256L;
        	cno    +=((long) (JoinNibbletoChar (&cardbytein[4]))* 65536L);        	
        	if(cno>=1000000L)	cno = cno - ((cno / 1000000L)*1000000L);	//kk get thru after long been 
        	longtos (gcrec.CardNo, &cno);						//perplexed by the old way 23/10/04				
        	CommPutStr(gcrec.CardNo);
		Flags.gnewcard = 1;
		CardDataIn=0;
		SHD=WAKEUP;	//12/4/2005 9:36AM
		return 1;
	}
	return 0;
}
void initmcu(void)
{
/*------------------------------------------------
Setup the serial port for 19200 baud at 14.7456MHz.
------------------------------------------------*/
TMOD=0x00;			//clear all
PCON	=0x80;      		// 0x80 Baudrate double
SCON  	= 0x40;	//0x50	        /* SCON: mode 1, 8-bit UART, enable rcvr      */
TMOD 	|= 0x20;               	/* TMOD: timer 1, mode 2, 8-bit reload        */
TH1   = 0xF5;// 20Mhz 9600 //252;                	/* TH1:  reload value for 19200 baud @ 16MHz   */
TR1   = 1;                  	/* TR1:  timer 1 run                          */
TI    = 1;                  	/* TI:   set TI to send first char of UART    */
ES	=0;	//1

//Timer 0, Mode 2 Interrupt configuration
//TMOD |=0x02;			//set timer0, 8 bit auto reload
//TH0 = -146;    			/* 200us  */
//TL0 = -146;			//interrupt every 25 clock signal (8us each)
TMOD |=0x01;			// 16 bits timer selected
TH0 = 0xff;//(65536 - 146) / 256;
TL0 = 0x84;//-123;//(65536 - 146) % 256;
ET0 = 1;                      	/* Enable Timer 0 Interrupts */
TR0 = 0;                      	/* Start Timer 0 Running */
/*-----------------------------------------------
Configure INT0 (external interrupt 0) to generate
an interrupt on the falling-edge of /INT0 (P3.2).
Enable the EX0 interrupt and then enable the
global interrupt flag.
-----------------------------------------------*/
IT0 = 1;   			// Configure interrupt 0 for falling edge on /INT0 (P3.2)
IT1 = 0;
EX1 = 0;			//disabled EX1 Interrupt
EX0 = 1;   			// Enable EX0 Interrupt

/*--------------------------------------
Set Timer2 for 16-bit auto-reload.
The timer counts to 0xFFFF, overflows,
is reloaded, and generates an interrupt.
--------------------------------------*/
T2MOD = 0x00;
T2CON = 0x00;                /* 10000000 */

/*--------------------------------------
Set the reload values to be 1000 clocks.
--------------------------------------*/
TL2 = RCAP2L;
TH2 = RCAP2H;

RCAP2L = 0x37;			//0.6us for 1 clock cycle and 45000 cycles required to complete 27ms of 
RCAP2H = 0x50;			//interval for wiegand output. Thus, FFFF-AFC8(45000)=0x3750	

ET2 = 1;                      /* Enable Timer 2 Interrupts */
TR2 = 1;                      /* Start Timer 2 Running */

EA = 1;    			// Enable Global Interrupt Flag	
EXT=1;
}
/***************************************************************************************************
This is the keypad modified by jah for the latest keypad portion.
The cold start still using '4' & '7'

****************************************************************************************************/
unsigned char scankey(void)
{
idata unsigned char datain,shifter,i,addr=0x0E,COL,ROW,OO=0,j;
idata unsigned char keypad[3][4]=     {	{'#','9','6','3'},
					{'0','8','5','2'},
					{'*','7','4','1'}};	//change for the wrong keypad design
				
	P0=0x0F;//PCF8574_write(addr,0x0F);         																														
	datain = P0;//PCF8574_read(addr, data);
	shifter = 0x01;
	for(i=0;i<3;i++)  //4                                      
	{
		if(!(datain & shifter))
		{     
			COL=(2-i);    //3, so that for 000x 0000 and 0000 000x each represent third place of the key matrice                      
	
			P0=0xF0;//PCF8574_write(addr,0xF0);           
																															
			datain = P0;//PCF8574_read(addr, data);
		
			shifter = 0x10;
			for(j=0;j<4;j++)  //4                                      
			{
				if(!(datain & shifter))
				{     							
					if(!bit_keyhold || ColdStartCheck==1)        //prevent from detecting multiple input from bit_keyhold ing 
					{						
						ROW=(3-j);    		// so that for 000x 0000 and 0000 000x each represent third place of the key matrice                                						
						ClearBuzz();
						if(OO=='*')		//'#'Check Cold start pattern						
							if(keypad[COL][ROW]=='#')	//'0',*																	
								return 1;
																						
						OO	=keypad[COL][ROW];												
						put_c(OO);	//11/10/2005 9:00PM																			
						bit_keyhold=1; 
						
						if(!ColdStartCheck)	return OO;                                   												
					}
					else return 0;                                                  																									
				}       
				shifter = shifter << 1;
			}
		}       
		shifter = shifter << 1;
	}
	bit_keyhold=0;       
	return 0;   
}
/*************************************************************************************************
This is kk original version.
**************************************************************************************************/
/*
unsigned char scankey(void)
{
idata unsigned char datain,shifter,i,addr=0x0E,COL,ROW,OO=0;
idata unsigned char keypad[4][4]=     {	{'1','2','3','A'},
					{'4','5','6','B'},
					{'7','8','9','C'},
					{'*','0','#','D'}};
				
	P0=0x0F;//PCF8574_write(addr,0x0F);           
																														
	datain = P0;//PCF8574_read(addr, data);

	shifter = 0x01;
	for(i=0;i<4;i++)                                        
	{
		if(!(datain & shifter))
		{     
			COL=(3-i);    // so that for 000x 0000 and 0000 000x each represent third place of the key matrice                      
	
			P0=0xF0;//PCF8574_write(addr,0xF0);           
																															
			datain = P0;//PCF8574_read(addr, data);
		
			shifter = 0x10;
			for(i=0;i<4;i++)                                        
			{
				if(!(datain & shifter))
				{     							
					if(!bit_keyhold || ColdStartCheck==1)        //prevent from detecting multiple input from bit_keyhold ing 
					{						
						ROW=(3-i);    		// so that for 000x 0000 and 0000 000x each represent third place of the key matrice                                						
						ClearBuzz();
						if(OO=='#')		//Check Cold start pattern						
							if(keypad[COL][ROW]=='0')	//*																	
								return 1;
																						
						OO	=keypad[COL][ROW];												
						put_c(OO);	//11/10/2005 9:00PM																			
						bit_keyhold=1; 
						
						if(!ColdStartCheck)	return OO;                                   												
					}
					else return 0;                                                  																									
				}       
				shifter = shifter << 1;
			}
		}       
		shifter = shifter << 1;
	}
	bit_keyhold=0;       
	return 0;   
}
*/

unsigned char CheckKeyTimeOut (void)
{
	
	if (keytimeout == 1)
    	{      		        	
        	keytimeout=0;
        	ShowError();
        	//if(Flags.WaitingKey)
        	LED_GREEN=LED_OFF;			//to off the waiting key         	
        	return 1;
    	}
    	//kickdog();

    	return 0;
}

void flush_keypad(void)
{
	key_count       = 0;	
	keytimeout      = 0;	
}

void ReloadKeyTimeOut (void)
{		
    	//keytimeout      = 175;	//approximate 5 seconds
    	//keytimeout	= 1050;		//appro. 30 sec requested 
    	keytimeout	= 400;		//upon request to shortened time up time.
}

void AsterikResetKey (void)
{
    key_count = 0;    
    //KeyChar [key_count ++]='*';
    flush_keypad();
    //ReloadKeyTimeOut ();
    LED_GREEN=LED_OFF;
    //LED_RED=LED_OFF;	
    if (Flags.WaitingKey)
    {
    	ShowError ();    	
    }
}

void AddNewKeyToBuffer (unsigned char ch)
{	
//	unsigned int pg;	//testing
	
	
	beep(1);
	
	if (key_count>=MAXKEYCHAR)
	{
    		if (ch == '#')
    		{        	
    			if(KeyChar [key_count-1]=='#')	
    			{
    				AsterikResetKey ();
    				KeyChar [key_count ++]='#';
    			}
    			
        	}
        	else                	ShowError();
        
        	return;
	}
    	else if (ch == '*')
    	{    		
            	AsterikResetKey ();
                return;            	
    	}
    	else if(ch=='#')
    	{
    		if(key_count)
    		{
    			if(KeyChar [key_count-1]=='#')
    			{	
    				
    				/*KeyChar [key_count ++]='#';
    				put_c('L');
    				if(KeyChar[0]=='#' )	put_c('N');
    				if(KeyChar[1]=='#' )	put_c('M');*/
    				ShowError();			
    				return;
    			}
    			/*else     
    			{
    				if(MainMenuItem!=6)		//not in install card mode
    				{	    						    				    				    					
    					if(MainMenuItem >0)    					
    						ShowErrInMainEntered();
    						
    					else ShowError();
    					return;
    				}
    			}*/
    		}	    		
    	}

    	KeyChar [key_count ++]=ch;

    	ReloadKeyTimeOut ();
}   

void Process_LocalKeypad(void)
{
char newkey;	

   	newkey=scankey();
   	
   	if (newkey)   		    AddNewKeyToBuffer (newkey);
   	
   	if (CheckKeyTimeOut ())	    return;
}
void ResetUserEvent (void)
{
	CardDataIn 	= 0;
    	Flags.gnewcard 	= 0;
	SubMenuItem 	= 0;
	MainMenuItem 	= 0;
	Flags.WaitingKey= 0;	
	flush_keypad();
}
/****************************************************************************************************
Initialize or restore the Database for EERPOM, its only happen after system cold start
*****************************************************************************************************/
void InitDB (void)
{
	idata char i;
	
	SystemDatabase.OperationMode   |= O_CARD;	//kk 0707 as requested	
    	SystemDatabase.MasterPin[0]   = 0x33;
	SystemDatabase.MasterPin[1]   = 0x33;
    	SystemDatabase.MasterPin[2]   = 0x33;
	
    for(i=0;i<MAX_PINNO;i++)
    {
    SystemDatabase.AutoPin [i][0]  = 0;
    SystemDatabase.AutoPin [i][1]  = 0;
    }

    SystemDatabase.DoorOpenTime    = 10;		//origin 10 sec
    SystemDatabase.LockReleaseTime = 5;		//orign = 5 sec
		

     RestoreCardPos();	//12/18/2005 3:54PM
    WriteSysDB ();
    //mess_lcd(0, "Initialise DB");   
}
/********************************************************************************
write all the System DB into EEPROM
**********************************************************************************/
void WriteSysDB(void)
{	
	idata unsigned char i;
	write_eeprom_bytes(0,SystemDatabase.OperationMode);

    	write_eeprom_bytes(1,SystemDatabase.MasterPin[0]);
	write_eeprom_bytes(2,SystemDatabase.MasterPin[1]);

⌨️ 快捷键说明

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