📄 ct5557.txt
字号:
#include "main.h"
#include "Time_A.h"
#include "Led.h"
#include "funtion.h"
/*---------------------------------------------------------*/
#define SYN_UPPER_LIMIT 450 //实际435,计算350
#define SYN_LOWER_LIMIT 395
#define ONE_WAVE_UPPER_LIMIT 330 //330 //实际290,计算250
#define ONE_WAVE_LOWER_LIMIT 240
#define HALF_WAVE_UPPER_LIMIT 200//190 //实际151,计算115
#define HALF_WAVE_LOWER_LIMIT 80//100goo
uchar RF_capture_Data[6];
uchar capture_data;
uint capture_length;//捕获时间长度
uchar fist_fined_capture;//找第一位捕获
uchar capture_length_flag;
uchar first_bit_end;
uchar capture_bit_index;
uchar first_one_wave;
uchar serch_syn_byte; //找1.5P的同步信号
uint jum_flag;
uchar rf_syn_byte;
uint fine_syn_byte;
uchar No_half_wave;
uchar fine_start;
uchar syn_error_read_end;
uchar normal_read_end; //读RF结束
uchar error_read_end; //错误读RF结束
uchar fined_start;//找到同步信号后第一次读数据开始
uchar half_wave_time;//找到的是半波时间
//uchar error_read_end;//读RF结束
uchar compare_data[8];
uchar Get_CCR2;
uchar Total_One;
uchar Total_Zero;
uchar Total_byte;
uchar begin_read_data;
uchar half_wave;
uchar i=0;
uchar j=0;
uchar All_total;//找到同步信号后,每捕获一次加一,符合条件(1P,0.5P)
//Total_byte加一,两者的数据要相同才是有效的数据
uchar One_byte_total;
uchar Half_byte_total;
uchar One_byte_total_high;
uchar One_byte_total_low;
uchar Half_byte_total_high;
uchar Half_byte_total_low;
uchar capture_bit[124];
uchar capture_total_bit;
uchar capture_first_bit;
uchar capture_first_half_bit;
/*-----------------------------------------------------------*/
/*--------1P=290;------0.5P=151;-------1.5P=435*/
void delay( uint Tmie_delay)
{
uint i;
for(i=0;i<Tmie_delay;i++)
_NOP();
}
void Init_RF_Card(void)
{
P1SEL|=0x08;
P1DIR3=0;
CCTL2=0C900h;
TACTL=0224h;
}
void rest_fine_bit(void)
{
serch_syn_byte=0;
fined_start=0;
error_read_end=0;
capture_bit_index=0;
first_bit_end=0;
capture_total_bit=0;
first_one_wave=0;
half_wave=0;
syn_error_read_end=0;
normal_read_end=0;
No_half_wave=0;
}
/*===============找到1=================*/
void fine_one(void)
{
capture_bit[capture_total_bit++]=0;
}
/*===============找到0=================*/
void fine_zero(void)
{
capture_bit[capture_total_bit++]=1; //低
}
/*--------找波长-----------*/
/*===============0.5P波长=================*/
void fine_half_wave(void)
{
if(!(first_bit_end))
{
if((serch_syn_byte)&&(CCTL2&0X0008))
{
if(!fined_start)
fined_start++; //找到开始读RF数据位
else if(first_one_wave==1) { first_bit_end++; fine_one(); }//高
}
else error_read_end++; //当检测到第一个1.5P后的第一位不是0.5P则结束读数据
}
else if(first_bit_end)
{
if(half_wave==1)
{
half_wave=0;
if((CCTL2&0X0008)) //高
fine_one();
else
fine_zero(); //低
}
else half_wave++;
}
}
/*===============1P波长=================*/
void fine_one_wave(void)
{
if((fined_start)&&(capture_bit_index==1))//找到SYN信号后第一个1P
first_one_wave++;
if(first_bit_end)
{
if((CCTL2&0X0008)) //高
fine_one();
else
fine_zero(); //低
}
}
/*===============1.5P波长=================*/
void fine_syn_wave(void)
{
if(!serch_syn_byte)//1.5P
serch_syn_byte++;
else if((capture_bit_index==1)&&(!(CCTL2&0X000)))
{
first_bit_end++;
fine_zero();
}
else if(capture_total_bit==32) normal_read_end++;//正常结束
else error_read_end++ ;
// else syn_error_read_end++; //错误结束
}
/*----------------------------------------------------------------*/
uint read_rf_times;
extern void read_RF_card(void);
main()
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog
DCOCTL=0XE0;
rest_fine_bit();
Init_RF_Card();//初始化RF卡
while(capture_total_bit<24)//在测试是只读24位,根据实际情况改动
//while(!first_bit_end)
{
read_RF_card();
if(error_read_end) rest_fine_bit();
}
Green_Led1(2);
while(1){;}
}
void read_RF_card(void)
{
_DINT();
do
{
while(!(CCTL2&0X0001)){}//等待获得捕获信号
TAR=0X0000;
CCTL2&=0XFFFE;
//TACTL=0X0224;
capture_length=CCR2;
CCR2=0X0000;
} while(((read_rf_times++)<2000)&&(!serch_syn_byte)&&(!((capture_length>SYN_LOWER_LIMIT)&&(capture_length<SYN_UPPER_LIMIT))));
if(fined_start) capture_bit_index++;//找到总捕获数据
/*---------------------------------------------------*/
if((capture_length>HALF_WAVE_LOWER_LIMIT)&&(capture_length<HALF_WAVE_UPPER_LIMIT))
capture_data=1;//0.5P
else if((capture_length>ONE_WAVE_LOWER_LIMIT)&&(capture_length<ONE_WAVE_UPPER_LIMIT))
capture_data=2;//1p
else if((capture_length>SYN_LOWER_LIMIT)&&(capture_length<SYN_UPPER_LIMIT))
capture_data=3;//1.5p
else if(first_bit_end) error_read_end++ ;
//No_half_wave++; //错误跳出读操作
/*---------------------------------------------------*/
switch(capture_data)
{
case 1:fine_half_wave();
break;
case 2:fine_one_wave();
break;
case 3:fine_syn_wave();
break;
default: break;
}
_EINT();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -