新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > SLE4442卡_IC的51單片機(jī)驅(qū)動(dòng)程序

        SLE4442卡_IC的51單片機(jī)驅(qū)動(dòng)程序

        作者: 時(shí)間:2016-12-02 來源:網(wǎng)絡(luò) 收藏

        void Byte_WRT(uchar Xdata) //寫字節(jié)
        {
        uchar count;
        DATA_OUT;
        DelayUs(2);
        for(count=8;count!=0;count--)
        {
        CLK_LOW;
        DelayUs(2);
        if((Xdata)&0x01)
        {
        DATA_HIGH;
        }
        else
        {
        DATA_LOW;
        }
        DelayUs(2);
        CLK_HIGH;
        DelayUs(2);
        Xdata = Xdata >> 1; //循環(huán)右移,從最低位開始寫
        }
        }

        本文引用地址:http://www.104case.com/article/201612/324690.htm


        void Command(uchar command,uchar address,uchar IC_data)
        {
        Start();
        Byte_WRT(command); //發(fā)送命令
        Byte_WRT(address); //發(fā)送地址
        Byte_WRT(IC_data); //發(fā)送數(shù)據(jù)
        Stop(); //操作命令結(jié)束
        }

        void Process(void)
        {
        uint j; //寫指令后的處理過程
        DATA_OUT;
        DelayUs(2);
        CLK_LOW;
        DATA_LOW;
        DelayUs(2);
        for(j = 0;j < 255;j++)
        {
        CLK_HIGH;
        DelayUs(2);
        CLK_LOW;
        DelayUs(2);
        }
        DATA_HIGH;
        }

        void Process2(void)
        {
        uint j; //寫指令后的短處理過程
        DATA_OUT;
        DelayUs(2);
        CLK_LOW;
        DATA_LOW;
        DelayUs(2);
        for(j = 0;j < 2;j++)
        {
        CLK_HIGH;
        DelayUs(2);
        CLK_LOW;
        DelayUs(2);
        }
        DATA_HIGH;
        }

        uchar Code_Check(uchar Code1,uchar Code2,uchar Code3) //密碼校驗(yàn)函數(shù)
        {
        uchar i;
        Command(0x31,0x00,0x00);
        for(i = 0;i < 4;i++)
        {
        ErrorCount[i] = Byte_Read();
        }
        if(ErrorCount[0] == 0)
        {
        return 0;
        }
        else
        {
        if((ErrorCount[0]&0x01) == 1)
        {
        ErrorCount[0] &= 0x06; //bit0=0;
        }
        else if((ErrorCount[0]&0x02) == 1)
        {
        ErrorCount[0] &= 0x05; //bit1=0;
        }
        else
        {
        ErrorCount[0] &= 0x03; //bit2=0
        }
        }
        Command(0x39,0x00,ErrorCount[0]);
        Process();

        Command(0x33,0x01,Code1);
        Process2();

        Command(0x33,0x02,Code2);
        Process2();

        Command(0x33,0x03,Code3);
        Process2();

        Command(0x39,0x00,0xff);
        Process();

        Command(0x31,0x00,0x00);
        for(i = 0;i < 4;i ++)
        {
        ErrorCount[i] = Byte_Read();
        }
        if(ErrorCount[0] == 0x07)
        {
        return 1;
        }
        else
        {
        return 0;
        }
        }


        void ReadMainROM(uchar addr,uchar *p,uchar N) //讀主存區(qū)
        {
        Command(0x30,addr,0xff);
        while(N--)
        {
        *p=Byte_Read();
        p++;
        }
        }



        評論


        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 且末县| 肃宁县| 怀集县| 和龙市| 滨海县| 寻甸| 溆浦县| 旬阳县| 广昌县| 九寨沟县| 安宁市| 健康| 桦川县| 哈巴河县| 布尔津县| 介休市| 仁化县| 贵阳市| 云龙县| 镇远县| 南岸区| 莱芜市| 恩施市| 平谷区| 澳门| 唐海县| 徐州市| 太和县| 宣化县| 息烽县| 多伦县| 屯门区| 上栗县| 宁蒗| 宁波市| 平塘县| 元江| 佳木斯市| 宁都县| 泰顺县| 新蔡县|