{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
InitPorts;
EnableInts;
loop
//RELAY2:=SWITCH_PB0;
//BEEP_D0:=not(SWITCH1);
/////First Samle
while not(Pin_pwm) do endwhile;
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while not(Pin_pwm) do
endwhile;
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while bit(Pin_pwm) do
endwhile;
if (TCNT1L<$0D) and (TCNT1L>$08) then
G_stop:=0;
G_Byte_Tmp:=0;
/////////////////////////////////////////////////////////////////
while not(Pin_pwm) do endwhile;
repeat
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while not(Pin_pwm) do
//if TCNT1H>0 then G_Byte_Tmp:=1;break;endif;
endwhile;
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while bit(Pin_pwm) do
//if TCNT1H>0 then G_Byte_Tmp:=1;break;endif;
endwhile;
G_tmp_ARRAY[g_stop]:=TCNT1L;
if (G_Byte_Tmp=0) and (g_stop=0) then
G_TE_LEN_max:=G_tmp_ARRAY[g_stop]+3;
G_TE_LEN_min:=G_tmp_ARRAY[g_stop]-3;
endif;
if ((G_tmp_ARRAY[g_stop])<G_TE_LEN_max) and ((G_tmp_ARRAY[g_stop])>G_TE_LEN_min) then
G_stop:=G_stop+1;
else
G_Byte_Tmp:=1;
G_stop:=0;
break;
endif;
if G_Byte_Tmp=1 then G_stop:=0;break;endif;
until g_stop>10;
if G_Stop>0 then
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while not(Pin_pwm) do endwhile;
if (TCNT1L> (G_TE_LEN_max*6)) and (TCNT1L< (G_TE_LEN_max*10)) then
G_Stop:=12;
else
G_Stop:=0;
endif;
endif;
if G_Stop>0 then
for G_Byte_Tmp:=0 to 65 do
G_tmp_ARRAY[G_Byte_Tmp+G_Stop]:=0;
G_Count:=0;
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while not(Pin_pwm) do
//if TCNT1H>0 then G_Count:=1;break;endif;
endwhile;
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while bit(Pin_pwm) do
//if TCNT1H>0 then G_Count:=1;break;endif;
endwhile;
G_tmp_ARRAY[G_Byte_Tmp+G_Stop]:=TCNT1L;
if G_count>0 then break;endif;
endfor;
if g_count=0 then
for g_stop:=12 to 77 do
G_byte_tmp:=(G_tmp_ARRAY[G_stop]) div G_TE_LEN_min;
tmp_j:=(g_stop-12) div 8;
tmp_k:=(g_stop-12) mod 8;
tmp_l:=$01 shl tmp_k;
if G_byte_tmp=1 then
tmp_byte_array[tmp_j]:=tmp_byte_array[tmp_j] or tmp_l;
else
tmp_byte_array[tmp_j]:=tmp_byte_array[tmp_j] and not(tmp_l);
endif;
endfor;
///////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
G_MKey[0]:=$01;
G_MKey[1]:=$23;
G_MKey[2]:=$45;
G_MKey[3]:=$67;
G_MKey[4]:=$89;
G_MKey[5]:=$AB;
G_MKey[6]:=$CD;
G_MKey[7]:=$EF;
////////////////////////
G_KEY[0]:=G_MKEY[7];
G_KEY[1]:=G_MKEY[6];
G_KEY[2]:=G_MKEY[5];
G_KEY[3]:=G_MKEY[4];
G_KEY[4]:=G_MKEY[3];
G_KEY[5]:=G_MKEY[2];
G_KEY[6]:=G_MKEY[1];
G_KEY[7]:=G_MKEY[0];
G_CSR[0]:=tmp_byte_array[0];
G_CSR[1]:=tmp_byte_array[1];
G_CSR[2]:=tmp_byte_array[2];
G_CSR[3]:=tmp_byte_array[3];
G_CSR[4]:=tmp_byte_array[4];
G_CSR[5]:=tmp_byte_array[5];
G_CSR[6]:=tmp_byte_array[6];
G_CSR[7]:=tmp_byte_array[7];
G_CSR[8]:=tmp_byte_array[8];
//////////////////////
G_HOP[0]:=G_CSR[0];
G_HOP[1]:=G_CSR[1];
G_HOP[2]:=G_CSR[2];
G_HOP[3]:=G_CSR[3];
For G_CNT1:=12 downto 1 do
For G_CNT0:=48 downto 1 do
if G_CNT1=1 then
//rotate_key();
//KEY[7]: KEY[6]: KEY[5]: KEY[4]: KEY[3]: KEY[2]: KEY[1]: KEY[0]:
//7777777766666666555555554444444433333333222222221111111100000000
// Rotate
//7777777666666665555555544444444333333332222222211111111000000007
//RLE GET key 7 Flag
G_Flag_c_L:=G_KEY[7] and $80;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key0
G_Flag_c_L:=G_KEY[0] and $80;
G_KEY[0]:=G_KEY[0] shl 1;
G_KEY[0]:=G_KEY[0] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key1
G_Flag_c_L:=G_KEY[1] and $80;
G_KEY[1]:=G_KEY[1] shl 1;
G_KEY[1]:=G_KEY[1] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key2
G_Flag_c_L:=G_KEY[2] and $80;
G_KEY[2]:=G_KEY[2] shl 1;
G_KEY[2]:=G_KEY[2] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key3
G_Flag_c_L:=G_KEY[3] and $80;
G_KEY[3]:=G_KEY[3] shl 1;
G_KEY[3]:=G_KEY[3] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key4
G_Flag_c_L:=G_KEY[4] and $80;
G_KEY[4]:=G_KEY[4] shl 1;
G_KEY[4]:=G_KEY[4] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key5
G_Flag_c_L:=G_KEY[5] and $80;
G_KEY[5]:=G_KEY[5] shl 1;
G_KEY[5]:=G_KEY[5] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key6
G_Flag_c_L:=G_KEY[6] and $80;
G_KEY[6]:=G_KEY[6] shl 1;
G_KEY[6]:=G_KEY[6] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key7
G_Flag_c_L:=G_KEY[7] and $80;
G_KEY[7]:=G_KEY[7] shl 1;
G_KEY[7]:=G_KEY[7] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
else
//Clear C flage
G_Flag_C_L:=$00;
G_Flag_C_R:=$00;
G_MASK:=$01;
if (G_HOP[2] and $08)=$08 then G_Mask:=$10; endif;
if (G_HOP[1] and $01)=$01 then
//RLE
G_Flag_c_L:=G_Mask and $80;
G_Mask:=G_Mask shl 1;
G_Mask:=G_Mask or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE
G_Flag_c_L:=G_Mask and $80;
G_Mask:=G_Mask shl 1;
G_Mask:=G_Mask or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
endif;
if (G_HOP[0] and $01)=$01 then
//RLE
G_Flag_c_L:=G_Mask and $80;
G_Mask:=G_Mask shl 1;
G_Mask:=G_Mask or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
endif;
if (G_HOP[3] and $42)=$42 then
G_Mask:=G_Mask and $3A;
endif;
if (G_HOP[3] and $42)=$40 then
G_Mask:=G_Mask and $5C;
endif;
if (G_HOP[3] and $42)=$02 then
G_Mask:=G_Mask and $74;
endif;
if (G_HOP[3] and $42)=$00 then
G_Mask:=G_Mask and $2E;
endif;
G_work:=0;
if G_Mask<>0 then G_Work:=$80;endif;
G_work:=G_work xor G_Hop[1];
G_work:=G_work xor G_Hop[3];
G_work:=G_work xor G_Key[1];
G_MASK:=G_Work;
//RLE
G_Flag_c_L:=G_Mask and $80;
G_Mask:=G_Mask shl 1;
G_Mask:=G_Mask or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE Hop1
G_Flag_c_L:=G_HOP[0] and $80;
G_HOP[0]:=G_HOP[0] shl 1;
G_HOP[0]:=G_HOP[0] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE Hop2
G_Flag_c_L:=G_HOP[1] and $80;
G_HOP[1]:=G_HOP[1] shl 1;
G_HOP[1]:=G_HOP[1] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE Hop3
G_Flag_c_L:=G_HOP[2] and $80;
G_HOP[2]:=G_HOP[2] shl 1;
G_HOP[2]:=G_HOP[2] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE Hop4
G_Flag_c_L:=G_HOP[3] and $80;
G_HOP[3]:=G_HOP[3] shl 1;
G_HOP[3]:=G_HOP[3] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE GET key 7 Flag
G_Flag_c_L:=G_KEY[7] and $80;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key0
G_Flag_c_L:=G_KEY[0] and $80;
G_KEY[0]:=G_KEY[0] shl 1;
G_KEY[0]:=G_KEY[0] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key1
G_Flag_c_L:=G_KEY[1] and $80;
G_KEY[1]:=G_KEY[1] shl 1;
G_KEY[1]:=G_KEY[1] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key2
G_Flag_c_L:=G_KEY[2] and $80;
G_KEY[2]:=G_KEY[2] shl 1;
G_KEY[2]:=G_KEY[2] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key3
G_Flag_c_L:=G_KEY[3] and $80;
G_KEY[3]:=G_KEY[3] shl 1;
G_KEY[3]:=G_KEY[3] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key4
G_Flag_c_L:=G_KEY[4] and $80;
G_KEY[4]:=G_KEY[4] shl 1;
G_KEY[4]:=G_KEY[4] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key5
G_Flag_c_L:=G_KEY[5] and $80;
G_KEY[5]:=G_KEY[5] shl 1;
G_KEY[5]:=G_KEY[5] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key6
G_Flag_c_L:=G_KEY[6] and $80;
G_KEY[6]:=G_KEY[6] shl 1;
G_KEY[6]:=G_KEY[6] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key7
G_Flag_c_L:=G_KEY[7] and $80;
G_KEY[7]:=G_KEY[7] shl 1;
G_KEY[7]:=G_KEY[7] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
endif;
endfor;
endfor;
///////////////////////////////////////////////////////////////////////////////////////////////////
//toggle(Pin_led);
tmp_i:=tmp_byte_array[7] and $F0;
tmp_j:=G_HOP[3] and $F0;
if tmp_i=tmp_j then
toggle(RELAY2);
if tmp_i=$90 then BEEP_D0:=false;endif;
if tmp_i=$20 then BEEP_D0:=true;endif;
endif;
endif;
endif;
mdelay(3);
endif;
endloop;
Chip -->mega8L
Crystal-->7.3728M
compiler---> e-lab pascal compiler(www.e-lab.de)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
program HCS200_MEGA8L_RF;
{ $BOOTRST $00C00} {Reset Jump to $00C00}
{$NOSHADOW}
{ $WG} {global Warnings off}
Device = mega8, VCC=5;
//Import SysTick, SerPort;
Import SerPort;
From System Import longword;
Define
ProcClock = 7372800; {Hertz}
//SysTick = 10; {msec}
StackSize = $0032, iData;
FrameSize = $0032, iData;
SerPort = 9600; {Baud, StopBits|Parity}
RxBuffer = 16, iData;
TxBuffer = 16, iData;
Implementation
const
PIN_SCLK: BYTE=$10;
PIN_SDA : BYTE=$20;
PIN_RST : BYTE=$40;
DDR_SDA : BYTE=$20;
{$IDATA}
{--------------------------------------------------------------}
{ Type Declarations }
type
{--------------------------------------------------------------}
{ Const Declarations }
{--------------------------------------------------------------}
{ Var Declarations }
var
{$IDATA}
//////////////////////////////////
G_tmp_OK :boolean;
G_RX_ok : boolean;
G_Word_tmp :word;
G_byte_tmp:byte;
G_value_write : word;
G_Rx :byte;
//////////////////////////////////
G_Ds1302_RST[@portd, 6] : bit;
G_Ds1302_O_SDA[@pORTd, 5] : bit;
G_Ds1302_SCLK[@portd, 4] : bit;
G_Ds1302_I_SDA[@pind, 5] : bit;
G_Ds1302_REG : byte;
G_Ds1302_INDEX : byte;
SWITCH1[@PIND,2]:bit;
RELAY2[@PORTD,7]:bit;
SWITCH_PB0[@PINB,0]:bit;
//////////////////////////////////////
//////////////////////////////////////
Pin_pwm[@Pinc,0]:bit;
G_stop : byte;
G_count :byte;
G_tmp_ARRAY : array [0 .. 80] of byte; //66 bit
G_TE_LEN : byte;
G_TE_LEN_max : byte;
G_TE_LEN_min : byte;
//////////////////////////////////////////////////
//////////////////////////////////////////////////
//HOPPING
G_CSR: array [0 ..8] of byte;
G_HOP: array [0 ..8] of byte;
G_Key: array [0 ..7] of byte;
G_MKey: array [0 ..7] of byte;
G_CNT0 : byte;
G_CNT1 : byte;
G_MASK : byte;
G_Work : byte;
G_Work_word : word;
G_Flag_C : byte;
G_Flag_C_L : byte;
G_Flag_C_R : byte;
////////////////////////////////////////////////////
////////////////////////////////////////////////////
tmp_byte_array: array[0 .. 8] of byte;
tmp_i : byte;
tmp_j : byte;
tmp_k : byte;
tmp_l :byte;
{$EEPROM}
var
G_Lock : byte;
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
{--------------------------------------------------------------}
{ functions }
function Checksum(Const InString : string[16]):string[2];
var
tmp_i : byte;
tmp_j : byte;
tmp_word : word;
tmp_s :string[2];
begin
tmp_word:=0;
tmp_j:=length(instring);
for tmp_i:=2 to tmp_j do
tmp_word:=tmp_word+ord(instring[tmp_i]);
endfor;
tmp_s:=bytetohex(lo(tmp_word));
return (tmp_s);
end;
procedure InitPorts;
begin
DDRB :=$00;
PORTB:=$FF;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
// refer for CC2500_IO
// 76543210
// 00001110 --->PORTX
// 01110001 --->DDRX
// ^^^^^^
// ||||||------------CC2500_CSN
// |||||-------------CC2500_GDO0
// ||||--------------CC3500_GD02
// |||---------------CC2500_SO
// ||----------------CC2500_SCK
// |-----------------CC2500_SI
DDRC :=$71;
PORTC:=$07;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
// refer for SERIAL IN SWITCH
// 76543210
// 00111101 PORTX
// 11001010 DDRX
// ^^^^^
// ||||||-------------SWITCH1
// |||||--------------BEEP_D0
// ||||---------------DS1302
// |||----------------DS1302
// ||-----------------DS1302
// |------------------RELAY2
DDRD :=$CA;
PORTD:=$3D;
end;
//////////////////////////////////////////////////////
//
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
InitPorts;
EnableInts;
loop
//RELAY2:=SWITCH_PB0;
//BEEP_D0:=not(SWITCH1);
/////First Samle
while not(Pin_pwm) do endwhile;
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while not(Pin_pwm) do
endwhile;
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while bit(Pin_pwm) do
endwhile;
if (TCNT1L<$0D) and (TCNT1L>$08) then
G_stop:=0;
G_Byte_Tmp:=0;
/////////////////////////////////////////////////////////////////
while not(Pin_pwm) do endwhile;
repeat
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while not(Pin_pwm) do
//if TCNT1H>0 then G_Byte_Tmp:=1;break;endif;
endwhile;
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while bit(Pin_pwm) do
//if TCNT1H>0 then G_Byte_Tmp:=1;break;endif;
endwhile;
G_tmp_ARRAY[g_stop]:=TCNT1L;
if (G_Byte_Tmp=0) and (g_stop=0) then
G_TE_LEN_max:=G_tmp_ARRAY[g_stop]+3;
G_TE_LEN_min:=G_tmp_ARRAY[g_stop]-3;
endif;
if ((G_tmp_ARRAY[g_stop])<G_TE_LEN_max) and ((G_tmp_ARRAY[g_stop])>G_TE_LEN_min) then
G_stop:=G_stop+1;
else
G_Byte_Tmp:=1;
G_stop:=0;
break;
endif;
if G_Byte_Tmp=1 then G_stop:=0;break;endif;
until g_stop>10;
if G_Stop>0 then
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while not(Pin_pwm) do endwhile;
if (TCNT1L> (G_TE_LEN_max*6)) and (TCNT1L< (G_TE_LEN_max*10)) then
G_Stop:=12;
else
G_Stop:=0;
endif;
endif;
if G_Stop>0 then
for G_Byte_Tmp:=0 to 65 do
G_tmp_ARRAY[G_Byte_Tmp+G_Stop]:=0;
G_Count:=0;
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while not(Pin_pwm) do
//if TCNT1H>0 then G_Count:=1;break;endif;
endwhile;
TCNT1H:=0;
TCNT1L:= $00; // 1000 = 03E8h
while bit(Pin_pwm) do
//if TCNT1H>0 then G_Count:=1;break;endif;
endwhile;
G_tmp_ARRAY[G_Byte_Tmp+G_Stop]:=TCNT1L;
if G_count>0 then break;endif;
endfor;
if g_count=0 then
for g_stop:=12 to 77 do
G_byte_tmp:=(G_tmp_ARRAY[G_stop]) div G_TE_LEN_min;
tmp_j:=(g_stop-12) div 8;
tmp_k:=(g_stop-12) mod 8;
tmp_l:=$01 shl tmp_k;
if G_byte_tmp=1 then
tmp_byte_array[tmp_j]:=tmp_byte_array[tmp_j] or tmp_l;
else
tmp_byte_array[tmp_j]:=tmp_byte_array[tmp_j] and not(tmp_l);
endif;
endfor;
///////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
G_MKey[0]:=$01;
G_MKey[1]:=$23;
G_MKey[2]:=$45;
G_MKey[3]:=$67;
G_MKey[4]:=$89;
G_MKey[5]:=$AB;
G_MKey[6]:=$CD;
G_MKey[7]:=$EF;
////////////////////////
G_KEY[0]:=G_MKEY[7];
G_KEY[1]:=G_MKEY[6];
G_KEY[2]:=G_MKEY[5];
G_KEY[3]:=G_MKEY[4];
G_KEY[4]:=G_MKEY[3];
G_KEY[5]:=G_MKEY[2];
G_KEY[6]:=G_MKEY[1];
G_KEY[7]:=G_MKEY[0];
G_CSR[0]:=tmp_byte_array[0];
G_CSR[1]:=tmp_byte_array[1];
G_CSR[2]:=tmp_byte_array[2];
G_CSR[3]:=tmp_byte_array[3];
G_CSR[4]:=tmp_byte_array[4];
G_CSR[5]:=tmp_byte_array[5];
G_CSR[6]:=tmp_byte_array[6];
G_CSR[7]:=tmp_byte_array[7];
G_CSR[8]:=tmp_byte_array[8];
//////////////////////
G_HOP[0]:=G_CSR[0];
G_HOP[1]:=G_CSR[1];
G_HOP[2]:=G_CSR[2];
G_HOP[3]:=G_CSR[3];
For G_CNT1:=12 downto 1 do
For G_CNT0:=48 downto 1 do
if G_CNT1=1 then
//rotate_key();
//KEY[7]: KEY[6]: KEY[5]: KEY[4]: KEY[3]: KEY[2]: KEY[1]: KEY[0]:
//7777777766666666555555554444444433333333222222221111111100000000
// Rotate
//7777777666666665555555544444444333333332222222211111111000000007
//RLE GET key 7 Flag
G_Flag_c_L:=G_KEY[7] and $80;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key0
G_Flag_c_L:=G_KEY[0] and $80;
G_KEY[0]:=G_KEY[0] shl 1;
G_KEY[0]:=G_KEY[0] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key1
G_Flag_c_L:=G_KEY[1] and $80;
G_KEY[1]:=G_KEY[1] shl 1;
G_KEY[1]:=G_KEY[1] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key2
G_Flag_c_L:=G_KEY[2] and $80;
G_KEY[2]:=G_KEY[2] shl 1;
G_KEY[2]:=G_KEY[2] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key3
G_Flag_c_L:=G_KEY[3] and $80;
G_KEY[3]:=G_KEY[3] shl 1;
G_KEY[3]:=G_KEY[3] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key4
G_Flag_c_L:=G_KEY[4] and $80;
G_KEY[4]:=G_KEY[4] shl 1;
G_KEY[4]:=G_KEY[4] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key5
G_Flag_c_L:=G_KEY[5] and $80;
G_KEY[5]:=G_KEY[5] shl 1;
G_KEY[5]:=G_KEY[5] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key6
G_Flag_c_L:=G_KEY[6] and $80;
G_KEY[6]:=G_KEY[6] shl 1;
G_KEY[6]:=G_KEY[6] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key7
G_Flag_c_L:=G_KEY[7] and $80;
G_KEY[7]:=G_KEY[7] shl 1;
G_KEY[7]:=G_KEY[7] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
else
//Clear C flage
G_Flag_C_L:=$00;
G_Flag_C_R:=$00;
G_MASK:=$01;
if (G_HOP[2] and $08)=$08 then G_Mask:=$10; endif;
if (G_HOP[1] and $01)=$01 then
//RLE
G_Flag_c_L:=G_Mask and $80;
G_Mask:=G_Mask shl 1;
G_Mask:=G_Mask or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE
G_Flag_c_L:=G_Mask and $80;
G_Mask:=G_Mask shl 1;
G_Mask:=G_Mask or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
endif;
if (G_HOP[0] and $01)=$01 then
//RLE
G_Flag_c_L:=G_Mask and $80;
G_Mask:=G_Mask shl 1;
G_Mask:=G_Mask or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
endif;
if (G_HOP[3] and $42)=$42 then
G_Mask:=G_Mask and $3A;
endif;
if (G_HOP[3] and $42)=$40 then
G_Mask:=G_Mask and $5C;
endif;
if (G_HOP[3] and $42)=$02 then
G_Mask:=G_Mask and $74;
endif;
if (G_HOP[3] and $42)=$00 then
G_Mask:=G_Mask and $2E;
endif;
G_work:=0;
if G_Mask<>0 then G_Work:=$80;endif;
G_work:=G_work xor G_Hop[1];
G_work:=G_work xor G_Hop[3];
G_work:=G_work xor G_Key[1];
G_MASK:=G_Work;
//RLE
G_Flag_c_L:=G_Mask and $80;
G_Mask:=G_Mask shl 1;
G_Mask:=G_Mask or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE Hop1
G_Flag_c_L:=G_HOP[0] and $80;
G_HOP[0]:=G_HOP[0] shl 1;
G_HOP[0]:=G_HOP[0] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE Hop2
G_Flag_c_L:=G_HOP[1] and $80;
G_HOP[1]:=G_HOP[1] shl 1;
G_HOP[1]:=G_HOP[1] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE Hop3
G_Flag_c_L:=G_HOP[2] and $80;
G_HOP[2]:=G_HOP[2] shl 1;
G_HOP[2]:=G_HOP[2] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE Hop4
G_Flag_c_L:=G_HOP[3] and $80;
G_HOP[3]:=G_HOP[3] shl 1;
G_HOP[3]:=G_HOP[3] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE GET key 7 Flag
G_Flag_c_L:=G_KEY[7] and $80;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key0
G_Flag_c_L:=G_KEY[0] and $80;
G_KEY[0]:=G_KEY[0] shl 1;
G_KEY[0]:=G_KEY[0] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key1
G_Flag_c_L:=G_KEY[1] and $80;
G_KEY[1]:=G_KEY[1] shl 1;
G_KEY[1]:=G_KEY[1] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key2
G_Flag_c_L:=G_KEY[2] and $80;
G_KEY[2]:=G_KEY[2] shl 1;
G_KEY[2]:=G_KEY[2] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key3
G_Flag_c_L:=G_KEY[3] and $80;
G_KEY[3]:=G_KEY[3] shl 1;
G_KEY[3]:=G_KEY[3] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key4
G_Flag_c_L:=G_KEY[4] and $80;
G_KEY[4]:=G_KEY[4] shl 1;
G_KEY[4]:=G_KEY[4] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key5
G_Flag_c_L:=G_KEY[5] and $80;
G_KEY[5]:=G_KEY[5] shl 1;
G_KEY[5]:=G_KEY[5] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key6
G_Flag_c_L:=G_KEY[6] and $80;
G_KEY[6]:=G_KEY[6] shl 1;
G_KEY[6]:=G_KEY[6] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
//RLE key7
G_Flag_c_L:=G_KEY[7] and $80;
G_KEY[7]:=G_KEY[7] shl 1;
G_KEY[7]:=G_KEY[7] or G_Flag_C_R;
G_Flag_C_R:=G_Flag_C_L shr 7;
////////////////////////////
endif;
endfor;
endfor;
///////////////////////////////////////////////////////////////////////////////////////////////////
//toggle(Pin_led);
tmp_i:=tmp_byte_array[7] and $F0;
tmp_j:=G_HOP[3] and $F0;
if tmp_i=tmp_j then
toggle(RELAY2);
if tmp_i=$90 then BEEP_D0:=false;endif;
if tmp_i=$20 then BEEP_D0:=true;endif;
endif;
endif;
endif;
mdelay(3);
endif;
endloop;
end HCS200_MEGA8L_RF.
一周热门 更多>