KCS301滚动码解码程序

发布者:平稳心绪最新更新时间:2016-11-17 来源: eefocus关键字:KCS301  滚动码  解码程序 手机看文章 扫描二维码
随时随地手机看文章

#include
#define uchar unsigned char

#define HOP1    CSR0
#define HOP2    CSR1
#define HOP3    CSR2
#define HOP4    CSR3

uchar KEY0,KEY1,KEY2,KEY3,KEY4,KEY5,KEY6,KEY7;
uchar CSR0,CSR1,CSR2,CSR3,CSR4,CSR5,CSR6,CSR7,CSR8;

uchar CNT0,CNT1,HOP_LENGTH,MASK,KEELOQ_Temp;

bit bb,bb1;
uchar testbit(uchar x,uchar n)
{
    return x & (1<

}
void decrypt(void)
{
    uchar i,j;
    uchar temp1,temp;
    for(i=0;i<12;i++)
    {
        for(j=0;j<48;j++)
        {
            if(i==11) 
            goto aa;

            if(testbit(HOP3,3)!=0)
             MASK=0x10;
            else
             MASK=1;

            if(testbit(HOP2,0)!=0)
            {
             MASK<<=2;
            }
            if(testbit(HOP1,0)!=0)
             MASK<<=1;

            temp1=HOP4 & 0x42; ;//Bit6 and bit 1
            switch(temp1)
            {
                case 0x0:
                    temp=0x2e;
                    break;
                case 0x02:
                    temp=0x74;
                    break;
                case 0x40:
                    temp=0x5c;
                    break;
                case 0x42:
                    temp=0x3a;
                    break;
                default:
                    break;
            }
            if((MASK & temp)==0)
                temp=0;
            else
                temp=0x80;
            temp^=HOP2;
            temp^=HOP4;
            temp^=KEY1;

            bb=HOP1>0x7f;
            HOP1<<=1;
            if(temp>0x7f) HOP1|=1;

            bb1=HOP2>0x7f;
            HOP2<<=1;
            if(bb) HOP2|=1;

            bb=HOP3>0x7f;
            HOP3<<=1;
            if(bb1) HOP3|=1;

            HOP4<<=1;
            if(bb) HOP4|=1;
                     

aa:           
            bb=KEY0>0x7f;
            KEY0<<=1;
            if(KEY7>0x7f) KEY0|=1;
            
            bb1=KEY1>0x7f;
            KEY1<<=1;
            if(bb) KEY1|=1;
            
            bb=KEY2>0x7f;
            KEY2<<=1;
            if(bb1) KEY2|=1;
            
            bb1=KEY3>0x7f;
            KEY3<<=1;
            if(bb) KEY3|=1;
            
            bb=KEY4>0x7f;
            KEY4<<=1;
            if(bb1) KEY4|=1;
            
            bb1=KEY5>0x7f;
            KEY5<<=1;
            if(bb) KEY5|=1;
            
            bb=KEY6>0x7f;
            KEY6<<=1;
            if(bb1) KEY6|=1;
            
            bb1=KEY7>0x7f;
            KEY7<<=1;
            if(bb) KEY7|=1;
                       

        }
    }

}

void main(void)
{
    KEY7=0x01;
    KEY6=0x23;
    KEY5=0x45;
    KEY4=0x67;
    KEY3=0x89;
    KEY2=0xab;
    KEY1=0xcd;
    KEY0=0xef;
    while(1)
    {
        CSR3=0X60;       ;
        CSR2=0;
        CSR1=3;
        CSR0=0X45;     //解码结果87 24 3D 4B
        decrypt();
    }

}


关键字:KCS301  滚动码  解码程序 引用地址:KCS301滚动码解码程序

上一篇:基于2051单片机串行数据采集传输模块的设计
下一篇:C51的延时函数

推荐阅读最新更新时间:2024-03-16 15:20

红外解码程序换种写法
#include reg52.h #define uint unsigned int #define uchar unsigned char sbit IR=P3^2; //红外接口标志 sbit RS = P1^0; sbit RW = P1^1; sbit E = P1^2; sbit beep = P1^7; uint hour,minute,second,count; char code Tab ={'0','1','2','3','4','5', '6','7','8','
[单片机]
小广播
添点儿料...
无论热点新闻、行业分析、技术干货……
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

换一换 更多 相关热搜器件
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved