📄 baseclk.c
字号:
#include "typedef.h"
#include "intrins.h"
#include "time.h"
#include "ll.h"
////////////////////////////////////////////////////
void _sendBit(bit temp)
{
DIN = 1;
SCLOCK = 0; _nop_();
DIN = temp; _nop_();
SCLOCK = 1; _nop_();
SCLOCK = 0;
}
/************************************************************************/
/* clockmaster transfer from uctrl to ASIC*/
/************************************************************************/
void _trans1(void)
{
SCLOCK = 0;
DIN = 0; _nop_();
DIN = 1; _nop_();
DIN = 0; _nop_();
DIN = 1; _nop_();
SCLOCK = 1;_nop_();
}
/*****************************************************************/
/* clockmaster transfer from ASIC to uctrl************************/
/*****************************************************************/
void _trans2(void)
{
SCLOCK = 0;
DIN = 1; _nop_();
DIN = 0; _nop_();
DIN = 1; _nop_();
DIN = 0; _nop_();
}
/*****************************************************************/
/*startbit S1:rising edge on Din while SCLOCK high *************/
/*****************************************************************/
void _startBit(void)
{
SCLOCK = 0; _nop_();
DIN = 0; _nop_();
SCLOCK = 1; _nop_();
DIN = 1; _nop_();
SCLOCK = 0; _nop_();
}
/*****************************************************************/
/* stopbit ES1:falling edge on Din while SCLOCK high ************/
/*****************************************************************/
void _stopBit(void)
{
SCLOCK = 0; _nop_();
DIN = 1; _nop_();
SCLOCK = 1; _nop_();
DIN = 0; _nop_();
SCLOCK = 0; _nop_();
}
/*****************************************************************/
/* find S2: a SOF sent by the TAG *******************************/
/*****************************************************************/
uchar _findS2(void)
{
uchar S2=0;
while ((!SCLOCK)&&(!TIMERINT)); //等到SCLK变高
if (SCLOCK) //sclk变到高电平
{
while ((SCLOCK)&&(!TIMERINT)&&(!DOUT)); //等到dout输出为高
if (DOUT) //dout已经为高电平
{
while ((SCLOCK)&&(!TIMERINT)&&(DOUT));//等sclk变为低电平,dout为高
if (!SCLOCK)
{
S2 = 1; //找到起始信号
}
}
}
return (S2);
}
/*****************************************************************/
/* readbit:read data from DOUT*************************************/
/*****************************************************************/
uchar _readbit(void)
{
/*
uchar i, sample;
uchar debounce=1; // min clockpulse is 4.7us for 106kBaud
bit doutstore = 0;
while ((!SCLOCK)&&(!TIMERINT)); //wait for rising edge
for (i=0; i<debounce;i++);
if (SCLOCK)
{
if(ERR)
{
if(ERR)
{
sample = 2; //冲撞
return (sample);
}
}
doutstore=DOUT;
if (DOUT)
sample = 1;
else
sample = 0; //store sample: no debouncing!
while ((SCLOCK)&&(!TIMERINT)&&(doutstore==DOUT)); //等到sclk变为低电平,等待下个数据位
if ((SCLOCK)&&(doutstore != DOUT) ) // ES2
{
sample = 0x03;
}
else if (TIMERINT) // timeout
{
sample = 0x04;
}
}
return(sample);
*/
uchar i, sample, doutstore;
uchar debounce=1; // min clockpulse is 4.7us for 106kBaud
while ((!SCLOCK)&&(!TIMERINT)); //wait for rising edge
for (i=0; i<debounce;i++);
if (SCLOCK)
{
if(ERR)
{
if(ERR) { sample = 2; return (sample); }
}
doutstore=DOUT;
if (!DOUT)
sample = 0;
else
sample = 1; //store sample: no debouncing!
while ((SCLOCK)&&(!TIMERINT)&&(doutstore ==DOUT));
if ((SCLOCK)&&(doutstore != DOUT) ) // ES2
{
sample = 0x03;
}
else if (TIMERINT) // timeout
{
sample = 0x04;
}
}
return(sample);
}
/*****************************************************************/
/***read on DOUT and write on DIN, with uctrl master of clock.****/
/*****************************************************************/
uchar _rwbit(uchar wbit)
{
uchar i, rbit;
if(wbit)
DIN = 1;
else
DIN = 0;
SCLOCK = 1;
DOUT = 1;
for (i=0;i<2;i++); //dummy
if (!DOUT)
rbit=0;
else
rbit=1;
SCLOCK = 0;
return (rbit);
}
/*****************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -