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

📄 reader.c

📁 使用PIC16F628和U2280构建的门禁控制机,有原理图
💻 C
字号:


/***********************************************************************************************/
#pragma interrupt_level 0
void interrupt maibatsu(void)
/***********************************************************************************************/

{


//----------- WAS PIN CHANGE
	 
	if (RBIF && RBIE)		// was pin change
	 {

	 	datas = 	PORTB;	// REAd data TO prevent setting of the RBIF
	  	RBIF = 0;

// ---- splitter controls the current status of data acqusition
//	  		0 - first  edge detected, now wait second one, to fall in sequence
//	  		1 - if it was long pulse (positive or negative) - syncronization OK
//			2 - common data acquisition mode
	  	
	  	switch (splitter) {
	  		
	  		case 2:	{						// get data

				if (!TMR1IF)					// period to next simbol not expired yet
				  break;							// so this is still not the data edge

				TMR1ON = 0;	// stop TIMER1 to avoid scrolling of the results
								// and for more accurate time measurment

//------ roll five bytes and enter data FIFO (Most Significant Bit first)

	  			if (TMR1 > TIME_LONG)		// if wrong length - stop gathering data 
				 	splitter  = 0;			// restart everything from beginning
				 else
				 {		
		 			// times comparision is OK - get bit

					CARRY =  (datas & MASK_INPUT)? 0:1;	// get the CARRY
					STAC[0] = STAC[0];						// this will force the memory page
					asm("rlf _STAC+7,f");
					asm("rlf _STAC+6,f");
					asm("rlf _STAC+5,f");
					asm("rlf _STAC+4,f");					/// roll the 64 bit array
					asm("rlf _STAC+3,f");
					asm("rlf _STAC+2,f");
					asm("rlf _STAC+1,f");
					asm("rlf _STAC+0,f");
	
					counter_bits--;		// decrement bits
	 	
				 	if (counter_bits)		// check if all bits are captured
				 	 {
						 
						TMR1 = COUNT_TIME_NEXTA;		// load timer with next time period
						TMR1ON = 1;							// it's longer then SHORT period and shorter then LONG one
						TMR1IF = 0;							// TMR1IF is used to determine the data edge

				 	 }
				 	 else
				 	 {
			//========== ALL BITS ARE INTO THE BUFFER	- ISR routines are auto switched OFF			 	 	
				 	 	RBIE = 0;				// disable ISR anymore
				 	 	flag_DETECTED = 1;	// detection successful, now time to proceed it
				 	 }

		  			break;
		  		}	// was good time period 
	  		}		// end of case statement	- capture data


	  		case 1:	{		// was second edge, to determine 1 long pulse period
				TMR1ON = 0;		// pause TIMER1 for a while
	  			if (TMR1 < TIME_L1 || TMR1 > TIME_L2)	// if overflow or wrong length - stop 
	  			  {
	  			  	splitter = 0;
	  			  						// return to initial state to wait for sync
										// don't change splitter - still waiting of pulses
	  			 	TMR1 = 0;
	  			 	TMR1ON = 1;
	  			 	break;
	  			  }
	  			  
//------------ START SEQUENCE DETECTED ---------------------------------	  			 
				TMR1 = COUNT_TIME_NEXTB;	// load timer with next time period
				TMR1IF = 0;						// TMR1IF is used to determine the data period
				TMR1ON = 1;
				splitter++;						// now start getting bits

				counter_bits = 64;		// initialize counter of bits

				break;

	  		}	// end of looking for synchronization
	  		
	  		case 0:	{	  		
								// initial wait of pulse - was first pulse
								// now should wait some long pulse (POS or NEG)
								// for sinchronization to bit stream
								// looking for sinchronization - first edge detected
				TMR1 = 0;	// reset the timer to get how long is the next pulse
				
				splitter++;
	  			break;
	  		}

	  	}	// end of switch statement	
	 }		// end of RBIF routine
	 
}


⌨️ 快捷键说明

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