Ejemplo n.º 1
0
void Control()
{
	static uchar i=0;
	i++;
	if(i>10)
	{
		i=0;
		UartPutByte('T');
		UartPutByte('e');
		UartPutByte('m');
		UartPutByte('p');
		UartPutByte(':');
		UartPutByte(temp_dat/10+'0');	
		UartPutByte(temp_dat%10+'0');
		UartPutByte('.');
		UartPutByte(temp_dot+'0');
		UartPutByte('\n');
	}
	
 	if(beep_flag>0)
	{
		if(i<5)
		BEEP=0;
		else
		BEEP=1;	
	}
	else
	BEEP=1;

}
Ejemplo n.º 2
0
void
Type2ReadTwoBlocks(u08_t rd2b)
{	
	u08_t i = 0, command[4];
	
	buf[0] = 0x8F; 						// reset FIFO
	buf[1] = 0x91; 						// send with CRC
	buf[2] = 0x3D; 						// write continuous from register 
	buf[3] = 0x00;						// value for register 1D
	buf[4] = 0x20;						// register 1E (# of bytes to be transmitted)
	buf[5] = 0x31;						// RD2B command
	//buf[6+30] = rd2b;						// addressed block
	
	buf[200] = 80;							// tell apart from Ack/Nack
	
	rx_error_flag = 0x00;
	
	command[0]	= SPECIAL_FUNCTION;
	command[1]	= SPECIAL_FUNCTION;
	Trf797xReadSingle(&command[1], 1);
	command[1] |= BIT2;						// enable 4-bit receive
	
	McuCounterSet();						// TimerA set 
	COUNT_VALUE = COUNT_1ms * 5;			// 5ms 
	IRQ_CLR;								// PORT2 interrupt flag clear 
	IRQ_ON;
	
	Trf797xReset();							// FIFO has to be reset before recieving the next response

	Trf797xRawWrite(&buf[0], 7);			// set Special Function Register
	
	i_reg = 0x01;
	START_COUNTER;							// start timer up mode
	irq_flag = 0x00;
	while(irq_flag == 0x00)					// wait for end of TX interrupt
	{
	}
	
	Trf797xWriteSingle(command, 2);			// enable 4-bit receive
	
	rxtx_state = 1;						// the response will be stored in buf[1] upwards
		
	McuCounterSet();						// TimerA set
	COUNT_VALUE = COUNT_1ms * 10;    
	START_COUNTER;							// start timer up mode
	i_reg = 0x01;
	while(i_reg == 0x01)					// wait for interrupt
	{
	}

	if(rx_error_flag == 0x02)
	{	
		i_reg = 0x02;
	}
	
	if(i_reg == 0xFF)						// recieved response
	{	
		UartPutChar('[');
		for(i = 1; i < rxtx_state; i++)
		{
			UartPutByte(buf[i]);
		}
		UartPutChar(']');
	}
	else if(i_reg == 0x02)
	{	

		if(buf[200] < 0x20)					// not acknowledged
		{	
			UartSendCString("[NACK]");
		}
		else								// collision occured
		{
			UartPutChar('[');
			UartPutChar('z');
			UartPutChar(']');
		}
	}
	else if(i_reg == 0x00)					// no responce
	{	
		UartPutChar('[');
		UartPutChar(']');
	}
	else
	{
	}
	command[0]	= SPECIAL_FUNCTION;
	command[1]	= SPECIAL_FUNCTION;
	Trf797xReadSingle(&command[1], 1);
	command[1] &= ~BIT2;
	Trf797xWriteSingle(command, 2);			// disable 4-bit receive
}
Ejemplo n.º 3
0
void
iso14443bAnticollision(u08_t command, u08_t slots)
{
	u08_t	i = 0, collision = 0x00, j, found = 0;
	u32_t	k = 0;
	#ifdef ENABLE_HOST
		//u08_t rssi[2];
	#endif
	
	rx_error_flag = 0x00;

	buf[0] = 0x8F;
	buf[1] = 0x91;
	buf[2] = 0x3D;
	buf[3] = 0x00;
	buf[4] = 0x30;
	buf[5] = 0x05;
	buf[6] = 0x00;

	if(slots == 0x04)
	{	
		Trf797xEnableSlotCounter();
	}

	buf[7] = slots;

	if(command == 0xB1)
	{	
		buf[7] |= 0x08; 					// WUPB command else REQB command
	}

	i_reg = 0x01;

	Trf797xRawWrite(&buf[0], 8);

	IRQ_CLR;								// PORT2 interrupt flag clear
	IRQ_ON;

	j = 0;
	while((i_reg == 0x01) && (j < 2))
	{
		j++;
		McuCounterSet();			// TimerA set
		COUNT_VALUE = COUNT_1ms * 2;		// 2ms
		START_COUNTER;
		irq_flag = 0x00;
		while(irq_flag == 0x00)
		{
		}
	}										// wait for end of TX

	i_reg = 0x01;
	
	McuCounterSet();				// TimerA set
	COUNT_VALUE = COUNT_1ms * 2;			// 2ms
	START_COUNTER;

	for(i = 1; i < 17; i++)
	{	
		rxtx_state = 1;						// the response will be stored in buf[1] upwards

		while(i_reg == 0x01)				// wait for RX complete
		{	
			k++;
			if(k == 0xFFF0)
			{	
				i_reg = 0x00;
				rx_error_flag = 0x00;
				break;
			}
		}

		if(rx_error_flag == 0x02)
		{	
			i_reg = rx_error_flag;
		}
		
		if(i_reg == 0xFF)					// recieved SID in buffer
		{	
			if(stand_alone_flag == 1)
			{	
				found = 1;
			}
			else
			{	
				#ifdef ENABLE_HOST
				
					UartPutChar('[');
					for(j = 1; j < rxtx_state; j++)
					{	
						UartPutByte(buf[j]);
					}
					UartPutChar(']');

					//UartPutChar('(');
					//UartPutByte(rssi[0]);
					//UartPutChar(')');
					UartPutCrlf();
				#endif
			}
		}
		else if(i_reg == 0x02)				// collision occured
		{	
			if(stand_alone_flag == 0)
			{	
				#ifdef ENABLE_HOST
					UartPutChar('[');
					UartPutChar('z');
					UartPutChar(']');
				#endif
			}
			collision = 0x01;
		}
		else if(i_reg == 0x00)				// slot timeout
		{	
			if(stand_alone_flag == 0)
			{	
				#ifdef ENABLE_HOST
					//UartPutChar('[');
					//UartPutChar(']');
				#endif
			}
		}
		else
		{
		}

		if((slots == 0x00) || (slots == 0x01) || (slots == 0x02) || ((slots == 0x04) && (i == 16)))
		{	
			break;
		}

		iso14443bSlotMarkerCommand(i);

		i_reg = 0x01;

		if(stand_alone_flag == 0)
		{	
			#ifdef ENABLE_HOST
				//UartPutCrlf();
			#endif
		}
	}										// for

	if(slots == 0x04)
	{	
		Trf797xDisableSlotCounter();
	}

	IRQ_OFF;
	
	if(remote_flag == 0)
	{
		if(found == 1)
		{	
			LED_14443B_ON;
		}
		else
		{	
			LED_14443B_OFF;
		}
	}

	if(collision)
	{	
		iso14443bAnticollision(0x20, 0x02);	// Call this function for 16 timeslots
	}
}											// iso14443bAnticollision