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

📄 rfid.c

📁 自己作的的射频卡项目的源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
					set_timer0(106);//对计数器0赋初值
					Time_Out=0;
					if(input(RF_DATA_IN)==1)
					temp=0;
					else
					temp=1;
					temp1=(temp1<<1)|temp;
					BitCounter--;
				}while(BitCounter);
				*(PData+ByteCounter)=temp1;
				ByteCounter=ByteCounter+1;
			}while(ByteCounter<10);
			set_timer0(106);
			Time_Out=0;
			pc=4;
			temp1=0;
			do
			{
				delay_us(445);
				if(input(RF_DATA_IN)==1)
				temp=1;
				else
				temp=0;
				Star_Timer=1;
				while(input(RF_DATA_IN)==temp)
				{
					if(Time_Out==1)
						{
							Star_Timer=0;//停止计数器
							Time_Out=0;
							goto	str;
						}
				}
				Star_Timer=0;
				set_timer0(106);//对计数器0赋初值
				Time_Out=0;
				if(input(RF_DATA_IN)==1)
				temp=0;
				else
				temp=1;
				temp1=(temp1<<1)|temp;
				pc--;
			}while(pc);
			temp1=temp1<<1;
			normal_Data[10]=temp1;
			delay_us(445);
			set_timer0(106);//对计数器0赋初值
			Time_Out=0;
			if(input(RF_DATA_IN)==1)
			temp=1;
			else
			temp=0;
			Star_Timer=1;
			while(input(RF_DATA_IN)==temp)
				{
					if(Time_Out==1)
						{
							Star_Timer=0;//停止计数器
							Time_Out=0;
							goto	str;
						}
				}
			Star_Timer=0;
			set_timer0(106);//对计数器0赋初值
			Time_Out=0;
			if(input(RF_DATA_IN)==1)
			temp=0;
			else
			temp=1;
			delay_us(1);
			if(temp==0)
			{
				
				PData=normal_Data;
				PData1=sendData;
				for(ByteCounter=0;ByteCounter<11;ByteCounter++)//有5个字节数据
       			{
              		temp=(((*(PData+ByteCounter))&0x10)>>4)+(((*(PData+ByteCounter))&0x08)>>3)+(((*(PData+ByteCounter))&0x04)>>2)+(((*(PData+ByteCounter))&0x02)>>1);  
					if(ByteCounter==10)
					{   
						temp1=*(PData+ByteCounter)&0x1f;
						*(PData1+ByteCounter)=temp1;
              			
       				}
					else
					{
						if((temp&0x01)==((*(PData+ByteCounter))&0x01))//效验高4位
              			{
							temp1=*(PData+ByteCounter)&0x1f;
							*(PData1+ByteCounter)=temp1;
							temp1=(temp1&0x1e)>>1;
							*(PData+ByteCounter)=temp1;
              			}
              			else
              			{
                     	normal_Clern_Number();//并清所有数据
						goto	str;
              			}
					}
				}
				output_high(PIN_C5);
				delay_ms(1000);
				output_low(PIN_C5);
				Check_Data_bit=1;
				SendCmd(0xc0);
				putcLCD(' ');
				putcLCD(' ');
				putcLCD(' ');
				putcLCD(' ');
				putcLCD(' ');
				putcLCD('s');
				putcLCD('u');
				putcLCD('c');
				putcLCD('c');
				putcLCD('e');
				putcLCD('s');
				putcLCD('s');
			}
			else
			{
				normal_Clern_Number();
				goto	str;
			}
		}
	}	
}
//***************************************************************
void normal(void)
{
	int8	temp;
	delay_ms(100);
	normal_Inti();
ni:
	normal_Recive();
	if(Check_Data_bit==0)
	goto	ni;
	else
	{
		Check_Data_bit=0;
		simulation_Inti();
		while(1)
		{	
			simulation();
		}
	}
}
//******************************************************************************************
//                                          模拟卡片模块
//******************************************************************************************
#INT_TIMER3
void TIMER3_isr(void)
{
	over=1;
	set_timer3(65082);
}
void simulation_Inti(void)
{
	setup_timer_3(T3_INTERNAL|0x00);
	set_timer3(65082);
	over=0;
	enable_interrupts(INT_TIMER3);
	enable_interrupts(global);
	CFE_DIR=0;
}
void simulation(void)
{
	int8	header,*PData,count,i,run;
	tim3Str=1;
	for(header=0;header<9;header++)
	{
		tim3Str=1;
		CFE=1;
		delay_us(251);
		CFE=0;
		while(over==0);
		over=0;
		tim3Str=0;
	}
	PData=sendData;
	for(count=0;count<11;count++)
	{	
		temp=*(PData+count);
		temp=temp<<3;
	//	delay_us(1);
		for(i=0;i<5;i++)
		{
			run=temp&0x80;
			if(run==0)
			{
				tim3Str=1;
				CFE=0;
				delay_us(256);
				CFE=1;
			}
			else
			{
				tim3Str=1;
				CFE=1;
				delay_us(256);
				CFE=0;
			}
			temp=temp<<1;
			while(over==0);
			over=0;
			tim3Str=0;
		}
	}
}
//******************************************************************************************
//                                          主函数模块
//******************************************************************************************
void InitADKEY(void)
	{
		#asm
		movlw	0x41
		movwf	ADCON0
		movlw	0x02
		movwf	ADCON1
		bsf		TRISA,0
		#endasm
	}
int8 GetADKEY(void)
{
		int8	ADKEYH;
		int8	KEYRES;
		#asm
			bsf		ADCON0,GO
		IsOver:
			btfsc	ADCON0,GO
			goto	IsOver
			movf	ADRESH,W
			movwf	ADKEYH
			movlw	0x31
			movwf	KEYRES
		KEY1:	
			movlw	0xcb
			subwf	ADKEYH,W
			btfss	STATUS,C
			goto	KEY2
			goto	KEYOUT
		KEY2:
			incf	KEYRES,F
			movlw	0xa8
			subwf	ADKEYH,W
			btfss	STATUS,C
			goto	KEY3
			goto	KEYOUT
		KEY3:
			incf	KEYRES,F
			movlw	0x8f
			subwf	ADKEYH,W
			btfss	STATUS,C
			goto	KEY4
			goto	KEYOUT
		KEY4:
			incf	KEYRES,F
			movlw	0x7c
			subwf	ADKEYH,W
			btfss	STATUS,C
			goto	KEY5
			goto	KEYOUT
		KEY5:
			incf	KEYRES,F
			movlw	0x6f
			subwf	ADKEYH,W
			btfss	STATUS,C
			goto	KEY6
			goto	KEYOUT
		KEY6:
			incf	KEYRES,F
			movlw	0x63
			subwf	ADKEYH,W
			btfss	STATUS,C
			goto	KEY7
			goto	KEYOUT
		KEY7:
			incf	KEYRES,F
			movlw	0x5a
			subwf	ADKEYH,W
			btfss	STATUS,C
			goto	KEY8
			goto	KEYOUT
		KEY8:
			incf	KEYRES,F
			movlw	0x53
			subwf	ADKEYH,W
			btfss	STATUS,C
			goto	KEY9
			goto	KEYOUT
		KEY9:
			incf	KEYRES,F
			movlw	0x4c
			subwf	ADKEYH,W
			btfss	STATUS,C
			goto	KEY0
			goto	KEYOUT
		KEY0:
			movlw	0x30
			movwf	KEYRES
		KEYOUT:
			movf	KEYRES,W
		#endasm
		return	KEYRES;
}
void InitLCD(void)
{
	LCD_DB7_DIR=0;
    LCD_DB6_DIR=0;
    LCD_DB5_DIR=0;
    LCD_DB4_DIR=0;
    LCD_E_DIR=0;
    LCD_RS_DIR=0;
    LCD_DB7=0;
    LCD_DB6=0;
    LCD_DB5=0;
    LCD_DB4=0;
    LCD_E=0;
    LCD_RS=0;
	LCD_E=1;                  //清数据线
	LCD_E=0;
	LCD_DB5=1;	           //设置LCD工作方式
 	LCD_E=1;
	LCD_E=0;
	delay_ms(1000);
	SendCmd(0x28);
	SendCmd(DISP_ON);
	SendCmd(ENTRY_INC);
	SendCmd(DD_RAM_ADDR);
	clrLCD();
	
}
void putcLCD(int8 mychar)
{	
    LCD_RS=1;	      //设置为送数据模式
	write(mychar);
	mychar=mychar<<4;
    write(mychar);
	delay_ms(100);
}
void SendCmd(int8 mychar)
{
		
	LCD_RS=0;    	  //设置为送命令模式
	write(mychar);
	mychar=mychar<<4;
    write(mychar);
	delay_ms(100);
}
void clrLCD(void)
{	
	SendCmd(CLR_DISP);
}
void write(int8 mychar)
{
	if((mychar&0x80)!=0)
	LCD_DB7=1;
	else
	LCD_DB7=0;
	if((mychar&0x40)!=0)
	LCD_DB6=1;
	else
	LCD_DB6=0;
	if((mychar&0x20)!=0)
	LCD_DB5=1;
	else
	LCD_DB5=0;
	if((mychar&0x10)!=0)
	LCD_DB4=1;
	else
	LCD_DB4=0;
	LCD_E=1;
	LCD_E=0;
}
void main(void)
{
	int8	temp;
	CFE_DIR=0;
	InitADKEY();
   	InitLCD();
	SendCmd(0x40);
	SendCmd(0x40);
	putcLCD(0x18);
	putcLCD(0x18);
	putcLCD(0x07);
	putcLCD(0x08);
	putcLCD(0x08);
	putcLCD(0x08);
	putcLCD(0x07);
	putcLCD(0x00);	
	while(1)
	{
		SendCmd(0x80);
		putcLCD(' ');
		putcLCD(' ');
		putcLCD(' ');
		putcLCD(' ');
		putcLCD('M');
		putcLCD('a');
		putcLCD('i');
		putcLCD('n');
		putcLCD(' ');
		putcLCD('M');
		putcLCD('e');
		putcLCD('n');
		putcLCD('u');
		SendCmd(0xc0);
		putcLCD('1');
		putcLCD(':');
		putcLCD('M');
		putcLCD('o');
		putcLCD('n');
		putcLCD('M');
		putcLCD('o');
		putcLCD('d');
		putcLCD('2');
		putcLCD(':');
		putcLCD('N');
		putcLCD('o');
		putcLCD('r');
		putcLCD('M');
		putcLCD('o');
		putcLCD('d');
		temp=0;
		while(GetADKEY()==0x30);
		temp=GetADKEY();
		delay_ms(20);
		if(temp!=GetADKEY())
		continue;
		while(GetADKEY()!=0x30);
		clrLCD();
		delay_us(1);
		if(temp==0x31)
		{
			SendCmd(0x80);
			putcLCD(' ');
			putcLCD(' ');
			putcLCD(' ');
			putcLCD(' ');
			putcLCD('M');
			putcLCD('o');
			putcLCD('n');
			putcLCD('M');
			putcLCD('o');
			putcLCD('d');
			delay_ms(1000);
			moniter();
			clrLCD();
		}
		else if(temp==0x32)
		{
			SendCmd(0x80);
			putcLCD(' ');
			putcLCD(' ');
			putcLCD(' ');
			putcLCD(' ');
			putcLCD('N');
			putcLCD('o');
			putcLCD('r');
			putcLCD('M');
			putcLCD('o');
			putcLCD('d');
			delay_ms(1000);
			normal();
			clrLCD();
		}
		else
		{
			SendCmd(0x80);
			putcLCD(' ');
			putcLCD(' ');
			putcLCD('E');
			putcLCD('o');
			putcLCD('r');
			putcLCD('r');
			putcLCD(' ');
			putcLCD('C');
			putcLCD('h');
			putcLCD('o');
			putcLCD('i');
			putcLCD('c');
			putcLCD('e');
			delay_ms(1000);
			clrLCD();
		}
	}
	
}

⌨️ 快捷键说明

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