SLE4442卡_IC的51單片機驅(qū)動程序
char data_RST[4], ErrorCount[4];
本文引用地址:http://m.butianyuan.cn/article/201612/324690.htmvoid IC_RST(void)
{
uchar value,i,count;
DATA_IN; //IC輸入
RST_LOW; //復(fù)位時序
CLK_LOW;
DATA_HIGH;
DelayUs(5);
RST_HIGH;
DelayUs(5);
CLK_HIGH;
DelayUs(5);
CLK_LOW;
DelayUs(5);
RST_LOW;
DelayUs(2);
for(i=0;i<4;i++) //讀4個BYTE 可用后面的Byte_Read()代替
{
value = 0xff;
for(count=0;count<8;count++)
{
value = value >> 1;
DelayUs(2);
CLK_LOW;
DelayUs(2);
CLK_HIGH;
DelayUs(2);
if(RD5 == 1)
{
value |= 0x80; //判斷IO腳是否為1,是則位置1
}
else
{
value &= 0x7f; //否則位置0
}
DelayUs(2);
}
data_RST[i] = value;
DelayUs(2);
}
DelayUs(2);
CLK_LOW;
DelayUs(2);
DATA_HIGH;
}
void IC_Init(void) //初始化
{
TRISD1 = 0;
RD1 = 0; //上電
TRISD4 = 0; //時鐘輸出
TRISD3 = 0; //RST輸出
DelayMs(5); //上電的必要延時,否則程序出錯
}
void Start(void)
{
DATA_OUT; //開始時序
CLK_LOW;
DATA_HIGH;
DelayUs(2);
CLK_HIGH;
DelayUs(2);
DATA_LOW;
DelayUs(2);
CLK_LOW;
}
void Stop(void) //結(jié)束時序
{
DATA_OUT;
CLK_LOW;
NOP();
NOP();
DATA_LOW;
DelayUs(2);
CLK_HIGH;
DelayUs(2);
DATA_HIGH;
DelayUs(2);
}
uchar Byte_Read(void) //讀字節(jié)
{
uchar count;
uchar value;
DATA_IN;
DelayUs(2);
value = 0xff;
for(count=0;count<8;count++)
{
value = value >> 1; //循環(huán)右移,從最低位開始讀
DelayUs(2);
CLK_LOW;
DelayUs(2);
CLK_HIGH;
DelayUs(2);
if(RD5 == 1)
{
value |= 0x80;//判斷IO腳是否為1
}
else
{
value &= 0x7f;
}
DelayUs(2);
}
return (value);
}
評論