|
6楼
![](static/image/common/ico_lz.png)
楼主 |
发表于 2019-7-9 19:52:08
|
只看该作者
bool check()
{
unsigned char i,j,counter;
unsigned char cache,cache_1;
unsigned char c;
// _Bool result=TRUE;
for(i=0;i<10;i++)
{
counter=0;
cache=g_ucData;
cache_1=g_ucData;
for(j=0;j<4;j++)
{
cache&=0x10; //计算有几个1
if(cache==0x10)
{
counter++;
}
cache_1 <<=1;
cache=cache_1;
}
if((counter==0) ||(counter==2) ||(counter==4))
{
check_bit=0;
}
else if((counter==1) || (counter ==3))
{
check_bit=1;
}
c=g_ucData;
c&=1; //校验位
if(c==1)
{
PC_bit=1; //校验位是1的
}
else
{
PC_bit=0;
}
if(check_bit==PC_bit)
{
// result=TRUE; //表示检验正确
}
else
{
LED_ON;
return FALSE;
}
}
return TRUE;
}
bool row()
{
// _Bool result=TRUE;
unsigned char i,j,counter;
unsigned char cache,cache_1;
bool result;
cache_1=0x80; //------------------------------------此处如果跟上面一样 0x10 就读不出数据了 ,很不解,上面的就可以,上面的函数是行校验,下面的是列校验
for(i=0;i<4;i++)
{
counter=0;
for(j=0;j<10;j++)
{
cache=g_ucData;
cache&=cache_1;
if(cache==cache_1)
{
counter++;
}
}
if((counter==0) ||(counter==2) || (counter==4) || (counter==6) || (counter==8) || (counter==10))
{
check_bit1=0;
}
else if((counter==1) || (counter==3) || (counter==5) || (counter==7) || (counter==9))
{
check_bit1=1;
}
cache=g_ucData[10];
cache&=cache_1;
if(cache==cache_1)
{
PC_bit1=1; //最后一位
}
else
{
PC_bit1=0;
}
if(check_bit1==PC_bit1)
{
result=TRUE;
}
else
{
result=FALSE;
return result;
}
cache_1 >>=1;
}
return result;
} |
|