sle4442卡,可以读数据,但是写不上去,求大神解惑
时间:10-02
整理:3721RD
点击:
弄了两天了,求大神给看看
每个引脚都通过三极管驱动,所以都是反向的,即单片机输出1的时候,sle4442接收到的是0. IC_IO_R除外。
- void sle4442_start_com()
- {
- IC_IO_W = 0;
- Delay10us();
- IC_CLK = 0;
- Delay5us();
- IC_IO_W = 1;
- Delay5us();
- IC_CLK=1;
- }
- void sle4442_stop_com()
- {
- IC_CLK = 1;
- IC_IO_W = 1;
- Delay10us();
- IC_CLK = 0;
- Delay5us();
- IC_IO_W = 0;
- Delay10us();
- }
- void sle4442_sendbyte(uchar data)
- {
- uint i;
- for(i = 8; i > 0; i--)
- {
- IC_CLK = 1;
- IC_IO_W = !(data & 0x01);
- Delay10us();
- IC_CLK = 0;
- Delay10us();
- data = data >>1;
- }
- }
- unsigned char sle4442_rcvbyte()
- {
- uint i,ch;
- ch = 0;
- for(i = 8; i > 0; i--)
- {
- IC_CLK = 1;
- ch = ch >> 1;
- if((uint)IC_IO_R)
- ch |= 0x80;
- else ch |= 0x00;
- Delay10us();
- IC_CLK = 0;
- Delay10us();
- }
- IC_CLK=1;
- return ch;
- }
- void sle4442_ansrst()
- {
- //IC_CLK=1;
- //IC_RST=1;
- IC_RST=0;
- Delay5us();
- IC_CLK=0;
- Delay10us();
- Delay5us();
- IC_CLK=1;
- Delay5us();
- IC_RST=1;
-
- ic_id[0] = sle4442_rcvbyte();
- ic_id[1] = sle4442_rcvbyte();
- ic_id[2] = sle4442_rcvbyte();
- ic_id[3] = sle4442_rcvbyte(); //读出32个相应数据 是IC卡的ID
-
- IC_CLK = 1;
- Delay5us();
- IC_IO_W = 0;
- }
- void sle4442_process_plus()
- {
- uint i=255;
- IC_CLK = 1;
- Delay5us();
- IC_IO_W = 1;
- Delay5us();
- while(i--)
- {
- IC_CLK = 1;
- Delay10us();
- IC_CLK = 0;
- Delay5us();
- }
- IC_IO_W = 0;
- IC_CLK=1;;
- }