整理了开端的试验草稿版,将端口宏界说,函数声明以及常用的函数声明树立头文件,感觉清楚多了,在不断地修正中凝练,在不断的实践中进步,满眼的思绪,在小小的Readme中划过一笔~~~~~~~~
char data_RST[4], ErrorCount[4];
void IC_RST(void)
{
uchar value,i,count;
DATA_IN; //IC输入
RST_LOW; //复位时序
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) //完毕时序
{
DATA_OUT;
CLK_LOW;
NOP();
NOP();
DATA_LOW;
DelayUs(2);
CLK_HIGH;
DelayUs(2);
DATA_HIGH;
DelayUs(2);
}
uchar Byte_Read(void) //读字节
{
uchar count;
uchar value;
DATA_IN;
DelayUs(2);
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
}
else
{
value &= 0x7f;
}
DelayUs(2);
}
return (value);
}