📄 bakeup.#3
字号:
//---------------------------------------------------------------------------//
// 接收数据信息包 //
//---------------------------------------------------------------------------//
unsigned char Receive_Information_Package()
{
unsigned char r_count=0;
unsigned char count =0;
unsigned char sample_number=0;
unsigned char first=0;
unsigned char sencond=0;
unsigned char r_timers=0;
timer0_count=0;
while(count<34)
{
//在1ms中检测datamsg有无高电平到来
//如果检测到datamsg的高电平,则退出循环
if (timer0_count<10)
{
if (DATAMSG==1) //如果在其间检测到DATAMSG的高电平,则计数变量加1.
{
r_count++;
//if(r_count>=100)break; //如果连续监测到DATAMSG保持为高电平的时间为65us,则表明为有效的信号。
}
else r_count=0; //否则,计数变量清0
}
else
{
count++; //否则在1ms中内没有检测到高电平,则循环计数变量加1
if (r_count>=10000) break;
}
}
if (count>=34) return(0x00); //如果在100us*10*34=34ms中之内datamsg一直为低电平,则返回接收失败信息0x00
else //否则表明在其间检测到有效的datamsg信号,即找到了datamsg=1;接下来需要找datamsg为0的有效信号
{
timer0_count=0;
count=0;
while(1)
{
if(timer0_count<15) //如果15*100=1.5ms之内,执行下面的过程
{
if (DATAMSG==0) //查找DATAMSG=0
{
count++;
if (count>=40) break; //连续采集40次(--21us)
}
else count=0; //只要datamsg=1,则计数变量清0
}
else break; //否则,退出循环,进入外围循环。
}
if (count>=40) //如果采集到有效的datamsg=0信号
{
if(timer0_count>=7) //如果timer0_count>0.7ms,则表明低电平信号有效
{
timer0_count=0; //定时计数器清0
count=9; //开始数据接收
while(count<9)
{
wait_time_100us(); //等待100us
timer0_count=0;
r_count=0;
while(sample_number<8)
{
//采样8次
if (datamsg==0) r_count++;
}
first=r_count;
wait_time_100us(); //等待100us
timer0_count=0;
r_count=0;
while(sample_number<8)
{
//采样8次
if (datamsg==0) r_count++;
}
sencond=r_count;
}
}
}
}
}
}
//-----------------------------------2003-12-10日备份-------------------------------------//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -