CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

KeeLoq Decoder.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Kasper



Joined: 14 Jan 2004
Posts: 88
Location: Aurora, Ontario, Canada

View user's profile Send private message Visit poster's website

KeeLoq Decoder.
PostPosted: Mon Feb 09, 2004 7:54 pm     Reply with quote

Hi. I am trying to get a Microchip KeeLoq encoder/decoder pair working. I am currently working on getting the decoder to work, before getting the encoder going, and I am running into a bit of trouble, which I hope someone here could shed some light on.

This is the code I use to initialize the decoder (HCS515) http://www.microchip.com/1010/pline/security/keysecat/decoders/devices/hcs515/index.htm

I think that the datastream to the decoder is right, verified with oscilloscope, but the S_CLK line never goes high to verify that it received it. Is there anything wrong with the code, am I goofing somewhere? any insight would be appreciated

Thanks in advance

Kasper
PCH 3.184, PIC 18F6720, WinXP PRO SP1, ICD2
Code:


#define KeeLoqREAD        0xF0
#define KeeLoqWRITE        0xE1
#define KeeLoqACTIVATE_LEARN     0xF0
#define KeeLoqERASE_ALL        0xC3
#define KeeLoqPROGRAM        0xB4
#define CRYPT           ABCDEF               // the actual 64 bit crypt key
#define TREQ      50   // min 0.005 max 500 ms
#define TRESP      100      // suggested value
#define   TSTART      100      // suggested Value
#define TCLKH      100      //  microsecond delay Clock High
#define TCLKL      100      //  microsecond delay Clock Low
#define   T_ACK      50


void init_keeloq(void) {
char CryptKey[8];
long int i;
char temp[1];
strcpy(CryptKey,"CRYPT");
output_high(S_CLK);
   delay_ms(TREQ);   
   output_low(S_CLK);
   delay_us(TSTART);   // ready for programming mode.
   // here the 80 bits of data is shifted to the KeeLoq decoder.

temp[0] = KeeloqPROGRAM;
for(i=0;i<(8);i++) {
   output_bit(S_DAT,shift_right(temp,1,1)); // shifts out the data from the receiveBuffer
   output_high(S_CLK);
   delay_us(TCLKH);   
   output_low(S_CLK);
   delay_us(TCLKL);   
}

temp[0] = 0x00; // config byte.
for(i=0;i<(8);i++) {
   output_bit(S_DAT,shift_right(temp,1,1)); // shifts out the data from the receiveBuffer
   output_high(S_CLK);
   delay_us(TCLKH);   
   output_low(S_CLK);
   delay_us(TCLKL);   
}   

   //   shift out the 64 bit Crypt Key
for(i=0;i<(64);i++) {   // always 64 bits to be shifted out, hence hardcoded.
   output_bit(S_DAT,shift_right(CryptKey,8,1)); // shifts out the data from the receiveBuffer
   output_high(S_CLK);
   delay_us(TCLKH);   
   output_low(S_CLK);
   delay_us(TCLKL);   
   }// end of for.
output_float(S_DAT);
output_high(S_CLK);
delay_ms(T_ACK);
output_low(S_CLK);

delay_ms(50);
}
Philies
Guest







PostPosted: Tue Feb 10, 2004 12:40 am     Reply with quote

Hi Kasper

Have a look Microchip application note AN744 "Modular Mid-Range PICmicro® KEELOQ® Decoder in C"
Kasper



Joined: 14 Jan 2004
Posts: 88
Location: Aurora, Ontario, Canada

View user's profile Send private message Visit poster's website

PostPosted: Tue Feb 10, 2004 9:59 am     Reply with quote

Philies wrote:
Hi Kasper

Have a look Microchip application note AN744 "Modular Mid-Range PICmicro® KEELOQ® Decoder in C"


Thanks for the link, but unfortunately I am using a seperate decoder chip, the HCS515, which is the one I am having trouble with. .. it is not Acknowledging that I am sending commands to it... anyone with ideas for that?
Interesting thing how they dedicate a whole microcontroller to do the decoding in that app note! Shocked
Kasper



Joined: 14 Jan 2004
Posts: 88
Location: Aurora, Ontario, Canada

View user's profile Send private message Visit poster's website

PostPosted: Wed Feb 11, 2004 11:19 am     Reply with quote

well I got it working.. I was just not waiting long enough for the ack bit.. damn this thing is slow!

Code:

void init_keeloq(void) {
char CryptKey[8];
long int i;
char temp[1];
strcpy(CryptKey,"CRYPT");
output_low(S_DAT);
output_float(S_DAT);
output_high(S_CLK);
   while(bit_test(PORTE,7) == 0) {
   }
   delay_us(TRESP);   
   output_low(S_CLK);
   while(bit_test(PORTE,7) == 1) {
   }   
   delay_us(TSTART);   // ready for programming mode.
   // here the 80 bits of data is shifted to the KeeLoq decoder.

temp[0] = KeeloqPROGRAM;
for(i=0;i<(8);i++) {
   output_bit(S_DAT,shift_right(temp,1,1)); // shifts out the data from the receiveBuffer
   output_high(S_CLK);
   delay_us(TCLKH);   
   output_low(S_CLK);
   delay_us(TCLKL);   
}

temp[0] = 0x00; // config byte.
for(i=0;i<(8);i++) {
   output_bit(S_DAT,shift_right(temp,1,1)); // shifts out the data from the receiveBuffer
   output_high(S_CLK);
   delay_us(TCLKH);   
   output_low(S_CLK);
   delay_us(TCLKL);   
}   

   //   shift out the 64 bit Crypt Key
for(i=0;i<(64);i++) {   // always 80 bits to be shifted out, hence hardcoded.
   output_bit(S_DAT,shift_right(CryptKey,8,1)); // shifts out the data from the receiveBuffer
   output_high(S_CLK);
   delay_us(TCLKH);   
   output_low(S_CLK);
   delay_us(TCLKL);   
   }// end of for.
   output_float(S_DAT);
   delay_ms(1);
   output_high(S_CLK);
   while(bit_test(PORTE,7) == 0) {
   }
delay_ms(1);
output_low(S_CLK);
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group