|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
uchar rf_rec_end_check (Uint8 * DataBufRx)
{
static uchar BufRxFormer[20],ser=0;
unsigned char i,j,x,y;
const uchar tab_bit[8]={1,2,4,8,0x10,0x20,0x40,0x80};
uchar succeed=0;
DataBufRx[6]&=0xf8;
j=0;
for(i=0;i<7;i++)
{
if(BufRxFormer!=DataBufRx)j=1;
BufRxFormer=DataBufRx;
}
if(!ClockIdRepeat)j=1;
ClockIdRepeat=30;
if(j)
{
y=0xff;
for(i=0;i<5;i++)
{
y^=DataBufRx;
}
x=0xf8;
for(j=0;j<5;j++)
{
for(i=0;i<8;i++)
{
if(DataBufRx[j]&tab_bit)x^=tab_bit[7-j];
}
}
if((x==DataBufRx[6])&&(y==DataBufRx[5]))
{
succeed=1;
}
}
return succeed;
}
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
void rf_rec_end_deal (void)
{
//static Uint8 ;
Uint16 i;
Uint8 j,rf_d;
Uint8 type=0,dt=0;
i=rf_rec_end_check(RfBuffer);
if(i)
{
if (read_eeprom_compare())
{
}
else if (!save_pin)
{
if (EERead(alarm_en) != 0xff) EEWrite(alarm_en,0xff);
j = EERead (CodeSaveSrial);
j ++;
if (j >= CodeNumberMax) j = 0;
i = ((j + CodeStartAddressEeprom) << 2);
EEWrite(i,RfDataOut[0]);
i ++;
EEWrite(i,RfDataOut[1]);
i ++;
EEWrite(i,RfDataOut[2]);
i ++;
EEWrite(i,0x40);
EEWrite(CodeSaveSrial,j);
}
type=(RfBuffer[3]>>1)&0x1f;
if(type&0x10)
{
if(RfBuffer[3]&1)dt|=0x80;
if(RfBuffer[4]&0x80)dt|=0x40;
if(RfBuffer[4]&0x40)dt|=0x20;
if(RfBuffer[4]&0x20)dt|=0x10;
}
else
{
if(RfBuffer[3]&1)dt|=0x80;
if(RfBuffer[4]&0x80)dt|=0x40;
if(RfBuffer[4]&0x40)dt|=0x10;
if(RfBuffer[4]&0x20)dt|=0x20;
}
ClockLed=100;
UsartPcTxPoint=0;
UartPcTxEn=1;
for(j=0;j<7;j++)PcComDataTx[j+1]=RfBuffer[j];
PcComDataTx[0]=j;
}
rf_rec_end = 0;
}
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
void eeprom_clr (void)
{
Uint8 i;
LedOn;
for(i=0;i<50;i++)
{
if ((save_pin) || (clr_pin)) return;
Delay(10000);
}
for(i=0;i<20;i++)
{
if ((save_pin) || (clr_pin)) return;
Delay(40000);
CovLedOnOff;
}
for(i=0;i<50;i++)
{
Delay(10000);
CovLedOnOff;
}
LedOff;
for(i=CodeStartAddressEeprom;i<CodeNumberMax;i++)
{
EEWrite(((i<<2)+3),0xff);
}
EEWrite(CodeSaveSrial,0xff);
EEWrite(alarm_en,0xff);
LedOn;
while ((!save_pin)||(!clr_pin))Delay(10000);
LedOff;
}
//=====================================================
void ClockMain (void)/////1mS
{
static Uint16 ClockA;
static Uint8 ClockB,ClockC;//,TampPinFormer=1;
ClockMainEn=0;
// sound_1mS_deal();
ClockB++;
if(ClockB>=100)////100mS
{
ClockB=0;
if(ClockIdRepeat)ClockIdRepeat--;
ClockC++;
if(ClockC>=10)////1S
{
ClockC=0;
}
}
if(LightTime)
{
ClockA++;
if(ClockA>=1000)
{
ClockA=0;
if((LightTime)&&(LightTime<250))LightTime--;
}
//if((ClockA<100)&&(LightTime))LightPortOn;
//else LightPortOff;
}
else
{
// LightPortOff;
ClockA=0;
}
if(ClockLed)
{
ClockLed--;
LedOn;
}
else
{
LedOff;
}
}
//==================
void UartPcRxDeal(Uint8 data)
{
UartRxPcDealEn=0;
/* static Uint8 buffer[TxRxDataBufMax+5],point=0,step=0,connect=0,n_byte=0;
Uint8 i,j,k=0,x;
point&=TxRxDataBufMax;
buffer[point]=data;
i=point;
point++;
if((ClockPcData==0)||(step==0))
{
connect=buffer;
if(connect<TxRxDataBufMax)
{
n_byte=0;
step=1;
}
else step=0;
}
else if(step==1)
{
n_byte++;
if(n_byte>=connect)
{
step=0;
for(j=connect;j>=1;j--)
{
k+=buffer[(i-j)&TxRxDataBufMax];
}
if(k==buffer);
{
SoftTest1;//////////////////////////////////test
PcRxDataDeal(connect-1,& buffer[0],i);
}
}
}
ClockPcData=40; */
}
//=======================
void UartPcTxDeal(void)
{
if(udre0_1)
{
if(UartPcTxEn)
{
UDR0_1=PcComDataTx[UsartPcTxPoint+1];
UsartPcTxPoint++;
if(UsartPcTxPoint>=PcComDataTx[0])
{
UsartPcTxPoint=0;
UartPcTxEn=0;
}
}
}
}
//==================
main()
{
Uint8 i;
_asm("sim");
GPIO_Init();
LedOn;
SystemClock_Init();
TIME_Init();
UART_Init();
init_WDG();
LedOff;
_asm("rim");
for(i=0;i<6;i++)
{
Delay(10000);
LedOn;
Delay(10000);
LedOff;
test;
}
while (1)
{
CLRWDT;
//if (TampAlarmEn) TampAlarmSet ();
if (rf_rec_end) rf_rec_end_deal ();
if (ClockMainEn)ClockMain ();
if(UartRxPcDealEn)UartPcRxDeal(UartRxPcData);
UartPcTxDeal();
}
}
//;;;;;;;;;;;;;;;;;;;*************************************
//void clr_rf_rec (void)
//{
// rf_bit_number=0;
// time_up=0;
// time_down=0;
// rf_bit_number = 0;
// timer_rf_plus_ovf = 0;
// rec_timer_now = 0;
// rec_timer_down = 0;
// timer_led_trb = 0;
// StartFlag=0;
// rf_data_temp=0;
//}
//==================
void RfRxDeal(Uint8 data,Uint8 up_down)
{
#define clr_rf_rec {rf_bit_number=0;time_up=0;time_down=0;}
static Uint8 bit_flag,rf_bit_number,rf_data_temp,time_now,
time_up,time_down,time_add,time_sub;
Uint8 i,j;
//if (data>=150) {clr_rf_rec; return;}
time_now=data;
if(up_down)
{
time_up=time_now;
time_add=time_up+time_down;
if(time_up>=time_down)
{
time_sub=time_up-time_down;
bit_flag=0;
}
else
{
time_sub=time_down-time_up;
bit_flag=1;
}
//if ((time_add < 94)&&(time_add >= 63)&&(time_sub < 63 )&&(time_sub >= 6))
if ((time_add < 29)&&(time_add >= 19)&&(time_sub < 20 )&&(time_sub >= 4))
{
if (bit_flag) rf_data_temp |= 1 ;
else rf_data_temp &= 0xfe ;
rf_bit_number ++ ;
if (!(rf_bit_number&7)) (RfBuffer[(rf_bit_number-1)>>3] = rf_data_temp);
if (rf_bit_number == 53 )
{
RfBuffer[6] = (rf_data_temp<<3)&0xf8;
rf_rec_end = 1 ;
clr_rf_rec;
//ClockLed=100;
}
rf_data_temp <<= 1 ;
}
else clr_rf_rec;
}
else
{
time_down=time_now;
}
} |
|