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

📄 readermodule1.c

📁 Use this program to decode the Manchester Code of the RFID. Validate the accessibility of detected c
💻 C
📖 第 1 页 / 共 5 页
字号:
                	bitcount  = 0;					//reset all parameter, search for the 
			nibin     = 0;					//correct start pattern			
            	}
            }
        }    	
	if(cbitcount > 66)
	{
		cbitcount	=	0;
    		//CardDataIn      = 	1;
        	rdr 		= 	0;	
        	columnparity	= 	nibin&0x0f;
        	cardtime	= 	18;
        	bytecount=0;
        	startpattern	=	0;
        	bitcount  = 0;						//reset all parameter, search for the 
		nibin     = 0;						//correct start pattern		
	}		
	clock_isr_counter1=0;		
	
	}

}
/*=============================================================================
=============================================================================*/
/******************************************
serial transmit interrupt
*********************************************/
/*
void serial (void) interrupt 4 
{ 
	
	if (RI)  
  	{                         		
    		comsinbuffer = SBUF;            
    		RI = 0;                          
  	}
}
*/
void fillintbuffer (char* buf, char len, unsigned int datano)
{
	idata char i, j, t;
    idata unsigned long mult;

    mult = 1U;
    for (i=len, j=1; i>0; i--, j++)
    {
    	t = (datano % (mult*10L)) / mult;
        mult *= 10L;
        buf [i-1] = t + '0';
		// + '0';
    }
}
void Delay_ms(unsigned char time)
{
	idata unsigned char j ;
	idata unsigned int i;
	
	
	for(j=0;j<time;j++)
	{
		for(i=0;i<1650;i++)
		{
		}
	}
}

void ClearKeyBuffer (void)
{
idata unsigned char i;
	for(i=0;i<=9;i++)
		KeyChar[i]=0;			
}

void ShowError (void)
{
	put_c('E');	//kk test
	beepbeep(3);
	masterpinCount=0;
	
	LED_GREEN=LED_OFF;
	//LED_RED = LED_OFF;
	ClearKeyBuffer();
    	ResetUserEvent();
}
void put_c(unsigned char buf)
{
	
#ifndef TESTING
	return;
#endif  
    
    TI=0;        
    SBUF=buf;
    while(!TI);
	        
}

void beep (unsigned char duration)
{
   buzzer_type=1;
   buzz_duration = duration;
   buzz_counter = 1;
}
void beepbeep (unsigned char count)
{
   buzzer_type = (count<<1)  ;		//(count <<1)-1
}
void ClearBuzz(void)
{
	buzzer_type = 0;
    buzz_counter  = 0;
    buzz_duration = 1;
}
/***************************************************************************************************
Function	:Process_Input
		:taking care of tamper, push button and door sensor
****************************************************************************************************/
void Process_Input(void)
{
unsigned char i;	
	if(DOORSENSOR) // Door Open
     	{
    		if (!dooropentime && !(SystemDatabase.OperationMode & O_SECURITYOFF))
        		Flags.DoorOpen  = 1;
         	else if (dooropentime)
         	{
        		Flags.doorwasopened = 1;
        		Flags.DoorOpen  = 0;
         	}
         	door_relay_duration = 0;
    	}
    	else 
    	{
    		if(Flags.DoorOpen)
    		{
    			Flags.DoorOpen=0;
    			//LED_GREEN=LED_OFF;	//1/10/2006 12:43PM
			//LED_RED = LED_OFF;
    			ClearBuzz();
    		}	
    	}
    	if(!PUSHBUTTON)
    	{
    		for(i=0;i<250;i++);	//debouncing
    		if(!PUSHBUTTON )
    		{	
    			turn_relay_on();		
			beep(4);
			ResetUserEvent();	    		
		}	
    	}
    	
    	if(DOORSENSOR || TAMPER)//if(!TAMPER || DOORSENSOR)
    	{
    		ALARMRELAY=RELAY_ON;
    		
    	}
    	else
    		ALARMRELAY=RELAY_OFF;
    		
    	/*
    	if(Flags.DoorOpen)//kk 080106
    	{
    		beep(3);
    	}
    	*/
}

void CommPutStr(char* str)
{
unsigned char idata i=0;

	while(str[i])
		put_c(str[i++]);	
	
}
void process_led(void)
{

	if(Flags.WaitingKey)	LED_GREEN=LED_ON;	
	
}
/***************************************************************************************************
Handle buzzer task
****************************************************************************************************/
void process_buzzer(void)
{
	if (Flags.DoorOpen)
  	      ClearBuzz();
  	else if (!buzzer_type)
  	{
        	BUZZER = OFF;
	    	ClearBuzz();
	    	return;
    	}    	
    	else
    	{	
		 if (++buzz_counter >=BUZZCOUNTER * 2 * buzz_duration)// 200// BUZZCOUNTER * buzz_duration*2)
        	{
    	    		buzzer_type --;
            		buzz_counter = 1;
  	 	}

        	if (buzzer_type & 0x01)
            		BUZZER = ON;//ON;//12/13/2005 10:52PM
        	else
            		BUZZER = OFF;   
            
         }
}
/************************************************************************************
I2C start for EEPROM 24C64C
Dont forget to define the PIN for SCL and SDA
*************************************************************************************/
void I2C_Start(void)
{
        SCL=HIGH;
	SDA=HIGH;
	SDA=LOW;
	SCL=LOW;
}
/************************************************************************************
I2C stop for EEPROM 24C64C
*************************************************************************************/
void I2C_Stop(void)
{
	SDA = LOW;
	SCL = HIGH;
	SDA=HIGH;
	//Delay_us(1);	//11/3/2005 4:56PM
}
/********************************************************
Function	:Shift out a byte to the AT24Cxx, most significant bit first.
		:SCL, SDA expected low on entry. Return with SCL low.
Remarks		:retun 0-success, 1-success			
*********************************************************/
char I2C_Write(unsigned char byte)
{
	unsigned char i;	
	
	for(i=0; i <8; i++)
	{		
		SDA=(byte<<i) & 0x80; //shift 1 bit out and store in temp		
		SCL=HIGH;	//to clock the data in	
		SCL=LOW; 		
	}

	SDA = HIGH;
	SCL = HIGH;
	i=SDA;
	SCL=LOW;
	return i;	//return 0 -success
			//return 1-fail
	
}
/***************************************************************************************************
Function	:Shift in a byte from the AT24Cxx, most significant bit first.
		:SCL expected low on entry. Return with SCL low.
***************************************************************************************************/
unsigned char I2C_Read(void)
{
	char i;
	unsigned char bitin=0, bytein=0;
	
	for(i=0; i<8; i++)
	{		
		SDA=HIGH;
		SCL=HIGH;
		bitin=SDA;
		bytein|=bitin<<(7-i);
		SCL=LOW; 
		bitin=0;				
	}
	return bytein;
}
/*************************************************************************************************
Function	:Clock out an acknowledge bit (low).
		:SCL expected low on entry. Return with SCL, SDA low.
*************************************************************************************************/
/*
void ACK(void)//ACK
{
	SDA=LOW;	
	SCL=HIGH;	
	SCL=LOW;	
}
*/
/*************************************************************************************************
Functon		:Clock out a negative acknowledge bit (high).
		:SCL expected low on entry. Return with SCL low, SDA high.
**************************************************************************************************/
void NAK(void)	//no ACK
{
	SDA=HIGH;
	SCL=HIGH;
	SCL=LOW;	
}
/**************************************************************************************************
Write to I2C EEPROM
***************************************************************************************************/
char write_eeprom_bytes(unsigned int add, unsigned char dataout)
{
	idata unsigned char addressbyte;
	
	addressbyte=high_byte(add);
	
	I2C_Start();
	
	if(I2C_Write(0xA0))
		return 0;	
	
	if(I2C_Write(addressbyte)) //send address high byte
		return 0;
	
	if(I2C_Write((unsigned char) add))
		return 0;			
	
	if(I2C_Write(dataout))
		return 0;
		
	I2C_Stop();
	Delay_ms(3);

	return 1;
}
/**************************************************************************************************
Read from  I2C EEPROM
***************************************************************************************************/   
unsigned char get_eeprom_bytes (unsigned int add)
{
	unsigned char addressbyte, datain;
	
	addressbyte=high_byte(add);	
	I2C_Start();	

	I2C_Write(0xa0);
	I2C_Write(addressbyte);	
	I2C_Write((unsigned char) add);
	I2C_Start();	
	I2C_Write(0xa1);
	datain=I2C_Read();	
	NAK();		//send negative ack
	I2C_Stop();
	return datain;
}
/**************************************************************************************************
Read the next following bytes
remarks	:Dont have to send address again(the fastest way to read bytes) !
***************************************************************************************************/
unsigned char get_eeprom_bytes1 (void)
{
	unsigned char datain;

	I2C_Start();	
	I2C_Write(0xA1);	
	datain=I2C_Read();
	NAK();		//send negative ack
	I2C_Stop();	
	
	return datain;
}
/***************************************************************************************************
Page write- write from a given page number
****************************************************************************************************/
/*
char write_block(unsigned char page, unsigned char *dataout, char count)
{
	idata unsigned int startaddr;
	unsigned char i, addressbyte;
	
	startaddr=page*32;
	addressbyte=high_byte(startaddr);
		
	I2C_Start();
	if(I2C_Write(0xA0))
		return 0;	
	
	if(I2C_Write(addressbyte)) //send address high byte
		return 0;
	
	if(I2C_Write((unsigned char) startaddr))
			return 0;	
	
		
	for(i=0;i<count;i++)
	{	
		if(I2C_Write(dataout[i]))
			return 0;
	}
	I2C_Stop();
	Delay_ms(2);

	return 1;
}
*/
/**********************************************************************************8
write from a given start address
***********************************************************************************/
char write_block(unsigned int startaddr, unsigned char *dataout, char count)
{
	//idata unsigned int startaddr;
	unsigned char i, addressbyte;
	
	//startaddr=page*32;
	addressbyte=high_byte(startaddr);
		
	I2C_Start();
	if(I2C_Write(0xA0))
		return 0;	
	
	if(I2C_Write(addressbyte)) //send address high byte
		return 0;
	
	if(I2C_Write((unsigned char) startaddr))
			return 0;	
	
		
	for(i=0;i<count;i++)
	{	
		if(I2C_Write(dataout[i]))
			return 0;
	}
	I2C_Stop();
	Delay_ms(2);

	return 1;
}

void ShowErrInMainEntered (void)
{	
	//put_c('s');
	beepbeep(3);
	Flags.WaitingKey = 1;
	key_count       = 0;		//kk 25-6-06
	ReloadKeyTimeOut();
			
}

/************************************************************************************
Function	:Install this cardno into card database(eeprom)
Remarks		:searching for database, if card found then reinstall
		:return 1-successfully install, 0-failed, due to oversize
************************************************************************************/
unsigned char InstallThisCard(void)
{
	unsigned int cpos;
	unsigned char wr=0;
	unsigned char buf[5];
	unsigned int i;	//12/19/2005 10:47PM
	
			
	if(FindThisCard())//if card already exist, then its must be install new pin in
	{		  			
		wr=1;		
		cpos=cardpos;  	
		card_exist=1;	      
	}
	else	//if new card so it is the first time install, Pin is set to 0xff 
	{
		if(!Flags.EmptySign)
		{

⌨️ 快捷键说明

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