Code:
code VAR byte[9] BANK0 ' PWM read in
code1 var byte[66] ' Keeloq bits to be decrypted
KEY_0 var byte BANK0
KEY_1 var byte BANK0
KEY_2 VAR BYTE BANK0
KEY_3 VAR BYTE BANK0
KEY_4 VAR BYTE BANK0
KEY_5 VAR BYTE BANK0
KEY_6 VAR BYTE BANK0
KEY_7 VAR BYTE BANK0
mask VAR BYTE BANK0
CSR_0 VAR BYTE BANK0
CSR_1 VAR BYTE BANK0
CSR_2 VAR BYTE BANK0
CSR_3 VAR BYTE BANK0
pass VAR BYTE BANK0
CNT1 VAR BYTE BANK0
CNT2 VAR BYTE BANK0
temp var word
OVER:
while 1
main:
index=0
guard:
pulsin portb.0,0,temp 'find header of 16ms
if temp<2500 then main ' PIC is clocked at 8MHz, so a PulsIn step is 5usec.
if temp>4400 then main ' 5usec x 2500= 12.5ms up to 5usec x 4400=22ms
preamp:
pulsin portb.0,1,temp 'then skip 12 pulses of 50% Duty, 400usec
if temp<50 then main
if temp>90 then main
index=index+1
if index<11 then preamp
index=0
pulsetrain: 'now collect 66 pulses ~800/400 usec
pulsin portb.0,1,code1[index]
index=index+1
if index<66 then pulsetrain
index=0
find_code: 'convert pulse width to binary 66 bit stream
if code1[index]>130 then
if code1[index]<170 then
code.0[index]=0
endif
endif
if code1[index]<80 then
if code1[index]>55 then
code.0[index]=1
endif
endif
index=index+1
if index<66 then find_code
'Display the encrypted and decrypted array
hserout ["Rec: ",bin2 code[8]," ",bin8 code[7]," ",bin8 code[6]," ",bin8 code[5]," ",bin8 code[4],":",bin8 code[3]," ",bin8 code[2]," ",hex2 code[1]," ",hex2 code[0],13,10] 'display pulse train
CSR_0=CODE[0]:CSR_1=CODE[1]:CSR_2=CODE[2]:CSR_3=CODE[3]
GOSUB DECRYPT_K
hserout ["Dec: ",bin2 code[8]," ",bin8 code[7]," ",bin8 code[6]," ",bin8 code[5]," ",bin8 code[4],":",bin8 CSR_3," ",bin8 CSR_2," ",hex2 CSR_1," ",hex2 CSR_0,13,10,13,10]
wend
Obviously, cannot show the DECRYPT_K routine... Sorry.
Bookmarks